Traders and coders are working for free:
- if it is interesting for them personally, or
- if it is interesting for many members of this forum.
Freelance section of the forum should be used in most of the cases.
- 2024.11.07
- www.mql5.com
Hi
You should probably check also Stoplevel for the sl/tp levels. For testing purposes (when broker don't return proper values of required levels) it's good to set this "minimum" allowed level as 2 points at least - to avoid any problems with this lack of data.
Also you could normalize used prices and round it to nearest tick. Try something like this for all used prices:
double freeze_level = MathMax(2, MathMax( SymbolInfoInteger(Symbol(), SYMBOL_TRADE_FREEZE_LEVEL ), SymbolInfoInteger( Symbol(), SYMBOL_TRADE_STOPS_LEVEL ) ))*_Point; .. newSL = MathMin(newSL, BID-freeze_level)); double ts = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE); if(ts==0) newSL = NormalizeDouble(newSL, (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS)); //no normalization if no ticksize info else newSL = ( MathRound(newSL/ts) * ts );
Check also other requirements here: https://www.mql5.com/en/articles/2555
Have a nice day👍📊
t tick.
Thank you, Marzena. I already have a minimum of 1 point for Freeze Level. You are recommending 2 points. I will try that and report back.
You said "check also Stoplevel for the sl/tp levels." As fas as I know, that is not needed to "modify" a position, only needed when opening the position (at the order).
Your suggestion of normalize prices using tick values: I will try that too, but I don't understand why it should play a role in Forex (where Point is the smallest value used).
I am aware of the article 2555 and I have implemented such checks already.
Thank you so much for your help
I did these tests. Here are the results:
1) changing the minimum FREEZE level to 2 points: didn't change the outcome. Same error, same everything.
2) In EURUSD I get: Point size = Tick size = _Digits = 0.00001, so normalizing with tick size is the same as I was doing normalizing with _Digits.
3) I tried with a FREEZE and STOP level of minimum 10 points, and the invalid stops disappeared. This is a mystery, because whatever levels are required, I check them before sending the modification order.
If any of the moderator can explain what is going on, please do so.
I re-ran the sim, (with 10 points minimum levels) I get the [Invalid Price] error (by the way, it happens at a previous year->2021; another mystery).
Here is the message:
when I run it is in my computer, I get the identical time, price, SL and got the order filled with no errors (see below), however, the automatic validation gives me an error (look at the first error above).
can any of you give me a reason why the automatic validation sends an error, but my own simulation is passing fine?
thank you
For completeness, this is the piece of code where the stop_level is checked before sending the order to buy or sell.
Notice that the price is given, while SL and TP are reassigned to satisfy the stop_level requirements.
everything is NormalizedDouble() with _Digits afterwards, and then the order is sent.
case ORDER_TYPE_BUY_LIMIT: case ORDER_TYPE_BUY_STOP: newSL=MathMin(newSL, price-stop_level); newTP=tp==0?0:MathMax(newTP, price+stop_level); break; case ORDER_TYPE_SELL_LIMIT: case ORDER_TYPE_SELL_STOP: newSL=MathMax(newSL, price+stop_level); newTP=tp==0?0:MathMin(newTP, price-stop_level); break;
I appreciate any help from a moderator on how to pass the Automatic Validation. It's been several days and I can't find the reason the EA does not comply with the validation because my local simulation does pass it in a Metaquotes Demo account.
Again, I have read and followed the article 2555.
thank you
Well, no moderator came to advise in this problem.
I figured out that the Automatic Validation does not like pending orders (Stop Buy/Sell, Limit Buy/Sell). I made all checks of stop_level, freeze_level, and the Automatic Validation always reported errors.
These errors of [Invalid Price] disappear as soon as I forced the EA to use market orders (Buy/Sell).
I also had to increase the minimum stop_level and freeze_level to 40 * _Points to pass the validation, but still would like to know why I don't get any error of Invalid Price when running on my computer even when the lot size, price,SL and TP are the same in my computer and in the error report from the Automatic Validation.
Any ways, thanks to Marzena for trying to help.
No! Your price calculations and alignment with the tick size is still incorrect. You simply don't see the error now because you are accepting the current market price.
I suggest you DO NOT ignore the issue. Make sure you implement all of the following and necessary checks ...
The checks a trading robot must pass before publication in the Market
MetaQuotes, 2016.08.01 09:30
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
No! Your price calculations and alignment with the tick size is still incorrect. You simply don't see the error now because you are accepting the current market price.
I suggest you DO NOT ignore the issue. Make sure you implement all of the following and necessary checks ...
Hi Fernando,
Thank you for taking time to take a look at this. I know what you mean. I bypassed the error by limiting all trades to market orders. But I have gone over that article dozens of times in the last two weeks before submitting the EA to the Automatic Validation, and I can't figure out what the problem is because I can't replicate the error in my computer.
As I wrote above, Point size = Tick size = _Digits = 0.00001 for EURUSD, so I didn't think it was needed to round a price by Tick instead of by Point. In any case, I switched to normalize prices using Symbol.NormalizePrice() which I am assuming will do it correctly.
I have implemented checks regarding stop_level when sending a pending order in multiple ways, but I've been unsuccessful. Here is the latest version of the code where I check and recalculate price/sl/tp at the opening of the trade, as needed.
I appreciate your feedback if you find anything wrong with it. I changed how to compute the ASK/BID using the MqlTick structure instead of calling the SymbolInfoDouble. It does not make a difference either way.
#define ASK (g_tick.ask) #define BID (g_tick.bid) #define MINSTOPPOINTS (40) #define STOPLEVEL (MathMax(MINSTOPPOINTS,(double)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL))*_Point) void ReviewOpeningOrderForSTOP_LEVEL(double price, // input double sl, // input double tp, // input double &newPrice, // output double &newSL, // output double &newTP, // output ENUM_ORDER_TYPE ordtype) { // input // get latest tick data SymbolInfoTick(g_symbolName,g_tick); switch(ordtype) { case ORDER_TYPE_BUY: newSL=MathMin(sl, BID-STOPLEVEL); newTP=tp==0?0:MathMax(tp,BID+STOPLEVEL); break; case ORDER_TYPE_SELL: newSL=MathMax(sl, ASK+STOPLEVEL); newTP=tp==0?0:MathMin(tp,ASK-STOPLEVEL); break; case ORDER_TYPE_BUY_LIMIT: newPrice=price>=ASK?ASK-_Point:price; newSL=MathMin(sl, newPrice-STOPLEVEL); newTP=tp==0?0:MathMax(newTP, newPrice+STOPLEVEL); break; case ORDER_TYPE_BUY_STOP: newPrice=price<=ASK?ASK+_Point:price; newSL=MathMin(sl, newPrice-STOPLEVEL); newTP=tp==0?0:MathMax(tp, newPrice+STOPLEVEL); break; case ORDER_TYPE_SELL_LIMIT: newPrice=price<=BID?BID+_Point:price; newSL=MathMax(sl, newPrice+STOPLEVEL); newTP=tp==0?0:MathMin(tp, newPrice-STOPLEVEL); break; case ORDER_TYPE_SELL_STOP: newPrice=price>=BID?BID-_Point:price; newSL=MathMax(sl, newPrice+STOPLEVEL); newTP=tp==0?0:MathMin(tp, newPrice-STOPLEVEL); break; } newPrice=g_symbol.NormalizePrice(newPrice); newSL=g_symbol.NormalizePrice(newSL); newTP=g_symbol.NormalizePrice(newTP); return; }
Oops, I saw a typo in the
case ORDER_TYPE_BUY_LIMIT: newPrice=price>=ASK?ASK-_Point:price; newSL=MathMin(sl, newPrice-STOPLEVEL); newTP=tp==0?0:MathMax(newTP, newPrice+STOPLEVEL); break;
The fourth line should read
newTP=tp==0?0:MathMax(tp, newPrice+STOPLEVEL);
But in any case, this is not the only the case where the "invalid price" happens. I get them in limit and also in stop orders.
Hi Fernando,
here are report errors after I fixed the typo error above. Same problem: pending orders "invalid price".

and here is my computer's simulation: same time, same prices, order send/triggered/performed (different volume, I don't know why).

It is hard to find an error when you can't replicate it locally. BTW, I am running "Every tick based on real ticks."
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use


The Automatic validation is giving errors that I can't reproduce in my computer.
Let's review just the first error of [Invalid Stops].
Here is the code to review the freeze level and adjust SL & TP
Above you can see the message from the automatic validation. Look at the first error at 2022:02:04 02:00:00.
Trade are modified with this piece of code (I added the way I compute the freeze_level in points, and the Print statements to show you the Journal tab below.
and the chart and Journal tab look like this:
The time, price,SL and TP values in the Automatic Validation report and the Journal are identical, but the report is giving be an error while my simulation is not.
The only difference would be the freeze_level used in the automatic validation, which I don't know, but it is checked before sending the modification.
I also have the other errors "invalid price" which I can't find any problem in my code either, but let's fix this "invalid stops" first, and then I come back with the others.
Please provide some help/advice/guidance.
thank you
Note: ASK and BID are defined as: