Download MetaTrader 5
To add comments, please log in or register
Do you want to write a trading robot? Find solution in MQL5 Reference!
cstangor 2016.12.01 20:18 

I've copied the script exactly from the docs:

...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
Trade Functions / OrderSend - Reference on algorithmic/automated trading language for MetaTrader 5
Ricardo Rojas
Ricardo Rojas 2016.12.01 20:36  

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.

honest_knave 2016.12.01 21:42  

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);
cstangor 2016.12.01 22:17  

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

To add comments, please log in or register