Don't make it difficult for yourself. Just use OrderCalcMargin ...
Calculates the margin required for the specified order type, in the deposit currency |
- www.mql5.com
Don't make it difficult for yourself. Just use OrderCalcMargin ...
Calculates the margin required for the specified order type, in the deposit currency |
I already check that before an OrderSend, inside this funcion:
bool CheckMoneyForTrade(string symb,double lots,ENUM_ORDER_TYPE type) { //--- Getting the opening price MqlTick mqltick; SymbolInfoTick(symb,mqltick); double price=mqltick.ask; if(type==ORDER_TYPE_SELL) price=mqltick.bid; //--- values of the required and free margin double margin,free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE); //--- call of the checking function if(!OrderCalcMargin(type,symb,lots,price,margin)) { //--- something went wrong, report and return false Print("Error in ",__FUNCTION__," code=",GetLastError()); return(false); } //--- if there are insufficient funds to perform the operation if(margin>free_margin) { //--- report the error and return false Print("Not enough money for ",EnumToString(type)," ",lots," ",symb," Error code=",GetLastError()); return(false); } //--- checking successful return(true); }
My intent now is, when the result of this check is negative, I can retry with a new lower volume that fits the margin.
How can I go that?
Maybe if I make that "margin" a global double variable, and retry with
new volume = Free MArgin * Old Volume / margin?Yes, by simple maths and by also checking the amount of available free margin (and if you need, also used margin from other open positions) ...
Returns a value of double type of the corresponding account property
ACCOUNT_MARGIN
Account margin used in the deposit currency
double
ACCOUNT_MARGIN_FREE
Free margin of an account in the deposit currency
double
ACCOUNT_MARGIN_LEVEL
Account margin level in percents
double
ACCOUNT_MARGIN_SO_CALL
Margin call level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency
double
ACCOUNT_MARGIN_SO_SO
Margin stop out level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency
double
ACCOUNT_MARGIN_INITIAL
Initial margin. The amount reserved on an account to cover the margin of all pending orders
double
ACCOUNT_MARGIN_MAINTENANCE
Maintenance margin. The minimum equity reserved on an account to cover the minimum amount of all open positions
double
- 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
Hi all.
I am trying to workout how can I get this "3" that I see on the symbol specs on my broker.
But SymbolInfoDouble Symbol Magrin Initial returns 0.0
So I ran them all and displayed as comment to debug:
To my surprise... all came as 0.0
How can I get that 3?
Thank you
Nuno