This trading system was stopped because the program used a negative or zero offset (ex: close[-10]) during the evaluation of the last candlestick. Please add protections to your code to prevent negative or zero offsets.
Because you have calculation period somewhere in your code and it returns a null or negative value. You might be able to fix this with ABS instruction.
If it doesn’t work, please post your code for a complete explanation of what happened.
In every every trade, when the first candle ran through and the system tried to evaluate the next candle, it ran on error
“… system was stopped because the program used a negative or zero offset (ex: close[-10]) during the evaluation of the last candlestick. …”
I solved it by just preventing the code to check “BarIndex – TradeIndex” when it is 0. This is always 0 in the first candle of the trade. So I added a simple condition to my code so that it looks as follows:
Thanks a lot for your feedback about how to resolve this kind of error. We could also test the Highest period with MAX instruction, to “force” the period to be at least 1 if it is inferior or Barindex-Tradeindex if it is superior: