Before modify check if anything has changed. Like the error suggests.
There is a check. It should be modified only if lastClosePrice+LastAverageTrueRangeValue*2.4 is lower than PositionGetDouble(POSITION_SL).
There is a check. It should be modified only if lastClosePrice+LastAverageTrueRangeValue*2.4 is lower than PositionGetDouble(POSITION_SL).
if( SL < CurrentStopLoss-_Point )
You should normalize SL
//SL double SL=NormalizeDouble(lastClosePrice+LastAverageTrueRangeValue*2.4, _Digits); if(SL<CurrentStopLoss)
You should normalize SL
I will try it out. Thank you
- SL/ TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
-
MathRound() and NormalizeDouble() are rounding in a different way. Make it
explicit.
MT4:NormalizeDouble - General - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
You used NormalizeDouble, It's use is usually wrong, as it is in your case.
- SL/ TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
-
MathRound() and NormalizeDouble() are rounding in a different way. Make it
explicit.
MT4:NormalizeDouble - General - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
I will look into it. But in my function I use values from yestarday and they do not change anymore right. Thats why I dont get why my if-check doesnt work properly.
I will look into it. But in my function I use values from yestarday and they do not change anymore right. Thats why I dont get why my if-check doesnt work properly.
You can add a Print() statement, perhaps before your if check, to see the values of SL and CurrentStopLoss - that'll take all the guess works out of the way.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone,
so I have a trailing stop function which works but once it changes my SL it keeps doing it again and again
So this is the function
Does anyone have an idea how to fix this?