Download MetaTrader 5

Need moneymanagement LOT size formula based on SL and Account Risk!

To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
Proximus
760
Proximus 2013.12.21 20:25 

Hi, i please need a code/ formula which resizes the lot size based on Account Risk % calculated by including the STOPLOSS, and taking in consideration that my account is in EUR.

What i have is this:

extern double RISK=1;  //1% RISK
double LOT;

LOT = NormalizeDouble(AccountEquity()*RISK/10000,2);

But this one doesnt consider the stoploss

So i found this one on google search

lot=NormalizeDouble(AccountBalance( )*MaximumRisk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);

And this one

lot = Risk * AccountEquity() / MarketInfo(Symbol(), MODE_TICKVALUE) / Stop;

But none of this works, please help me fix them, or give me a better one, thanks!

whroeder1
14544
whroeder1 2013.12.21 20:45  
  1. Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  2. Do NOT use TickValue by itself - DeltaPerlot
  3. You must also check FreeMargin to avoid stop out
yousef hammad
280
yousef hammad 2013.12.21 22:01  
   double Spread=MarketInfo(Symbol(),MODE_SPREAD)/Q;
   double Risk=(RiskPercent*AccountEquity())/100;//this means if your balance 1000$ & RiskPercent=10% >> you going to risk 100$
   double lot=Risk/((StopLoss+Spread)*MarketInfo(Symbol(),MODE_TICKVALUE)*Q);//Make Sure to Define Your StopLoss & Q=10 in 5 digits or Q=1 in 4 Digits 
whroeder1
14544
whroeder1 2013.12.21 22:13  
yousefh:, read the comment in my DeltaPerlot. Do NOT use tick value by itself.
Proximus
760
Proximus 2013.12.23 03:19  
yousefh:

Sorry its not good

WHRoeder:
  1. Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  2. Do NOT use TickValue by itself - DeltaPerlot
  3. You must also check FreeMargin to avoid stop out

Ok i see your point, so here is my logic and calculation how i calculate the RISK %


Which in MQL4 code looks like this:

extern double MYSTOPLOSS = 50;  // CUSTOM SL SIZE IN PIPS AFTER THE STOPLEVEL
extern double RISK =2; // 2% ACCOUNT RISK

double LOT =(AccountEquity()*RISK)/(100*(MarketInfo(Symbol(),MODE_STOPLEVEL)+MYSTOPLOSS)* Point *100000 );


A simple 1 liner, nothing complicated, now please help me insert that DELTA stuff that you have been talking about, i know the formula is not complete so please help me.And please note that my account is in EURO so in most cases its the basic currency.

Proximus
760
Proximus 2013.12.23 15:06  
Help me please quick, I would like to finish this project before X-mas :)
whroeder1
14544
whroeder1 2013.12.23 15:34  
Proximus: Help me please quick, I would like to finish this project before X-mas :)
  1. Lack of Planning
  2. now please help me insert that DELTA stuff
    Did you bother to click on the links provided?
Proximus
760
Proximus 2013.12.23 16:02  
WHRoeder:

  1. now please help me insert that DELTA stuff
    Did you bother to click on the links provided?

Yes i did, but i dont understand how you fit that into my equation, you said you need this:

  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE) 
But i dont understand how this helps my equation, because dividing these two numbers will give a big number instead of the ticksize...
Ubzen
5394
Ubzen 2013.12.23 16:21  
Proximus:

Yes i did, but i dont understand how you fit that into my equation, you said you need this:

But i dont understand how this helps my equation, because dividing these two numbers will give a big number instead of the ticksize...

Try this link: https://www.mql5.com/en/forum/148224.

Perhaps looking at it from a different angle might help.

Proximus
760
Proximus 2013.12.23 18:23  
ubzen:

Try this link: https://www.mql5.com/en/forum/148224.

Perhaps looking at it from a different angle might help.


WTF guys, shouldnt that be TICKVALUE * TICKSIZE instead of TICKVALUE /TICKSIZE ? I think there is a big mistake there





Just made a quick indicator which shows separate values, i guess the TICKVALUE * TICKSIZE is the appropriate one...


And note the demo account is in EUR so that is the base currency, while i did the same test with a USD account and there the POINT was equivalent to TICKVALUE * TICKSIZE because it measures the quote currency value.

Konstantinos Maleas
159
Konstantinos Maleas 2013.12.23 18:27  

If i have understand the question right this will do the job for you.

for( i=0; i<=ot; i++ ) for( z=0; z<=10; z++ )
      {
         if( long_orders_array_ATF[i][z] > 0 )
         for (zz=0; zz<=10; zz++)
         { 
            OrderSelect(zz,SELECT_BY_POS,MODE_TRADES);
            if (OrderTicket()==long_orders_array_ATF[i][z]) zz=ot+2; 
            if (ot+2<=zz)  
            long_potencial_loss = (OrderLots() * (OrderOpenPrice() - OrderStopLoss()))*100000;
            long_sum_potencial_loss = long_sum_potencial_loss + long_potencial_loss;
         }
      }
...

lot_size = ((((free-long_sum_potencial_loss) * percent_depo)/100.0)/pips)/100000 ; }
1234
To add comments, please log in or register