MQL5 wizard MA & PSAR trailing stop not working if initial SL is set


This has been driving me crazy, so I finally ground through and figured out exactly what is going on.

In the MQL5 wizard, if MA or PSAR trailing stop is selected, it doesn't work correctly (an otherwise profitable strategy becomes unprofitable) if the initial stop loss is set to anything other than 0.

To test this, I generated a simple MACD EA, with 4 trailing stop variations:  none, fixed, MA, and PSAR.

The fixed trailing stop behaves correctly, but the MA and PSAR only behave correctly if the initial stop loss is set to 0.

I used US2000, M1, and optimized the MACD values for year-to-date, with SL set to 0.

I then optimized the SL setting - nothing improved it over 0 SL, but 8640 was the first value that didn't actually hurt it, so I decided to use that for testing.

On the fixed trailing stop, with an initial SL of 8640, nothing improved results over the 0 SL, but at least there were values that were profitable, and close to the indicator-driven strategy.

But on both MA and PSAR, with initial SL set to 0, it's possible to optimize profitable results — again, not as good as the default strategy, but profitable.

But set the initial SL to 8640, and it's impossible to optimize the MA trailing stop or PSAR trailing stop.

This makes no sense and seems to me a likely bug in the MA and PSAR trailing stop code.