- Margin calculation
- How to calculate Marginrequired in mql5 ?
- How can I get the marginrequired in mt5
bool runonce=0;// Flag sinput double startlots=0.01;// Starting Lotsize //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ double getLots(double lt) { if(runonce==0) { result = startlots; runonce=1; return(result); } else if(runonce==1) { double marginrequired=MarketInfo(Symbol(),MODE_MARGINREQUIRED); double freemargin=AccountFreeMargin(); if(freemargin>(marginrequired*lt)) { return(lt); } double result=freemargin/marginrequired; result=MathFloor(result*10)/10; return(result); } } //+------------------------------------------------------------------+
I take it literally.
I take it literally.
Thank you at start,
I get a error: 'startlots' - declaration without type
Thank you at start,
I get a error: 'startlots' - declaration without type
but when put double I get a error:
'result' - undeclared identifier
but when put double I get a error:
'result' - undeclared identifier
bool runonce=0;// Flag sinput double startlots=0.01;// Starting Lotsize //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ double getLots(double lt) { if(runonce==0) { double result = startlots; runonce=1; return(result); } else if(runonce==1) { double marginrequired=MarketInfo(Symbol(),MODE_MARGINREQUIRED); double freemargin=AccountFreeMargin(); if(freemargin>(marginrequired*lt)) { return(lt); } double result=freemargin/marginrequired; result=MathFloor(result*10)/10; return(result); } } //+------------------------------------------------------------------+
If you always want to use same lot size then do the following ...
input StartLots = 0.01;
then,
double getLots(double lt) ( double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED); double freemargin = AccountFreeMargin(); if(freemargin > (marginrequired * lt)) { return(StartLots); } double result = freemargin / marginrequired; result = MathFloor(result * 10) / 10; return(StartLots); }
In this code, you always enforce the getLots( ) function to return same StartLots value !!!.
I believe it will work !.
If you always want to use same lot size then do the following ...
then,
In this code, you always enforce the getLots( ) function to return same StartLots value !!!.
I believe it will work !.
Yes it work fine!
Great thank you guys!
Good Luck Guys!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use