Validation failed [Volume limit reached]

 

Hi

I want to upload my EA to the market 

i get a error at the  Automatic validation ( When i run it on back test or real accound i dont get any error )

Automatic validation error

the code is 

double optimallotsize(double PercentLossFortrade, double EntryPrice, double StopLossPrice , string SYMBOL)
{
   if(PercentLossFortrade>5) PercentLossFortrade=5;
   double tick_size=SymbolInfoDouble(SYMBOL,SYMBOL_TRADE_TICK_SIZE);
   double tick_value=SymbolInfoDouble(SYMBOL,SYMBOL_TRADE_TICK_VALUE);
   double stop_loss_distance=MathAbs(EntryPrice-StopLossPrice);
   double risk_dollar=AccountInfoDouble(ACCOUNT_EQUITY)*PercentLossFortrade*0.01;
   double VOLUME_STEP=SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_STEP);
   int normalize=2;
   if(VOLUME_STEP==1) normalize=0;
   double optimal_lot_before=NormalizeDouble((risk_dollar/(stop_loss_distance/tick_size*tick_value)),normalize);
   int vol_ratio=optimal_lot_before/SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_STEP);
   double optimallotsize=vol_ratio*SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_STEP);
   Alert("Your account equity is = " + AccountInfoDouble(ACCOUNT_EQUITY));
   Alert("Allowed order size to fill is= " + optimallotsize);   
   if (optimallotsize<SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_MIN)) optimallotsize=SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_MIN);
   else if(optimallotsize>SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_MAX)) optimallotsize=SymbolInfoDouble(SYMBOL,SYMBOL_VOLUME_MAX);
   return optimallotsize;
}

i read that i need to use the 

SYMBOL_VOLUME_limit

but it return me 0.0 and i realy didnt understand how i need to use it 


any help please ?

 
Michael Katz: I want to upload my EA to the market i get a error at the  Automatic validation ( When i run it on back test or real accound i dont get any error ) the code is i read that i need to use the but it return me 0.0 any help plz ?

On my broker it also returns 0.0, however we could assume that under the test conditions of the verification process, that it may in fact return a valid value, so I did a search and found some advice on another thread:

Forum on trading, automated trading systems and testing trading strategies

Upload EA on Market

Sergey Golubev, 2020.04.10 14:10

The checks a trading robot must pass before publication in the Market 

Before making a trade request for placing a pending order by a symbol, you should check the limitation on the total volume of open position and pending orders on one symbol - SYMBOL_VOLUME_LIMIT. If there is no limitation, then the volume of a pending order cannot exceed the maximum allowed volume that can be received using the SymbolInfoDouble() volume.

double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);
if(max_volume==0) volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
----------------

https://www.mql5.com/ru/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_integer 

SYMBOL_VOLUME_LIMIT

Maximum allowed aggregate volume of an open position and pending orders in one direction (buy or sell) for the symbol. For example, with the limitation of 5 lots, you can have an open buy position with the volume of 5 lots and place a pending order Sell Limit with the volume of 5 lots. But in this case you cannot place a Buy Limit pending order (since the total volume in one direction will exceed the limitation) or place Sell Limit with the volume more than 5 lots.

double

Forum on trading, automated trading systems and testing trading strategies

MQL5: Validation :-( I have already broken my mind over the search for what it is and how it is solved.

Alexandr Gavrilin , 2018/11/27 08:04

I decided.

 //в функции до открытия ордера.

double max_volume= SymbolInfoDouble (m_name, SYMBOL_VOLUME_LIMIT );

       double current_lots=getAllVolume();

       if (max_volume> 0 && max_volume-current_lots-dlot<= 0 )
        {
         //PrintFormat("%.2f - %.2f",max_volume , dlot);
         return 0 ;
        }
//...
//функция подсчета объема
double getAllVolume()
     {
       int itotal= PositionsTotal ();
       ulong uticket=- 1 ;
       double dVolume= 0 ;

       for ( int i=itotal- 1 ;i>= 0 ;i--)
        {
         if (!(uticket= PositionGetTicket (i))) continue ;

         if ( PositionGetString ( POSITION_SYMBOL )==m_symbol.Name())
            dVolume+= PositionGetDouble ( POSITION_VOLUME );
        }

      itotal= OrdersTotal ();

       for ( int i=itotal- 1 ;i>= 0 ;i--)
        {
         if (!(uticket= OrderGetTicket (i))) continue ;

         if ( OrderGetString ( ORDER_SYMBOL )==m_symbol.Name())
            dVolume+= OrderGetDouble ( ORDER_VOLUME_CURRENT );
        }

       return dVolume;
     }
After that, the product successfully passed the test.

Forum on trading, automated trading systems and testing trading strategies

MQL5: Validation :-( I have already broken my mind over the search for what it is and how it is solved.

Vladimir Karputov , 2018/11/27 11:36

Yes, by the way, consider when calculating that SYMBOL_VOLUME_LIMIT can be equal to "0.0".

In order not to fall for verification:

 if (check_volume > SymbolInfoDouble (Symbol(), SYMBOL_VOLUME_LIMIT ))
   return ;
Reason: