About to give up… is PRT not the code for a simple breakout strategy?
Forums › ProRealTime English forum › ProOrder support › About to give up… is PRT not the code for a simple breakout strategy?
- This topic has 18 replies, 9 voices, and was last updated 2 weeks ago by
PeterSt.
-
-
01/30/2025 at 8:34 PM #243251
Hi Traders,
I am feeling I am about to hit a brick wall… for several weeks I have tried to learn and asked for your help regarding a simple breakout strategy:
- go long above the high of the 0945-1000 bar
- or go short below the low of the same bar
- i defined a target profit and a stop loss
- i wanted only 1 trade if the first trade was a win, else try a second and final trade for the day
- i wanted to trade only during the 0930-1600 NYC session timeframe
- i was using YM instrument
Below is my code (incorporates a lof of tweaks from the PRT community).
I have never managed to have trades placed in the 1000-1015 bar right after the breakout bar. I repeat: the system never placed an order in that first eligible bar; the earliest would always be the 1015-1030 bar.
I truly believe my code has mistakes, however thus far, no one was able to solve what I initially thought would be an easy set of instructions. I did make a lot of progress with a few specific brilliant minds here in the PRT community but the code never managed to place orders in the first eligible bar (1000-1015).
If someone can point me in the right direction, I would be extremely thankful. I am new to PRT but I really like it (and the community as well), however this is becoming a very tough experience for me to believe there is still light at the end of the tunnel…
Many thanks either way everyone.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647DEFPARAM CUMULATEORDERS = FALSE // to prevent adding to positionsdefparam FLATBEFORE = 094500DEFPARAM FLATAFTER = 160000Once MaxTrades = 2//Once BUFFER = 0//Once PT = 40IF IntraDayBarIndex=0 THENTradeCount=0TradeOn=1HI =0LO =0ENDIFIf StrategyProfit>StrategyProfit[1] thenTradeOn=0EndIfIf LongTriggered or ShortTriggered thenTradeCount=TradeCount+1EndIfIf OpenTime=094500 thenHI=HighLO=LowCandleLength=HI-LOEndIfIf NOT ONMARKET and TradeOn=1 and TradeCount<MaxTrades THENIf High >HI+Buffer thenBUY CON CONTRACTS AT HI+Buffer limitSET STOP PRICE LO-CandleLength *stopadjusterSET TARGET pProfit PTEndIfIF Low <LO-Buffer thenSELLSHORT CON CONTRACTS AT LO-Buffer limitSET STOP PRICE HI+CandleLength *stopadjusterSET TARGET pProfit PTEndIfEndIfGraph TradeCount as "TradeCount"Graph TradeOn as "TradeOn"GraphOnPrice HI as "HI"GraphOnPrice LO as "LO"01/30/2025 at 9:09 PM #24325401/31/2025 at 3:13 PM #243280Hello! In order to enter on the 10:00 candle, everything must be fulfilled on the 9:45 candle. This code is useful for entering on the 10:00 candle on the breakout.
1234567If NOT ONMARKET and opentime=094500 and TradeOn=1 and TradeCount<MaxTrades THENHI=HighLO=LowCandleLength=HI-LOBUY CON CONTRACTS AT HI+Buffer stopSELLSHORT CON CONTRACTS AT LO-Buffer stopEndIf1 user thanked author for this post.
01/31/2025 at 10:51 PM #243294Muchas Gracias (many thans) Ivan.
- the strategy now places trades in the 1000-1015 bar
- it complies with the maximum of 2 trades per day
However, it seems like this fix helped with enabling the strategy to place orders in the 1000-1015 bar but then messed up with incorrectly allowing for:
- a 2nd trade after the first one being a winner
- not placing valid trades in bars other than the 100-1015
- not assuming the profit target when placing a 2nd trade
- not assuming the correct stoploss level in the first trade
I am attaching a few pictures in case it helps:
- when there is no entry signal in the 1000-1015 bar (i.e. inside bar or high/low don’t cross the HI+buffer/LO-buffer), the strategy does not place any orders for the day even when there are signals in the following bars (picture #1 attached)
- in one instance, the 1st trade, a losing short, was closed out at the entry point of the long instead of at its own stoploss point, which is always above the entry point for the long due to an extra cushion provided by a certain % of the 0945-1000 candle legth (a variable defined as stopadjuster). It looked as if the entry point for the long override the real stop point for the initial short. Then the 2nd trade, the long, had the correct entry point but somehow closed way before the profit target was hit (8 points instead of 40) (picture #2 also attached)
- in a few instances, the strategy placed two winning trades in the same day (in the same 1000-1015 bar) when it should have stopped after the first one. In the 2nd trade, also a winner, it closed out again before the 40 points of profit target, like it doesn’t remember this condition for any subsequent trade after the 1st of the day (picture #3 attached)
I hope this helps…
Am I being too ambitious with the few conditions I would like to backtest?
Attaching the code with Ivan’s and Grahal’s inputs
12345678910111213141516171819202122232425262728293031323334353637383940414243DEFPARAM CUMULATEORDERS = FALSE // to prevent adding to positionsdefparam FLATBEFORE = 094500DEFPARAM FLATAFTER = 160000Once MaxTrades = 2//Once BUFFER = 0//Once PT = 40IF IntraDayBarIndex=0 THENTradeCount=0TradeOn=1HI =0LO =0ENDIFIf StrategyProfit>StrategyProfit[1] thenTradeOn=0EndIfIf LongTriggered or ShortTriggered thenTradeCount=TradeCount+1EndIfIf NOT ONMARKET and opentime=094500 and TradeOn=1 and TradeCount<MaxTrades THENHI=HighLO=LowCandleLength=HI-LOBUY CON CONTRACTS AT HI+Buffer stopSET STOP PRICE LO-CandleLength *stopadjusterSET TARGET pProfit PTSELLSHORT CON CONTRACTS AT LO-Buffer stopSET STOP PRICE HI+CandleLength *stopadjusterSET TARGET pProfit PTEndIfGraph TradeCount as "TradeCount"Graph TradeOn as "TradeOn"GraphOnPrice HI as "HI"GraphOnPrice LO as "LO"01/31/2025 at 11:06 PM #24329902/01/2025 at 2:23 AM #243303I didn’t realise till now, that if the code block set both BUY and SELLSHORT STOP orders, then there both active and the first one the price breaks, is the order taken, with cumulateorder = false.
However, from your 2nd image, the trigger candle breaks the LO level and enters the short, but it –> EXIT’s <– the trade to get out, and not by a STOP setting.
That EXIT level is the same level as the long entry, it appears that the Buy stop level was still active and when reached EXIT’ed the short and entered the long.
The long order then exited the buy at a STOP level, which I believe was the stop level for the short.
I’m not sure, but I think you can only have one active stop level set, and I would think it would be the latter one executed in code, the short one.
The bar which sets the orders only runs once, so the long stop is overridden with the short stop.
I bet this is same for the targets, and the active target is for the short.
If price reverses when in the long, and didn’t hit the short stop level to exit, I wonder if the trade would continue short at a loss till it hit the short target level.
Though its not noted above, if the stopadjuster = 1, and buffer = 0, then all the orders are at different levels, the short hits the buy level before the short stop resulting in the X exit.
Also, then the long hits the short stop just above, and maybe there was never a long target set.
If the stopAdjuster = 0, then the entry levels and stop levels are at HI and LO, when the short hits the level of both the short stop and long Buy, the short now STOP’s out, probably by the short stop level.
The long enters, but is immediately stopped out because of the short stop level I guess is still active.
1 user thanked author for this post.
02/01/2025 at 2:35 AM #243304On the third image, I’m going to guess how that big candle played out.
The candle broke LO-buffer and entered the short.
It continued lower and hit the short target, closing the trade.
The price reversed from its low and broke the HI+buffer and entered long.
The long got stopped out when it hit the still active short stop level.
I don’t think there ever was a long target level set.
In my earlier comments I may have use HI and LO levels for triggering orders and not mentioned these may be offset but BUFFER.
02/01/2025 at 10:20 PM #243324Strategy corrected1234567891011121314151617181920212223242526272829303132333435363738394041DEFPARAM CUMULATEORDERS = FALSE // to prevent adding to positionsdefparam FLATBEFORE = 094500DEFPARAM FLATAFTER = 160000Once MaxTrades = 2//Once BUFFER = 0//Once PT = 40IF IntraDayBarIndex=0 THENTradeCount=0TradeOn=1HI =0LO =0ENDIFIf StrategyProfit>StrategyProfit[1] thenTradeOn=0EndIfIf LongTriggered or ShortTriggered thenTradeCount=TradeCount+1EndIfIf NOT ONMARKET and opentime>=094500 and TradeOn=1 and TradeCount<MaxTrades THENHI=HighLO=LowCandleLength=HI-LOBUY CON CONTRACTS AT HI+Buffer stopSELLSHORT CON CONTRACTS AT LO-Buffer stopSET STOP PLOSS CandleLength *stopadjusterSET TARGET pProfit PTEndIf//Graph TradeCount as "TradeCount"//Graph TradeOn as "TradeOn"//GraphOnPrice HI as "HI"//GraphOnPrice LO as "LO"For me it doesn’t work because the condition is triggered only at 9.45, so it works only if the next candle break out. I’ve corrected the time condition and the stop loss
02/02/2025 at 9:27 AM #243329Correction1234567891011121314151617181920212223242526272829303132333435363738394041424344DEFPARAM CUMULATEORDERS = FALSE // to prevent adding to positionsdefparam FLATBEFORE = 094500DEFPARAM FLATAFTER = 160000Once MaxTrades = 2//Once BUFFER = 0//Once PT = 40IF IntraDayBarIndex=0 THENTradeCount=0TradeOn=1HI =0LO =0ENDIFIf StrategyProfit>StrategyProfit[1] thenTradeOn=0EndIfIf LongTriggered or ShortTriggered thenTradeCount=TradeCount+1EndIfIf opentime=094500 THENHI=HighLO=LowCandleLength=HI-LOEndifIf NOT ONMARKET and opentime>=094500 and TradeOn=1 and TradeCount<MaxTrades THENBUY CON CONTRACTS AT HI+Buffer stopSET STOP PRICE LO-CandleLength *stopadjusterSET TARGET pProfit PTSELLSHORT CON CONTRACTS AT LO-Buffer stopSET STOP PRICE HI+CandleLength *stopadjusterSET TARGET pProfit PTEndIfGraph TradeCount as "TradeCount"Graph TradeOn as "TradeOn"GraphOnPrice HI as "HI"GraphOnPrice LO as "LO"1 user thanked author for this post.
02/03/2025 at 2:31 PM #243368Noted, Moving the HI;LO; and candleLength update outside the IF NOT ONMARKET block and Adding the > to the opentime = 0945, allows further entry’s to be made while between FLATBEFORE/AFTER window.
However, this allows, if not in market, stop orders to be set, every bar till a order is triggered or condition fails.
One addition I have made to the code is with the setting of HI = 0 and LO = 0, in the INTRADAYBARINDEX = 0 IF block.
When these are set to zero, it affects the y-scale auto zoom, this because the CANDLES and GRAPH keyword, with its variable, are items that the auto y-scale zoom is triggered by.
This making the candles un-readable, since the lower level of the y-scale goes to ZERO instead of the lowest CANDLE low being displayed. (bigger Y-range in same panel height)
This means manually re-scale the y-axis, which happens a lot when debugging and re-ADDing to chart to update.
Setting, HI = UNDEFINED and, LO = UNDEFINED, help alleviate this drastic re-scale.
The HI and LO lines, when set to there operational levels, are closer to the candle levels, so not crushing the displayed objects in the panel.
Since undefined is not a value like zero, y-scale is not altered, the drawn line appear to stay at there last valid level. Not yet noticed a down side in doing this!
In reference to my earlier comment, having both BUY and SELLSHORT, allows a choice of order types depending on price direction breaks, the pre defined levels can be pre set.
These levels don’t require an additional break level condition, which would delay positioning to next bar, but which STOP and TARGET are used with them.
Also, in the same bar, if both are sequentially executed, how they interact, needs a bit more investigation.
But as in the original code, if conditions are added to test a break, then the order is delayed until next bar.
Using STOP/LIMIT orders, I think the direction the price crossing the order level matters, a candle testing the break, could close, and end up on the wrong side of the later placed type order level.
This means the order not being executed, even if the move was correct to the break test, and in a smaller price move, the missed order may execute on the reverse direction part of the move. Getting in too late and in wrong direction.
There maybe other scenarios which may not be ideal!
Having both orders in the same bar, allows a quicker response since, condition not related to a price break and the bar delay, but could run into other issue as mentioned above.
I doubt its possible to check which of the orders is currently being executed and make change to the stop/target, all within a single bar.
At this time, reducing the timeframe the orders are executed on, would allow these changes, but I don’t think it would eliminate it 100%, there would always be a possible short term candle which could trigger both orders in a bar, if big enough, however, this will be more of a remote scenario.
02/03/2025 at 6:23 PM #243388As you can see in the attached pic, the candle where the mouse is sitting shows that OnMarket is false (for the candle to its left OnMarket is false, as well). To tell if two opposite orders, as in the pic, have been triggered and exited on the same bar, you can use LongTriggered and LongTriggered:
123456789IF close > highest[10](high[1]) THENBUY 1 Contract at high + 10*PipSize STOPSELLSHORT 1 Contract at high - 10*PipSize STOPSET TARGET %PROFIT 0.1SET STOP %LOSS 0.1ENDIFgraph LongTriggered coloured("Blue")graph ShortTriggered coloured("Red")graph OnMarketI tested the code on DAX, Daily TF.
1 user thanked author for this post.
02/05/2025 at 8:42 PM #243530Many thanks Drubby and EVERYONE ELSE for all your help in these recent months. I have tried “everything” and have exhausted my metal capital on this PRT backtesting quest. I have ried running all your codes, fixes, but unfortunately there was no way the entries were not 100% “accurate”…
And yes, you are absolutely right, the entry of LIMIT/STOP orders will depend upon which direction the price is coming from…
This is the end of this road for me.
I truly appreciate everyone’s help. It was amazing to see everyone trying to support me.
Good luck to everyone in this community with your personal and professional endeavours!
See you somewhere, some day…
tiago
3 users thanked author for this post.
02/08/2025 at 12:16 AM #243603Thanks James #Watanabix,
Based on my early comments, I wrote this code, it doesn’t contain the bells and whistle’s of yours, but I was just trying to get some control over the orders.
It still uses the 15minute setting of the HI/LO range etc, but runs on the 1 second timeframe to avoid multiple order happening on the same bar.
Since the candles are a lot smaller at 1 second timeframe, this allowed to fit some conditions in to isolate only a long or short being set, depending on which halve of the range the price is in before a break.
It seems to work quite well, so I back-tested it over 200,000 units which only is about 3 days, a down side of a smaller timeframe, but it appeared to be profitable over that short time.
I had optimised the target value , which was 90 points over the 3ish days.
Commenting out the GRAPH lines, I run it as a strategy in ProBuilder Demo, over next 3 days, and it was still profitable.
The code evolution to this point, may contain bits which may not be used or necessary, but may be a good starting point for what you were trying solely at 15minutes.
The detailed reports, ( left system) (right back-test) DAX40(DFB) both seem to track closely with each other, back-test spread set at 1.4 points.
Regards
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687DEFPARAM PRELOADBARS = 1DEFPARAM CUMULATEORDERS = FALSE // to prevent adding to positionsdefparam FLATBEFORE = 094500DEFPARAM FLATAFTER = 160000start = 100000end = 160000window = time >= start and time < endPT=90cTime = 094500once HI = undefinedonce LO = undefinedonce centre = undefinedtimeframe(15minute,updateonclose)once iHI = undefinedonce iLO = undefinedif intradaybarindex = 0 or BARINDEX = 0 theniHI = undefinediLO = undefinedendifif opentime = cTime theniHI = highiLO = lowendifbar15 = barindextimeframe(default)IF bar15[0] <> bar15[1] THENbar = 1HI = iHILO = iLoelsebar = 0ENDIFif high < HI and low > lo thenvalid = 1elsevalid = 0endifIF NOT ONMARKET and valid = 1 then//AND bar = 1 THENcentre = ((HI-LO)/2)+LOif high > centre and LOw > centre thenBUY 1 CONTRACT AT HI stopSET STOP PRICE LOSET TARGET pProfit PTelsif low < centre and high < centre thenSELLSHORT 1 contract AT LO stopSET STOP PRICE HISET TARGET pProfit PTENDIFendifif longtriggered thenSET STOP PRICE LOSET TARGET pProfit PTelsif shorttriggered thenSET STOP PRICE HISET TARGET pProfit PTendifgraphonprice HI coloured("red")graphonprice centre coloured("yellow")graphonprice LO coloured("lime")graph 0.75 * window + 10graph 0.75 * (valid and not onmarket)+9graph 0.75 * valid +8graph 0.75 * (Not ONMARKET AND bar = 1) +7graph 0.75 * longTriggered + 5graph 0.75 * shortTriggered + 4graph 0.75 * ONMARKET + 3graph 0.75 * bar + 13 users thanked author for this post.
02/13/2025 at 6:03 PM #243792Update!
Another few days see an increase.
Both, back-test and proOrder(demo) detailed reports(closed positions) tracked well until Feb 12th.
On the 12th, the proOrder did a entry and then an exit, for reasons unknown as of yet.
The back-test didn’t do this action.
I’m still looking into it, my speculations is that its something to do with,
. The 1 second timeframe, the small or none exist candles on the TF periods
. The entry being triggered very close to entry threshold, within the spread value.
. The spread may be involved, because the loss was halve the spread.
. maybe the order execution, or something.
What I do no is that back-test did something different t o proOrder(demo)
02/13/2025 at 9:00 PM #243806the loss was halve the spread.
You probably know this, but IG spread is taken at half on entry and half on exit.
I read your good efforts / works druby … I always learn something! 🙂
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on