- OrderProfit() question ...
- Trading: Comparative Analysis of 30 Indicators and Oscillators
- Why do I get OrderSend error on UK100?
131 | Invalid trade volume. |
You should backtest the EA with a larger lot size that exceeds the margin limit,
or the broker lot size limit. Then, of course you will get an error,
-- because the validation process performs that stage.
So, now you can set a new function to handle it automatically.
Regards.
You have to adjust your volume to SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_MAX and SYMBOL_VOLUME_STEP.
It seems to be more difficult than it appears.
It seems to be more difficult than it appears.
You can use this function to normalize volume:
double NormalizeVolume(const double volume,string symbol=NULL) { if(symbol==NULL || symbol=="") symbol=_Symbol; double volumeStep=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP); double volumeMin=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN); double volumeMax=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX); double volumeNormalized=int(volume/volumeStep)*volumeStep; return(volumeNormalized<volumeMin?0.0:(volumeNormalized>volumeMax?volumeMax:volumeNormalized)); }
You have to check if the returned value isn't zero (it means that your requested volume is less than the minimum allowed volume).
I am using this code for Money Management, it uses NormalizeDouble for round lots and minimum lot size (0.01):
//---------------------------------------------- Money management ---! double LotsOptimized(){ double LotSize=NormalizeDouble(AccountFreeMargin()*0.618*30/100000,2); if(LotSize<0.01){LotSize=0.01;} return(LotSize); }
So I think MQL5 system doesn't admit less than 0.1 lot, is it true?
131 | Invalid trade volume. |
You should backtest the EA with a larger lot size that exceeds the margin limit,
or the broker lot size limit. Then, of course you will get an error,
-- because the validation process performs that stage.
So, now you can set a new function to handle it automatically.
Regards.
I tried this and doesn't give that error anymore.
double LotsOptimized(){ double LotSize=NormalizeDouble(AccountFreeMargin()*0.618*30/100000,2); if(LotSize>MarketInfo(Symbol(),MODE_MAXLOT)){LotSize=MarketInfo(Symbol(),MODE_MAXLOT);} if(LotSize<MarketInfo(Symbol(),MODE_MINLOT)){LotSize=MarketInfo(Symbol(),MODE_MINLOT);} return(LotSize); }
Now it gives a new error code 134, I tried this:
if(AccountFreeMargin()<MarketInfo(Symbol(),MODE_MARGINREQUIRED)){return;}
And now error 131 again..............
I tried this and doesn't give that error anymore.
Now it gives a new error code 134, I tried this:
And now error 131 again..............
Passed!
"If a check shows that there are insufficient funds to perform a trade operation, it is necessary to output an error message to the log instead of calling the OrderSend() function".
Just added that error message and passed the validation. Thanks to all.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use