validation error: no trading operations

 

my EA places buyStop and sellStop orders when certain criteria are met

after so many trials and errors, i realised the validation does not pass this line of code

   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   int stopLevel = (int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
   int freezeLevel = (int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL);

// for a buy stop order
            if(orderTP-orderEntry>=stopLevel && orderEntry-orderSL>=stopLevel)// does not pass through this line of code
              	if(orderEntry-ask>=freezeLevel)
	      	{
               	result = m_trade.BuyStop(NormalizeDouble(buyLot, 2), NormalizeDouble(orderEntry, _Digits), _Symbol, NormalizeDouble(orderSL, _Digits), orderTP, ORDER_TIME_GTC, 0, "FVG");
              	}
// for a sell stop order
            if(orderEntry-orderTP>=stopLevel && orderSL-orderEntry>=stopLevel) // does not pass through this line of code
		if(bid-orderEntry>=freezeLevel)              
		{
               	result = m_trade.SellStop(NormalizeDouble(sellLot, 2), NormalizeDouble(orderEntry, _Digits), _Symbol, NormalizeDouble(orderSL, _Digits), orderTP, ORDER_TIME_GTC, 0, "FVG");
              	}

but when that condition is removed, i get 'invalid price' errors during validation

but everything works fine on a my mt5 tester

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Crispin Tibilla:

my EA places buyStop and sellStop orders when certain criteria are met

after so many trials and errors, i realised the validation does not pass this line of code

but when that condition is removed, i get 'invalid price' errors during validation

but everything works fine on a my mt5 tester

You already have the solution. I mean, that code snippet is okay, and it's needed for one to pass validation. So, don't worry, them trade levels needs be checked.
Additionally, it is more safe for you to check also against the SYMBOL_FREEZE_LEVEL
 

thanks

i have fixed it now

i used only the freeze level as a check

double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
double bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);
int freezeLevel = (int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_FREEZE_LEVEL);


if(orderEntry-ask>=freezeLevel*_Point)
        result = m_trade.BuyStop(NormalizeDouble(buyLot, 2), NormalizeDouble(orderEntry, _Digits), _Symbol, NormalizeDouble(orderSL, _Digits), orderTP, ORDER_TIME_GTC, 0, "FVG");

if(bid-orderEntry>=freezeLevel*_Point)
        result = m_trade.SellStop(NormalizeDouble(sellLot, 2), NormalizeDouble(orderEntry, _Digits), _Symbol, NormalizeDouble(orderSL, _Digits), orderTP, ORDER_TIME_GTC, 0, "FVG");


 
Crispin Tibilla #:

thanks

i have fixed it now

i used only the freeze level as a check

Okay. You're welcome. Glad I could help.
Reason: