Invalid Volume - Error during EA Validation

Hadi Sadek  

Hello,

i am getting the below when publishing my EA, it fails validation, i tried with many lot sizes. can you help please 


test on EURUSD,H1 (netting) 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:00 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:01 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:02 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:03 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] 2019.04.18 11:00:03 failed instant sell 0.1 EURUSD at 1.12705 sl: 1.15713 tp: 1.12513 [Invalid volume] 2019.04.18 11:00:03 failed instant sell 0.1 EURUSD at 1.12706 sl: 1.15714 tp: 1.12514 [Invalid volume] there are no trading operations

Sergey Golubev  

There is one article which every seller on the market should read: it is about validation of the Market products - 

---------------- 

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

Why products are checked before they are published in the Market 

Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products.

If any errors are identified by the Market moderators in the process of checking your product, you will have to fix all of them. This article considers the most frequent errors made by developers in their trading robots and technical indicators. We also recommend reading the following articles: 

Zsolt Szabo  

Hello,


During the validation of my EA publishing I am get the failure message:

  validation failure messages

It looks the expert wants to buy bigger lot then the maximum. But during the test in "Strategi Tester" at same symbol (EURUSD), or on any other symbol there is no failure like this. It is inpossible, because I determin, if the calculated lot size bigger than the symbol max lot size, have to use the symbol max lot.

Max lot calc


Could anybody help me what is the problem?

Thanks for advance!

Fernando Carreiro  
Zsolt Szabo #: During the validation of my EA publishing I am get the failure message: It looks the expert wants to buy bigger lot then the maximum. But during the test in "Strategi Tester" at same symbol (EURUSD), or on any other symbol there is no failure like this. It is inpossible, because I determin, if the calculated lot size bigger than the symbol max lot size, have to use the symbol max lot. Could anybody help me what is the problem?

You seem to be calculating your lots incorrectly. A volume of "92233.72036865776808M" does not seem valid at all.

Are you verifying all the contract specifications for the symbol, including "SYMBOL_VOLUME_LIMIT"?

Are you also adjusting/normalising the lots as per the "SYMBOL_VOLUME_STEP"?

SYMBOL_VOLUME_MIN

Minimal volume for a deal

double

SYMBOL_VOLUME_MAX

Maximal volume for a deal

double

SYMBOL_VOLUME_STEP

Minimal volume change step for deal execution

double

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

Zsolt Szabo  
Fernando Carreiro #:

You seem to be calculating your lots incorrectly. A volume of "92233.72036865776808M" does not seem valid at all.

Are you verifying all the contract specifications for the symbol, including "SYMBOL_VOLUME_LIMIT"?

Are you also adjusting/normalising the lots as per the "SYMBOL_VOLUME_STEP"?

SYMBOL_VOLUME_MIN

Minimal volume for a deal

double

SYMBOL_VOLUME_MAX

Maximal volume for a deal

double

SYMBOL_VOLUME_STEP

Minimal volume change step for deal execution

double

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

            double freeMargin = AccountInfoDouble(ACCOUNT_FREEMARGIN);
            double maxLot = ((freeMargin / TradeContractSize * Leverage *1/Ask) -lotstep) * lotPerc;
            double maxLotNorm = (double)(MathRound(maxLot) / lotPerc);
            if((double)maxLotNorm < (double)SymbolMinLot){
            Print("Lot less then SymbolMinLot.");
            }
            if( (double)maxLotNorm > (double)SymbolMaxLot ){
            maxLotNorm = SymbolMaxLot;
            }          
//////////////////////////////////////// BUY //////////////////////////////
            
            trade.Buy(maxLotNorm,_Symbol,0,SL_In_Buy,lastBarOpenM15_3);

May yes, but something wrong just I don't know what? :/

Fernando Carreiro  
Zsolt Szabo #:May yes, but something wrong just I don't know what? :/

No! Volume should be calculated based on risk (stop-loss) and then adjusted based on margin requirements. It should not be calculated from the leverage and contract size ...

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference

if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) )
{
   dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) )
               * dbLotsStep, dbLotsMin ), dbLotsMax ); 
      
   // the rest of the code ...
};

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

Forum on trading, automated trading systems and testing trading strategies

Complete formula for calculating forex pip value for XAUUSD with account funded in euros

Fernando Carreiro, 2022.08.29 15:43

One more thing that should be considered by the OP or those following this thread ...

After you determine your volume (lots) for your risk amount, you should then check that against the free margin, useing the OrderCalcMargin (MQL5) or order_calc_margin (Python), to verify that the amount of margin that will be required is available in your free margin.

In fact, make sure that the required margin plus the risk is not greater than your free margin and that it will not cause a margin call or stop out.

I personally set a margin % limit and reduce the lot size if required. For example, I set a maximum % margin of 5-10% and use the OrderCalcMargin to adjust the volume to reduce the volume should the margin be higher than my limit.

The reason I set it to 5-10% is because I have to account for multiple positions in the market if I am trading on multiple symbols at the same time. If I were to allow a maximum margin on my balance, then I would not have any free margin left to trade on other symbols.

amrali  

I think you try to calculate position size as a ratio of account free margin:

//--- Calculate volume as a percentage of account free margin.
double CalcVolume(string symbol, double lotPerc)
  {
   double volume = (freeMargin / TickValue * TickSize * Leverage *1/Ask) * lotPerc;

//--- Round volume to stepvol.
   volume=MathFloor(volume/stepvol)*stepvol;

//--- Adjust volume to broker limits.
   volume=MathMin(MathMax(volume,minvol),maxvol);

   return(volume);
  }

Edit: the above code may not work on non-forex symbols as gold, silver.

For a code that works well:

//--- Calculate volume as a percentage of account free margin.
double CalcVolume(string symbol, double lotPerc)
  {
   double margin=0.0;
   bool res=OrderCalcMargin(ORDER_TYPE_BUY,symbol,1.0,Ask,margin);

   double volume = (freeMargin / margin) * lotPerc;

//--- Round volume to stepvol.
   volume=MathFloor(volume/stepvol)*stepvol;

//--- Adjust volume to broker limits.
   volume=MathMin(MathMax(volume,minvol),maxvol);

   return(volume);
  }
Zsolt Szabo  

Thanks for all of support. @amrali's proposal solved my "invalid volume" problem. However, appeared some other problems. Experts define always the biggest lot that is possible to buy, and buy it. (I know it is not the best strategy but I want to do this). Sometimes (independent of the calculation) the lot price is a little bit bigger than the free margin. What is the cause of this? What can I do against it?

No Money

Fernando Carreiro  
Zsolt Szabo #: Thanks for all of support. @amrali's proposal solved my "invalid volume" problem. However, appeared some other problems. Experts define always the biggest lot that is possible to buy, and buy it. (I know it is not the best strategy but I want to do this). Sometimes (independent of the calculation) the lot price is a little bit bigger than the free margin. What is the cause of this? What can I do against it?


Not only is it "bad" for the strategy it is also "bad" for your account. When the margin requirement are too large it is not allowed. That is why I wrote for you to use OrderCalcProfit AND OrderCalcMargin.

Please take some time to learn the basics of trading and proper risk management, especially if you plan to sell your product. Otherwise you and your products will end up getting a bad reputation.

amrali  
Zsolt Szabo #:

Thanks for all of support. @amrali's proposal solved my "invalid volume" problem. However, appeared some other problems. Experts define always the biggest lot that is possible to buy, and buy it. (I know it is not the best strategy but I want to do this). Sometimes (independent of the calculation) the lot price is a little bit bigger than the free margin. What is the cause of this? What can I do against it?


As Fernando said, using unsafe money management strategies like the above one is not advised.