Dax Breakout – Need some assistance please
Forums › ProRealTime English forum › ProOrder support › Dax Breakout – Need some assistance please
- This topic has 14 replies, 5 voices, and was last updated 12 months ago by MauroPro.
-
-
11/10/2023 at 4:43 PM #223505
Hi,
Posted this initially in the wrong forum, posting again correctly.
I am new to this forum and new to coding in general but hoping you can help.
I want to produce a strategy that takes the high and low of the 7:45-8am bar (UK). If the market goes 5 points above the high it’s a (buy), if 5 points below the low it triggers a sell. 20 point stop loss with a 40 point profit target. If one trade triggers the other is cancelled.
I think the below captures it but I might be wrong (I took a lot of it from a previous code I found and made amendments).
Lastly, and this is the part I need help with. If the trade is 15 points in my favour the stop loss moves to 0 or breakeven and I am not sure how to code that.
Any help would be greatly appreciated. Thanks.
DEFPARAM cumulateOrders = false
//—————————————–
timeframe (1 minute)
OTD = Barindex – TradeIndex(1) > IntradayBarIndex //one trade X day
startHour = 080000
cTime = time >= startHour
//——————————————————
if openTime = 074500 then
myHighest = high
myLowest = low
endif
if openTime >= 074500 and openTime <=075959 then
myHighest = max (myHighest,high)
myLowest = min (myLowest,low)
endif
//————————————————————–
if not onMarket and cTime and OTD then
buy 1 contract at myHighest + (5*pointSize) stop
sellShort 1 contract at myLowest – (5*pointSize) stop
endif
//—————————————————————–
SET STOP LOSS 20
set target pProfit 4011/10/2023 at 4:58 PM #223507The code seems correct and pending orders are automatically cancelled at the closing of each bar. They need to be placed again if needed.
There might be a minor chance that both pending orders are triggered, if that occurs on the same bar. It’s not possible to prevent that from happening (DEFPARAM cumulateOrders = false is of no use in this case).
The only correction I have made is to tell a STOP from a LIMIT order:
12345678910111213141516171819202122232425262728293031DEFPARAM cumulateOrders = false//—————————————-timeframe (1 minute)OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X daystartHour = 080000cTime = time >= startHour//——————————————————if openTime = 074500 thenmyHighest = highmyLowest = lowendifif openTime >= 074500 and openTime <=075959 thenmyHighest = max (myHighest,high)myLowest = min (myLowest,low)endif//————————————————————-if not onMarket and cTime and OTD thenIF close > myHighest THENbuy 1 contract at myHighest + (5*pointSize) limitELSIF close < myHighest THENbuy 1 contract at myHighest + (5*pointSize) stopENDIFIF close > myLowest THENsellShort 1 contract at myLowest - (5*pointSize) stopELSIF close < myLowest THENsellShort 1 contract at myLowest - (5*pointSize) limitENDIFendif//—————————————————————-SET STOP pLOSS 20set target pProfit 4011/10/2023 at 5:08 PM #223509Hi Roberto,
Thanks very much for looking at this.
Am I correct in saying “if the buy signal and the sell signal both trigger within the same 1 minute bar then both trades will trigger” but if they appear in different 1 min bars this will not happen?
Also, I mentioned moving my 20 point stop loss to Breakeven or 0 when I am 15 points in profit. Would you be able to assist with that?
11/10/2023 at 5:12 PM #223510If you wanto to bring the stop to breakeven after 15 points add to your code this snippet.
123456789101112if not onMarket thenmyExit = 0endifif longOnMarket and myExit = 0 and (close - tradePrice) >= 15 * pointSize thenmyExit = tradePrice(1)elsIf shortOnMarket and myExit = 0 and (tradePrice - close) >= 15 * pointSize thenmyExit = tradePrice(1)endifif myExit > 0 thensell at myExit STOPexitShort at myExit STOPendif2 users thanked author for this post.
11/10/2023 at 5:49 PM #22351311/10/2023 at 6:12 PM #223514Hi Roberto, I tried your code with the new instruction but it doesn’t hit the breakeven point. I had already tried it, written in a different way, before inserting the classical snippet, and also to me it didn’t work either (I thought I made a mistake).
Could you check?
11/10/2023 at 6:18 PM #223515This is the way I had written (but it didn’t work) the code with the new instruction (the old snippet work fine):
floatingPosition = positionPrice*positionPerf/pointSize
if (longOnMarket or shortOnMarket) and floatingPosition > 15*pointSize then
set stop breakeven
endif1 user thanked author for this post.
11/19/2023 at 12:46 PM #223917How could the code be changed to put at 1 or 2 points in profit instead of just break even?
11/19/2023 at 2:27 PM #223920In line 5 and 7 you have to write:
myExit = tradePrice(1) + 2*pointSize
1 user thanked author for this post.
11/21/2023 at 8:21 PM #224093Hi, I have noticed the coding produces results on a sunday evening and I would like to exclude this from the below. I tried what I thought was correct but doesn’t work.
DEFPARAM cumulateOrders = false
//—————————————-
timeframe (1 minute)
OTD = Barindex – TradeIndex(1) > IntradayBarIndex //one trade X day
startHour = 080000
cTime = time >= startHour
//——————————————————
if openTime = 074500 then
myHighest = high
myLowest = low
endif
if openTime >= 074500 and openTime <=075959 then myHighest = max (myHighest,high) myLowest = min (myLowest,low) endif //————————————————————- if not onMarket and cTime and OTD then IF close > myHighest THEN
buy 1 contract at myHighest + (5*pointSize) limit
ELSIF close < myHighest THEN buy 1 contract at myHighest + (5*pointSize) stop ENDIF IF close > myLowest THEN
sellShort 1 contract at myLowest – (5*pointSize) stop
ELSIF close < myLowest THEN
sellShort 1 contract at myLowest – (5*pointSize) limit
ENDIF
endif
//—————————————————————-
SET STOP pLOSS 20
set target pProfit 4011/22/2023 at 10:23 AM #22410411/23/2023 at 2:49 PM #224202Hi all,
I am not sure the coding gives me what I thought it was.
In summary, I expect the code to provide me with the high and low between 0745am and 0759am -minute bar. It would then trigger a buy or sell if the market hits 5 points below those bars’ high or low.
For example: On November 23rd the high and low of the DAX between 07:45am and 07:59am was 15,961.4 and 15948.4. This would mean a buy is triggered at 15,966.4 (15,961.4 + 5 points) and a sell would be triggered at 15943.4 (15948.4 – 5 points).
The trade triggered a sell at 15946.4 which is 3 points less than it should do and at no point did it reach 15943.4 to trigger a sell but the system triggered a sell at 08:01 at 15946.4 and proceeded to lose 20 points. I note that all the entries happen at the start of a new bar so I believe it will only ever trigger at the close of previous bar but I don’t understand why it triggered in the first place if the buy/sell at high/low + 5 is working properly.
Any help is greatly appreciated and thanks for all the assistance provided so far 🙂
DEFPARAM cumulateOrders = false//—————————————-timeframe (1 minute)OTD = Barindex – TradeIndex(1) > IntradayBarIndex //one trade X daystartHour = 080000cTime = time >= startHour//——————————————————if openTime = 074500 thenmyHighest = highmyLowest = lowendifif openTime >= 074500 and openTime <=075959 thenmyHighest = max (myHighest,high)myLowest = min (myLowest,low)endif//————————————————————-if not onMarket and cTime and OTD thenIF close > myHighest THENbuy 1 contract at myHighest + (5*pointSize) limitELSIF close < myHighest THENbuy 1 contract at myHighest + (5*pointSize) stopENDIFIF close > myLowest THENsellShort 1 contract at myLowest – (5*pointSize) stopELSIF close < myLowest THENsellShort 1 contract at myLowest – (5*pointSize) limitENDIFendif//—————————————————————-SET STOP pLOSS 20set target pProfit 4011/23/2023 at 4:24 PM #224207Hi,
Calculating the highest and lowest values doesn’t go well…
(if you want to know why, please let me know)
Try these:
If OpenTime=075900 then
myHighest=Highest[15](High)
myLowest=Lowest[15](Low)
EndIf
In the next part:
Omit these sentences:
If Close>myHighset then
If Close>myLowest then
1 user thanked author for this post.
11/23/2023 at 4:40 PM #224208In your formula you have typed: close > myLowest, instead you have to write close < myLowest.
Also use graphOnPrice to see the buy – sell levels.
You can also add this INDICATOR to see the max and min of the chosen time:
12345678910111213141516171819202122// rangeBox time1 - time2time1 = 074500time2 = 080000if openTime = time1 thenbar1 = barIndexhh = highll = lowendifhh = max(hh,high)ll = min(ll,low)//-------------------------------------------------if time = time2 thenbar2 = barIndexendifif bar2 > bar1 thendrawRectangle(bar1,hh,bar2,ll) coloured(255,0,0,25) borderColor(0,255,0,155)bar2 = 0endifreturnHere is the simplest formula:
123456789101112131415161718192021222324252627DEFPARAM cumulateOrders = false//—————————————-timeframe (1 minute)OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X daystartHour = 080000cTime = time >= startHour//——————————————————if openTime = 074500 thenmyHighest = highmyLowest = lowendifif openTime >= 074500 and openTime <= 075900 thenmyHighest = max (myHighest,high)myLowest = min (myLowest,low)endif//————————————————————-if not onMarket and cTime and OTD thenbuy 1 contract at myHighest + (5*pointSize) stopsellShort 1 contract at myLowest - (5*pointSize) stopendif//—————————————————————-SET STOP pLOSS 20set target pProfit 40graphonPrice myHighest + (5*pointSize)graphOnPrice myLowest - (5*pointSize)I add a picture of the day 23 you were referring to.
1 user thanked author for this post.
11/23/2023 at 4:51 PM #224210This would be the formula with the advice of JS (the result is the same, test 200K).
1234567891011121314151617181920212223DEFPARAM cumulateOrders = false//—————————————-timeframe (1 minute)OTD = Barindex - TradeIndex(1) > IntradayBarIndex //one trade X daystartHour = 080000cTime = time >= startHour//——————————————————If OpenTime=075900 thenmyHighest=Highest[15](High)myLowest=Lowest[15](Low)endif//————————————————————-if not onMarket and cTime and OTD thenbuy 1 contract at myHighest + (5*pointSize) stopsellShort 1 contract at myLowest - (5*pointSize) stopendif//—————————————————————-SET STOP pLOSS 20set target pProfit 40graphonPrice myHighest + (5*pointSize)graphOnPrice myLowest - (5*pointSize)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on