EA Market Upload - [Invalid Price]

 

Hello,


I am attempting to upload my EA to the Market place and I keep getting this validation error. I don't really see the issue since my price / sl / tp all appear to be valid. Any help would be much appreciated.

I cannot reproduce in my strategy tester.

Here is validation output:

test on EURUSD,H1 (hedging)
 2022.02.01 16:30:00   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:00   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:01   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:01   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:02   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:02   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:03   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:03   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:04   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:04   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:05   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:05   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:06   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:06   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:07   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:07   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:08   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:08   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:09   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
 2022.02.01 16:30:09   failed sell stop 0.2 EURUSD at 1.12680 sl: 1.12781 tp: 1.12387 [Invalid price]
 2022.02.01 16:30:10   failed buy stop 0.2 EURUSD at 1.12715 sl: 1.12614 tp: 1.13008 [Invalid price]
strategy tester report 4320 total trades
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 

Please search 🔍 before you post. Your question has already been discussed multiple times on the forum.

The price may be invalid in terms that it may be too close to current market price or violate the symbol's contract specifications.

Please, also read the following ...

Articles

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.

And the following ...


 
Fernando Carreiro #:

Please search 🔍 before you post. Your question has already been discussed multiple times on the forum.

The price may be invalid in terms that it may be too close to current market price or violate the symbol's contract specifications.

Please, also read the following ...

And the following ...

Thanks for responding Fernando. I have searched the forums extensively and I have read the article and implemented the majority of the checks hence why I posted here. I have yet to find information in that article that would relate to the issue I am experiencing with [Invalid price]. Taking the information provided by the logs (which I cannot reproduce on the exact symbol and timeframe in my Strategy Tester) I see nothing invalid about the price, I have gone as far as adding this simple code to prevent my BuyStop and SellStop from potentially failing:

if (buyStopPrice < SymbolInfoDouble(_Symbol, SYMBOL_ASK)) return;
if (sellStopPrice > SymbolInfoDouble(_Symbol, SYMBOL_BID)) return;


So since I have spent several days troubleshooting I figured I would post here in case someone has experienced the same symptom and am hopeful that if I can find my solution it can be captured here for someone else to use in the future.

 
Tyler James Thomas #:

Thanks for responding Fernando. I have searched the forums extensively and I have read the article and implemented the majority of the checks hence why I posted here. I have yet to find information in that article that would relate to the issue I am experiencing with "[Invalid price]. Taking the information provided by the logs (which I cannot reproduce on the exact symbol and timeframe in my Strategy Tester) I see nothing invalid about the price, I have gone as far as adding this simple code to prevent my BuyStop and SellStop from potentially failing:

So since I have spent several days troubleshooting I figured I would post here in case someone has experienced the same symptom and am hopeful that if I can find my solution it can be captured here for someone else to use in the future.

You are ignoring the Stops Level and Freeze Level. The following is from the MQL4 documentation but it is still valid for MQL5 ...

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

StopLevel Minimum Distance Limitation.

A trade operation will not be performed if any of the following conditions is disrupted.

Order Type
Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited
Bid-SL StopLevel TP-Bid StopLevel
Sell
Modification is prohibited SL-Ask StopLevel Ask-TP StopLevel
BuyLimit
Ask-OpenPriceStopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellLimit
OpenPrice-Bid StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel
BuyStop
OpenPrice-Ask StopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellStop
Bid-OpenPrice StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel

FreezeLevel Limitation (Freezing Distance).

Market orders can not be closed if the StopLoss and TakeProfit values violate the FreezLevel parameter requirements.
StopLoss or TakeProfit orders can not be modified if StopLoss or TakeProfit values violate the StopLevel parameter requirements.
Pending orders can not be deleted or modified if the declared open price violates the FreezeLevel parameter requirements.

Order Type
Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited Bid-SL > FreezeLevel TP-Bid > FreezeLevel
Sell
Modification is prohibited SL-Ask > FreezeLevel Ask-TP > FreezeLevel
BuyLimit
Ask-OpenPrice > FreezeLevel Regulated by the StopLevel parameter
Regulated by the StopLevel parameter
SellLimit
OpenPrice-Bid > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
BuyStop
OpenPrice-Ask > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
SellStop
Bid-OpenPrice > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
  • book.mql4.com
Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
 
Fernando Carreiro #:

You are ignoring the Stops Level and Freeze Level. The following is from the MQL4 documentation but it is still valid for MQL5 ...

Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

StopLevel Minimum Distance Limitation.

A trade operation will not be performed if any of the following conditions is disrupted.

Order Type
Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited
Bid-SL StopLevel TP-Bid StopLevel
Sell
Modification is prohibited SL-Ask StopLevel Ask-TP StopLevel
BuyLimit
Ask-OpenPriceStopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellLimit
OpenPrice-Bid StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel
BuyStop
OpenPrice-Ask StopLevel OpenPrice-SL StopLevel TP-OpenPrice StopLevel
SellStop
Bid-OpenPrice StopLevel SL-OpenPrice StopLevel OpenPrice-TP StopLevel

FreezeLevel Limitation (Freezing Distance).

Market orders can not be closed if the StopLoss and TakeProfit values violate the FreezLevel parameter requirements.
StopLoss or TakeProfit orders can not be modified if StopLoss or TakeProfit values violate the StopLevel parameter requirements.
Pending orders can not be deleted or modified if the declared open price violates the FreezeLevel parameter requirements.

Order Type
Open Price StopLoss (SL) TakeProfit (TP)
Buy
Modification is prohibited Bid-SL > FreezeLevel TP-Bid > FreezeLevel
Sell
Modification is prohibited SL-Ask > FreezeLevel Ask-TP > FreezeLevel
BuyLimit
Ask-OpenPrice > FreezeLevel Regulated by the StopLevel parameter
Regulated by the StopLevel parameter
SellLimit
OpenPrice-Bid > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
BuyStop
OpenPrice-Ask > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter
SellStop
Bid-OpenPrice > FreezeLevel Regulated by the StopLevel parameter Regulated by the StopLevel parameter

Thank you for pointing me in the right direction Fernando. In case it's helpful to anyone else implementing SYMBOL_TRADE_STOPS_LEVEL overcame my issue.

double stopLevel = SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) * _Point;
double buyPrice = NormalizeDouble(ask + stopLevel, _Digits);
trade.BuyStop(lotSize, buyPrice, _Symbol, sl, tp, ORDER_TIME_DAY)