When creating the topic"AccountInfo... Information relevance", I learnt that there are functions that use data "cached in the software environment" and there are functions that always have "direct access to actual data".
Which category of functions does the SeriesInfoInteger() function belong to ?
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
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 orderdouble symbol_max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
//--- get the limitation of volume by a symboldouble max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);
//--- get the volume of open position by a symboldouble opened_volume=PositionVolume(symbol);
if(opened_volume>=0)
{
//--- if we already used available volumeif(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?
Predefined Macro Substitutions - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Thank you.
'SYMBOL_VOLUME_LIMIT' - undeclared identifier.............
'SymbolInfoDouble' - none of the overloads can be applied to the function call.............
Is it just me?
'SYMBOL_VOLUME_LIMIT' - undeclared identifier.............
'SymbolInfoDouble' - none of the overloads can be applied to the function call.............
Is it just me?
Can you do that?
One more question about the SeriesInfoInteger() function.
When creating the topic"AccountInfo... Information relevance", I learnt that there are functions that use data "cached in the software environment" and there are functions that always have "direct access to actual data".
Which category of functions does the SeriesInfoInteger() function belong to ?
The following code is used in the CheckVolumeValue function:
int ratio=(int)MathRound(volume/volume_step);
if(MathAbs(ratio*volume_step-volume)>0.0000001)
{
description=StringFormat("Объем не является кратным минимальной градации SYMBOL_VOLUME_STEP=%.2f, ближайший корректный объем %.2f",
volume_step,ratio*volume_step);
return(false);
}
But it is more correct:
int ratio = (int)MathRound((volume-min_volume)/volume_step);
if (MathAbs(ratio*volume_step+min_volume-volume)>0.0000001)
{
description=StringFormat("Объем не является кратным минимальной градации SYMBOL_VOLUME_STEP=%.2f, ближайший корректный объем %.2f",
volume_step,ratio*volume_step+min_volume);
return(false);
}
Because the minimum step of volume change must be counted from the minimum value.
And perhaps the code snippet
//--- вычислим значение маржи
bool check=OrderCalcMargin(type,Symbol(),lots,last_tick.ask,margin);
should be replaced with:
//--- вычислим значение маржи
double price = (type == ORDER_TYPE_BUY || type == ORDER_TYPE_BUY_LIMIT || type == ORDER_TYPE_BUY_STOP || type == ORDER_TYPE_BUY_STOP_LIMIT) ? last_tick.ask : last_tick.bid;
bool check=OrderCalcMargin(type,Symbol(),lots,price,margin);
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
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