I received the erro in attached during my ALgo .
Ithink could be the trailing code ,
SL = stoploss // Initial SL
TP = TP
TSL = 1 // Use TSL?
TrailingDistance = 5 // Distance from close to TSL
TrailingStep = 5 // Pips locked at start of TSL
//************************************************************************
IF TSL = 1 THEN
//reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
CAND = 0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL = 0 AND CLOSE - TRADEPRICE(1) >= TrailingDistance*PipSize THEN
newSL = TRADEPRICE(1) + TrailingStep*PipSize
ENDIF
//next moves
CAND = BarIndex - TradeIndex
IF newSL > 0 AND CLOSE[1] >= HIGHEST[CAND](CLOSE) THEN
newSL = CLOSE[1] - TrailingDistance*PipSize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
ENDIF
SET STOP pLOSS SL
ENDIF
Could you please help to understand better ?
Thanks
Without the complete code is impossible to replicate it.
You should, besides posting code, tell us what instrument, TF and backtest range it is.
This problem is obvious, you cannot use an instruction with a period of 0, it is the case in your code at line 24, with the Highest instruction.
Replace line 23 with
CAND = max(1,BarIndex - TradeIndex)
to make sure CAND is not 0.