Forums › ProRealTime English forum › ProOrder support › BreakEven & Trailing Profit: complete function › Reply To: BreakEven & Trailing Profit: complete function
08/21/2025 at 4:26 PM
#249957
I found the issue (see Robertos-Trailing-PercentageWW).
It’s in these two lines:
1 2 |
SellPrice = max(SellPrice,PositionPrice + (y1 * pipsize)) ExitPrice = min(ExitPrice,PositionPrice - (y2 * pipsize)) |
because, sometimes the trailing stop EXCEEDED the current price, which should never be, as it might turn out that it’s never triggered and a loss is incurred in case the price retraces!
So just modify those two lines as follows, to make sure the current price (CLOSE) is never, ever, exceeded:
1 2 |
SellPrice = min(close,max(SellPrice,PositionPrice + (y1 * pipsize))) ExitPrice = max(close,min(ExitPrice,PositionPrice - (y2 * pipsize))) |