This ProBuilder script demonstrates how to adjust a stoploss to breakeven in a multi-timeframe trading strategy. The code snippet provided below shows how to manage orders on two different timeframes: the 1-hour timeframe for the trading signal and the 1-minute timeframe for order management, specifically for moving the stoploss to breakeven once a certain profit target is achieved.
defparam cumulateorders=false
//declare the strategy on the 1 hour timeframe
timeframe(1 hour, updateonclose)
myrsi = rsi[14]
buycondition = myrsi crosses over 50
//orders management on the 1 minute timeframe
timeframe(1 minute, default)
//create an order at market if the RSI has crosses the level 50 on the 1 hour timeframe
if buycondition then
buy 10 contract at market
endif
//if not order on market, reset the breakeven status
if not onmarket then
breakeven=0
endif
//check if the current order has made 15 points of profit
if longonmarket and close-tradeprice>=15*pointsize then
breakeven=1
endif
//put stoploss at open price + 5 points if breakeven=1
if breakeven=1 then
sell at tradeprice+5*pointsize stop
endif
graph breakeven
Explanation of the Code:
defparam cumulateorders=false to ensure that orders do not stack up and each order is treated individually.timeframe(1 hour, updateonclose) function sets the primary trading signals to be generated based on the 1-hour chart, updating only at the close of each 1-hour candle.This code snippet is a practical example of how to implement a multi-timeframe strategy in ProBuilder, focusing on dynamic stoploss management based on real-time profit conditions.
Check out this related content for more information:
https://www.prorealcode.com/topic/move-sl-during-current-candle/#post-79130
Visit Link