Just in case someone stumbles on this....
My mistake was that I did not take Tick Size into consideration. To fix:
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
_stop = MathCeil(GetStopLevel(ATR[0], "sell", openPrice) / tickSize) * tickSize;
_profit1 = MathFloor(NormalizeDouble(openPrice - (ATR[0] * FirstTakeProfitMultiplier), digits) / tickSize) * tickSize;
Did that fix the issue? Another thing to be aware of is that the minimum distance requirement from the broker?
For other users who may have the same question:
//+--------------------------------------------------------------------------------------------------------------------+ //| This function normalizes and adjusts the price to the TICK SIZE | //+--------------------------------------------------------------------------------------------------------------------+ bool NormalizePrice(string symbol, double &price) { //--- Local variables long decimal_digits = 0; double tick_size = 0.0; //--- Get the minimal price change if(!SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE, tick_size)) { Print(__FUNCTION__, " - Error getting the SYMBOL_TRADE_TICK_SIZE: ", GetLastError(), " - ", symbol); return(false); } //--- Get the number of decimal digits if(!SymbolInfoInteger(symbol, SYMBOL_DIGITS, decimal_digits)) { Print(__FUNCTION__, " - Error getting the SYMBOL_DIGITS: ", GetLastError(), " - ", symbol); return(false); } //--- Return the price normalized if(tick_size == 0.0) { price = NormalizeDouble(price, (int)decimal_digits); } //--- Return the price normalized and adjusted to the TICK SIZE else { price = NormalizeDouble(MathRound(price / tick_size) * tick_size, (int)decimal_digits); } //--- Successful normalization return(true); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello All,
I generally do not ask for help. Nevertheless, I have been wrestling with this problem for several weeks and have been unable to get past it. I have been translating my EA's to MQL5 from MQL4. These work perfectly in MQL4. However, when executing, I keep getting an invalid stops. I have already done all of the obvious which is print out the levels, adjust the stops if they are inside the levels, etc. I even contacted the broker to see if there was with the specific symbol (I am using USA30 with Hot Forex).
One specific entry is:
2024.06.11 06:22:31.938 2023.04.04 10:15:00 deal performed [#2 sell 0.67 USA30 at 33619.80]
When I go to modify the order, I get:
2024.06.11 06:22:31.941 2023.04.04 10:15:00 failed modify #2 sell 0.67 USA30 sl: 0.00, tp: 0.00 -> sl: 33636.30, tp: 33562.05 [Invalid stops]
My debug Print, however, shows that the Stop Loss is way outside of the imposed minimum:
2024.06.11 06:22:31.941 2023.04.04 10:15:00 MODIFY ORDER ERROR OCCURRED: 10016 Order Price: 33619.8 Min SL Price: 33619.200000000004
Any ideas?