Invalid volume error, On Market product validation ONLY

 

I have been working on an update on one of my programs, The code to validate lot size seems fine mostly as I have used it in several programs in the market. Error:

test on EURUSD,H1 (netting)
 2021.02.05 00:00:00   failed instant buy 0.05 EURUSD at 1.19628, close #2 sell 0.05 EURUSD 1.21301 [Invalid volume]
 2021.06.11 00:00:00   failed instant sell 0.05 EURUSD at 1.21751, close #35 buy 0.05 EURUSD 1.21728 [Invalid volume]
 2021.07.09 00:00:00   failed instant buy 0.05 EURUSD at 1.18477, close #43 sell 0.05 EURUSD 1.18491 [Invalid volume]
strategy tester report 47 total trades
Code:
double LotValidate(double volume)
{
   // Get the minimum, maximum, and step size for the symbol
   double min_volume = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
   double max_volume = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX);
   double step_volume = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);

   // Check if the volume is less than the minimum
   if (volume < min_volume)
      return min_volume;

   // Check if the volume is greater than the maximum
   if (volume > max_volume)
      return max_volume;

   // Check if the volume is a multiple of the step size
   int ratio = (int) MathRound(volume / step_volume);
   double adjusted_volume = ratio * step_volume;
   
   if (MathAbs(adjusted_volume - volume) > 0.0000001)
      return adjusted_volume;
      
   return adjusted_volume;
}

However, this time when I submit it the program to the market, the validation fails due to invalid volume. Can anyone spot an issue

 
I have read the article https://www.mql5.com/en/articles/2555 several times and adopted the Lot size validation code several times but, the error persists
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
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.
 
Writer You should be helping not the other way around.
 
Ugochukwu Mobi #:
Writer You should be helping not the other way around.

So what If I need help? 

 

Verify the Minimum and Maximum volumes at the end, not at the beginning ...

Forum on trading, automated trading systems and testing trading strategies

Market Registration of EA Unable to Validate

Fernando Carreiro, 2022.08.30 14:20

For your screenshot with an Error 131 and it also has a link on "How to fix it". So follow up on it and fix your EA accordingly.

In regards to volume, you have to check the contract specification of the symbol and limit your volume to the minimum, maximum and step that is allowed for the symbol.

// Variables for symbol volume conditions
   double
      dbLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
      dbLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
      dbLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
       
// Adjust volume for allowable conditions
   dbLots = fmin(  dbLotsMaximum,                           // Prevent too greater volume
            fmax(  dbLotsMinimum,                           // Prevent too smaller volume
            round( dbLots / dbLotsStep ) * dbLotsStep ) );  // Align to step value
 
Fernando Carreiro #:

Verify the Minimum and Maximum volumes at the end, not at the beginning ...

Thanks, your suggestion and code works locally but, when I submit the program again I get the exact same error. I even had to add the limit volume condition just in case, the error was coming from that angle.

double PositionsVolume()
  {
    double vol= 0;
    for (int i=PositionsTotal()-1; i>=0; i--)
      if (m_position.SelectByIndex(i))
         if (m_position.Symbol()==Symbol())
            vol += m_position.Volume();

   
    for (int i=OrdersTotal()-1; i>=0; i--)
      if (m_order.SelectByIndex(i))
         if (m_order.Symbol()==Symbol())
            vol += m_order.VolumeCurrent();
           
    return vol;
  }

Then;

if (CheckMoneyForTrade(lotsize, ORDER_TYPE_SELL))
{
  if (volume_limit ==0 ? true : (lotsize + PositionsVolume()) < volume_limit)
     m_trade.Sell(lotsize, Symbol(), ticks.bid, NormalizeDouble(intern_sl, Digits()), NormalizeDouble(intern_tp, Digits())); //open a sell trade
}

I keep on getting the same error, still.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger() , SymbolInfoDouble() and SymbolInfoString() . The first...
 
Omega J Msigwa #: Thanks, your suggestion and code works locally but, when I submit the program again I get the exact same error. I even had to add the limit volume condition just in case, the error was coming from that angle.Then; I keep on getting the same error, still.

Yes, you also have to also check for total volume limit per symbol (SYMBOL_VOLUME_LIMIT), and for pending orders check the initial volume requested (ORDER_VOLUME_INITIAL).

Also, in your validation process, it is failing on a "netting" account, not a "hedging" account. There may be something else in your code that is contributing to the error due to the difference of account types. So make sure you test on a "netting" account on your own local testing.

 
Fernando Carreiro #:

Yes, you also have to also check for total volume limit per symbol  ( SYMBOL_VOLUME_LIMIT ), and for pending orders check the initial volume requested ( ORDER_VOLUME_INITIAL).

Also, in your validation process, it is failing on a "netting" account, not a "hedging" account. There may be something else in your code that is contributing to the error due to the difference of account types. So make sure you test on a "netting" account on your own local testing.

Yes, I agree. Let me find a netting broker and test in that specific environment.

 

Probably not related at all, but this is strange condition, mixing "if" and "?" operator :

  if (volume_limit ==0 ? true : (lotsize + PositionsVolume()) < volume_limit)

You should avoid that style.

  if (volume_limit ==0 || (lotsize + PositionsVolume()) < volume_limit)
 
Omega J Msigwa #:

Thanks, your suggestion and code works locally but, when I submit the program again I get the exact same error. I even had to add the limit volume condition just in case, the error was coming from that angle.

Then;

I keep on getting the same error, still.

Where is the "LotValidate" function call in this code ? It's not.
 
Omega J Msigwa:

I have been working on an update on one of my programs, The code to validate lot size seems fine mostly as I have used it in several programs in the market. Error:

Code:

However, this time when I submit it the program to the market, the validation fails due to invalid volume. Can anyone spot an issue

I have been getting this too even with all the checks.  Something is up with the validator