Forums › ProRealTime English forum › ProOrder support › Trailing stops remaining static when there are multiple positions › Reply To: Trailing stops remaining static when there are multiple positions
You could code something like this in to your code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
sl = 144 slmove = 5 if not onmarket and (your long entry conditions) then buy 1 contract at market slprice = close - sl sell at slprice stop endif if not onmarket and your short entry conditions) then sellshort 1 contract at market slprice = close + sl exitshort at slprice stop endif if longonmarket and high - sl > slprice + slmove then slprice = high - sl endif if shortonmarket and low + sl < slprice - slmove then slprice = low + sl endif sell at slprice stop exitshort at slprice stop |
It checks the high at the candle close and if price moved ‘slmove’ pips above your last calculated stop loss price it adjusts your stop loss to be ‘sl’ pips below that high. The opposite for short trades compared to low.
The only downside is that the starting stop loss is calculated off of the close price because we do not know what our TRADEPRICE is at this point so if there is a gap to the next open then your stoploss might not be the desired distance away. I’ll try to code something to at least correct the stop loss distance after one candle.