Breakout Strategy on the candle stick – please Help!!
Forums › ProRealTime English forum › ProBuilder support › Breakout Strategy on the candle stick – please Help!!
- This topic has 19 replies, 2 voices, and was last updated 4 months ago by
crolakstrading.
-
-
07/14/2025 at 8:09 PM #24887412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576DEFPARAM CumulateOrders = False// Timeframe : H1tradingtime=(time >=090000 and time <=090000)if time=090000 thenvalue2 = highvalue1 = lowEntryPrice = (high) + (10* pipsize)EntryPrice1 = (low) - (10 * pipsize)StopLoss = range + (20 * pipsize) //10 pips below LOWStopLoss1 = range + (20 * pipsize) //10 pips above HIGH//takeprofit = range + (20 * pipsize) // TP LONG/SHORTENDIF// Conditions to enter long positionsIF NOT LongOnMarket AND tradingtime and value2 THENBUY 0.5 CONTRACTS AT EntryPrice STOPENDIFIF OnMarket THENSET STOP LOSS StopLossENDIF// Conditions to enter Short positionsIF NOT ShortOnMarket AND tradingtime and value1 THENSEllSHORT 0.5 CONTRACTS AT EntryPrice1 STOPENDIFIF OnMarket THENSET STOP LOSS StopLoss1ENDIF// Stops and targets : Enter your protection stops and profit targets here// points based STOP LOSS and TRAILING STOP// initial STOP LOSS//set target of positions at 40 pointsSET TARGET PROFIT 200 //(''takeprofit'' must be here if you want to achive 1:1 and remove below coding if not breakeven)//************************************************************************//trailing stop functiontrailingstart = 15 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************07/14/2025 at 9:17 PM #248876
The lines:
12IF NOT LongOnMarket AND tradingtime and value2 THENIF NOT ShortOnMarket AND tradingtime and value1 THENuse VALUE1 and VALUE2 as boolean variables, but they are NOT boolean variables as they are prices (high and low), so they will ALWAYS be true.
Can you explain what’s their purpose?
Moreover, the lines:
123456789IF OnMarket THENSET STOP LOSS StopLossENDIF...IF OnMarket THENSET STOP LOSS StopLoss1ENDIFwill always be BOTH executed. Since they are read and executed sequentially, the last one written in the code will override all prior SET STOP LOSS instruction; in this case only StopLoss1 will always be the real stop loss.
You should make them different by executing one of them for LONG trades and the other one for SHORT trades, this way:
1234567891011IF LongOnMarket THENSET STOP LOSS StopLossSET TARGET PROFIT StopLoss * 3 //1:3 ratioENDIF...IF ShortOnMarket THENSET STOP LOSS StopLoss1SET TARGET PROFIT StopLoss1 * 3 //1:3 ratioENDIFI also added the SET STOP PROFIT to 1:3 ratio, which you can change as best suits you.
07/14/2025 at 11:15 PM #2488771234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071DEFPARAM CumulateOrders = False// Timeframe : H1tradingtime=(time >= 090000 and time <=090000)if time=090000 thenvalue2 = highvalue1 = lowEntryPrice = (high) + (10* pipsize)EntryPrice1 = (low) - (10 * pipsize)StopLoss = range + (20 * pipsize) //10 pips below LOWStopLoss1 = range + (20 * pipsize) //10 pips above HIGHENDIF// Conditions to enter long positionsIF NOT LongOnMarket AND tradingtime THENBUY 1 CONTRACTS AT EntryPrice STOPENDIFIF LongOnMarket THENSET STOP LOSS StopLossSET TARGET PROFIT StopLoss * 3 //1:3 ratioENDIF// Conditions to enter Short positionsIF NOT ShortOnMarket AND tradingtime THENSEllSHORT 1 CONTRACTS AT EntryPrice1 STOPENDIFIF ShortOnMarket THENSET STOP LOSS StopLoss1SET TARGET PROFIT StopLoss1 * 3 //1:3 ratioENDIF//************************************************************************//trailing stop functiontrailingstart = 15 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************Hi Roberto,
Thank you very much as always. 🙂
I think I have removed everything and made it a bit clearer. Removed VALUE1 and VALUE2
Can I ask, If one of the orders got triggers long or short, will this not cancel the other order? Let’s say if the long order got triggered, short order should be cancelled and the long order SL should be the same within that tradingtime right?
if not both orders will get trigger. if the long order get triggered aggressively and hit the SL then short order will get triggered at the same time. is there a way to stop this?
07/15/2025 at 10:29 AM #248885Line 3 could simply read:
1tradingtime=090000To make sure pending orders not triggered are not placed again (they are automatically cancelled each bar, so you simply have to stop placing them when already at market), so replace both IF NOT LongOnMarket AND tradingtime THEN and IF NOT ShortOnMarket AND tradingtime THEN by:
1IF NOT OnMarket AND tradingtime THENAs to “if not both orders will get trigger. if the long order get triggered aggressively and hit the SL then short order will get triggered at the same time. is there a way to stop this?” the answer is NO, you can’t. If a pending order is triggered and hits the SL, the other order may also be triggered on the same bar, as all pending orders that haven’t been triggered are only cancelled when a bar closes.
07/15/2025 at 5:50 PM #248892Thank you Roberto for your kind help.
kinda makes sense now. I will still keep the time range, as I like to work with different time ranges. I really appreciate your help and sharing of knowledge!
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071DEFPARAM CumulateOrders = False// Timeframe : H1tradingtime=(time >= 090000 and time <=090000)if time=090000 thenvalue2 = highvalue1 = lowEntryPrice = (high) + (10* pipsize)EntryPrice1 = (low) - (10 * pipsize)StopLoss = range + (20 * pipsize) //10 pips below LOWStopLoss1 = range + (20 * pipsize) //10 pips above HIGHENDIF// Conditions to enter long positionsIF NOT OnMarket AND tradingtime THENBUY 1 CONTRACTS AT EntryPrice STOPENDIFIF LongOnMarket THENSET STOP LOSS StopLossSET TARGET PROFIT StopLoss * 3 //1:3 ratioENDIF// Conditions to enter Short positionsIF NOT OnMarket AND tradingtime THENSEllSHORT 1 CONTRACTS AT EntryPrice1 STOPENDIFIF ShortOnMarket THENSET STOP LOSS StopLoss1SET TARGET PROFIT StopLoss1 * 3 //1:3 ratioENDIF//************************************************************************//trailing stop functiontrailingstart = 15 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on 