Due to changes in MQL5, now the maximal overall volume allowed for one symbol can be obtained as following:
//--- get symbol limitation for volume double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);
Do not use the old variant! It was like this:
//--- get symbol limitation for volume double max_volume=AccountInfoDouble(ACCOUNT_LIMIT_VOLUME);The article has been corrected and the new Check_Order_And_Volume_Limits.mq5 expert code has been attached to it.
(build 306)
void OnStart()
{
double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);
}
compile errors:
'SYMBOL_VOLUME_LIMIT' - undeclared identifier test.mq5 4 46
'SymbolInfoDouble' - no one of the overloads can be applied to the function call test.mq5 4 20
Due to changes in MQL5, now the maximal overall volume allowed for one symbol can be obtained as following:
Do not use the old variant! It was like this:
The article has been corrected and the new Check_Order_And_Volume_Limits.mq5 expert code has been attached to it.Dear Admin
I try to use this function but it will return 0 in all cases.
My MT5 build is 2280
double orders_volume_on_symbol=PendingsVolume(symbol);
gives error, no such function
And after I modify function to not include pending orders, it gives 0
double NewOrderAllowedVolume(string symbol) { double allowed_volume=0; //--- get the limitation on the maximum volume of an order double symbol_max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX); //--- get the limitation of volume by a symbol double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT); //--- get the volume of open position by a symbol double opened_volume=PositionVolume(symbol); if(opened_volume>=0) { //--- if we already used available volume if(max_volume-opened_volume<=0) return(0); //--- volume of the open position doen't exceed max_volume //double orders_volume_on_symbol=PendingsVolume(symbol); //allowed_volume=max_volume-opened_volume-orders_volume_on_symbol; allowed_volume=max_volume-opened_volume; if(allowed_volume>symbol_max_volume) allowed_volume=symbol_max_volume; } return(allowed_volume); }
It is because max_volume is 0 and opened_volume is 0;
Why max volume is 0 if there is no opened positions?
Build 2715

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Limitations and Verifications in Expert Advisors is published:
Is it allowed to trade this symbol on Monday? Is there enough money to open position? How big is the loss if Stop Loss triggers? How to limit the number of pending orders? Was the trade operation executed at the current bar or at the previous one? If a trade robot cannot perform this kind of verifications, then any trade strategy can turn into a losing one. This article shows the examples of verifications that are useful in any Expert Advisor.
Author: MetaQuotes