When back testing I have a problem that i want my trade to stay on for at least one bar before it sells I have two programmes that I have written but dont know how to add the code or where inside the code to place it. Any help would be amazing, I have attached the robots below,
Are you talking about trade closure made my stoploss/takeprofit or made by your code’s conditions?
You can set your stoploss/takeprofit to 0 if your trade is less than 3 bars old (for example):
IF ONMARKET AND (BarIndex - TradeIndex(1)) >= 3 THEN
SET TARGET PPROFIT 20
SET STOP PLOSS 20
ELSE
SET TARGET PPROFIT 0
SET STOP PLOSS 0
ENDIF
Because PROFIT and LOSS must be set within the first bar, so you need to invalidate them before changing them (when it’s 3 bars old in this example).