Invalid Volume in OrderSend

 

I've copied the script exactly from the docs:

https://www.mql5.com/en/docs/trading/ordersend

...but the script returns 10014 Invalid Volume.

Can anyone help me?

Thanks in advance.

Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Reference on algorithmic/automated trading language for MetaTrader 5
 

It may happened if you are sending a smaller volume than SYMBOL_VOLUMEN_MIN or greater than SYMBOL_VOLUME_MAX

You can obtain that information in this way:

 

double minSymbolLot =  SymbolInfoDouble(_Symbol, SYMBOL_VOLUMEN_MIN);

double maxSymbolLot =  SymbolInfoDouble(_Symbol, SYMBOL_VOLUMEN_MAX);

 

The lot must be between SYMBOL_VOLUMEN_MIN and SYMBOL_VOLUME_MAX.

 

And a multiple of lot step.

double LotAdjuster(double lots)
  {
   double minlot  = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN),
          maxlot  = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX),
          lotstep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   lots = MathRound(lots/lotstep)*lotstep;
   lots = MathMax(lots,minlot); 
   lots = MathMin(lots,maxlot);
   return(lots);
  }
 

Thanks to both of you .. that was very helpful and I got it working!

Reason: