There’s a major issue, TRADEPRICE is not known when BUY is executed, until the next candle.
Due to this it will retain the exit price of the prior trade or 0 the very first time making the stop loss negative.
To overcome this I’d change line 54 using the current price and saving the ST value for a later use:
MyST = (st1 + st2 + st3) / 3 )
set stop loss (close - MyST)
then I would append these lines at the end, for the next candle:
If OnMarket and Not OnMarket [ 1 ] then
set stop loss (tradeprice - MyST)
Endif
This will grant you an initial stop loss, making it more accurate next candle.
1 user thanked author for this post.