There is so many problems with you code that it's surprising it place a trade
See your issue about stoploss. Why are using this loop ?
for(int i=0;i<30;i++)
Inside this loop you set :
StopLoss=STL[i+1];
But your STL array can only have a size of 3.
CopyBuffer(STLH,0,0,3,STL);
Print your stoploss value, and the market price at the time you got the error.
I strongly suggest you to check the returned value of any function you are using, they can produce an error.
Also you have to normalize your price.

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
- www.mql5.com
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to create a fix stoploss, using the value of indicator at the bar that gives the buy signal.
For example:
In this case, the position will be open at the new bar open.
I am trying to capture the value of indicator at the bar that gives the buy signal.
When backtest starts, the first position always works, adjusting the stoploss value, and closing the position.
The Error message starts to appear, after finished the first position and trying to place stop on second condition...
The whole code: