//////////////////////////////////////////////////////////////////////////////////////////////////////////////// double GetLot_f() { double Free =AccountFreeMargin(); double One_Lot =MarketInfo(Symbol(),MODE_MARGINREQUIRED); double Step =MarketInfo(Symbol(),MODE_LOTSTEP); double Loto =MathFloor(Free*percent_of_deposit/100/One_Lot/Step)*Step; double Min_Lot =MarketInfo(Symbol(),MODE_MINLOT); double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT); if(Loto<Min_Lot) Loto=Min_Lot; if(Loto>Max_Lot) Loto=Max_Lot; return(NormalizeDouble(Loto,nor_lot)); }
-
Play videoPlease edit your post.
For large amounts of code, attach it.
Symbol_RC = Symbol(); _bid = MarketInfo(Symbol_RC,MODE_BID); _ask = MarketInfo(Symbol_RC,MODE_ASK);
Why use those function calls when working with current symbol. Just use the predefined Bid/Ask- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
- Do NOT use TickValue by itself - DeltaPerlot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
return(NormalizeDouble(lotsizecalc,1));
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
eevviill:
Thanks @eevvill: but i want to calculate from stoploss
WHRoeder:
- Why use those function calls when working with current symbol. Just use the predefined Bid/Ask
- You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
- Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
- Do NOT use TickValue by itself - DeltaPerlot
- You must normalize lots properly and check against min and max.
- You must also check FreeMargin to avoid stop out
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
Thanks WHRoeder: this stuff helped me alot let me try if can solve the issue to following these.... well really thanks for this :)
shahzaibidrees:
Thanks @eevvill: but i want to calculate from stoploss
https://www.mql5.com/ru/code/viewcode/14296/79100/lot_risk_sl__2.mq4
Thanks @eevvill: but i want to calculate from stoploss
- Use the link button
- Violates Do NOT use TickValue by itself - DeltaPerlot
You are the worstest teacher(explanation) that I saw ever. So unfortenetly I can't use your advices.
eevviill:
https://www.mql5.com/ru/code/viewcode/14296/79100/lot_risk_sl__2.mq4
Thanks @eevvill for the code :)
https://www.mql5.com/ru/code/viewcode/14296/79100/lot_risk_sl__2.mq4
eevviill: You are the worstest teacher(explanation) that I saw ever. So unfortenetly I can't use your advices.
| You won't read, study, learn, nor ask questions, so no one can teach you. |
shahzaibidrees:
Thanks @eevvill for the code :)
My pleasure.
Thanks @eevvill for the code :)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i am trying to make an EA for auto risk calculation but still not successful.
i am trying to calculate risk from Stoploss value in pip.
Example my stoploss is 10pip & i want to take the risk of 5% of my total Account balance. it should calculate from these two parameters...
Here is my code i tried but not worked for me.
//RiskCalculate
double riskcalculation(int Val_SL01)
{
AccRiskAmount = MathAbs(MathRound((MathMin(AccountEquity(),AccountBalance())/100)*RiskPercentage));
Symbol_RC = Symbol();
BaseCurr = StringSubstr(Symbol_RC,0,3);
QuoteCurr = StringSubstr(Symbol_RC,3,3);
AcctCurr = AccountCurrency();
_bid = MarketInfo(Symbol_RC,MODE_BID);
_ask = MarketInfo(Symbol_RC,MODE_ASK);
minlot = MarketInfo(Symbol_RC,MODE_MINLOT);
USDExchange = MarketInfo("EURUSD",MODE_BID);
lotSize = MarketInfo(Symbol_RC,MODE_LOTSIZE);
double ValPerPip;
//Calc By Pair Curruncy value per pip
if(Symbol()=="GDAXIm.lmx" && Symbol()=="XAUUSD.lmx"){ValPerPip=10;}
else{
if(QuoteCurr==AcctCurr){ ValPerPip = lotSize*tickSize;}
else if(BaseCurr==AcctCurr){ ValPerPip = (lotSize*tickSize)/_bid;}
else{ValPerPip = (lotSize*tickSize*USDExchange)/_bid;}
}
double lotsizecalc = NormalizeDouble(AccRiskAmount/(ValPerPip*Val_SL01),1);
if(lotsizecalc<minlot){lotsizecalc=minlot;}
return(NormalizeDouble(lotsizecalc,1));
}
it would be really grateful if anyone have the code for the EA & help me out for the correct formula.Thanks