Modifying Long position SL
I don't see where do you check the new SL against the current market price in your code?
It was here...
trailing_stop=PositionGetDouble(POSITION_PRICE_CURRENT)-MathMax(StopFreeze(Ticker),trailing_points);
the new trailing stop price had to be below the the position's current price. Actually I had even tried the Bid price (in place of position current price), but I was still getting errors.
- www.mql5.com
What's StopFreeze(Ticker)? You have to compare the new SL to the current price (Bid for LONG) - it shouldn't be closer than SYMBOL_TRADE_STOPS_LEVEL to the current price.
Happy new year.
This
StopFreeze(Ticker)
was the maximum between the stops level which you have mentioned above, and the freeze level. 'Ticker' is just the string for the symbol name. Like I said above I was trying Bid price before and was still getting errors. I suspect its a bug in the CTrade class. I had to rewrite the trade class.
My EA needs to modify its position SL but sometimes gets the invalid stops error for long positions. The short positions are always modified without any problem.
Here is my source..
Is there a better way of implementing this?