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

 
maleas_k:

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


double free = AccountFreeMargin();

double potencial_loss,

double sum_potencial_loss = 0

double pips, lot_size;

double percent_depo = 5;

potencial_loss = (OrderLots() * (OrderOpenPrice() - OrderStopLoss()))*100000;
sum_potencial_loss = long_sum_potencial_loss + long_potencial_loss;

lot_size = ((((free-long_sum_potencial_loss) * percent_depo)/100.0)/pips)/100000 ;



Thanks but i already have the formula,i just need to fix the point value because i have EUR account not USD.The code is 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 );

And i need to replace the Point with TICKVALUE* TICKSIZE, so it would look 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)* MarketInfo(Symbol(), MODE_TICKVALUE)* 
MarketInfo(Symbol(), MODE_TICKSIZE)  *100000 );

If anyone can confirm this idea is correct then the problem is resolved i guess.So please help me quick, and Merry Christmas after!

 
RaptorUK:

I removed your code . . . .


Thanks for your help.
 
Proximus:

Thanks but i already have the formula,i just need to fix the point value because i have EUR account not USD.The code is this:

And i need to replace the Point with TICKVALUE* TICKSIZE, so it would look like this

If anyone can confirm this idea is correct then the problem is resolved i guess.So please help me quick, and Merry Christmas after!

I cannot confirm it but i suggest to debug it with the Alert(); like this ?

Alert("LOT : ",LOT);

or

Alert("AccountEquity : ",(AccountEquity()," RISK : " ,RISK," MODE_STOPLEVEL : ", MODE_STOPLEVEL," MYSTOPLOSS : ",MYSTOPLOSS," MODE_TICKVALUE : " ,MODE_TICKVALUE," MODE_TICKSIZE : ,MODE_TICKSIZE);

And you will confirm it by yourself.

 
maleas_k:

Thanks for your help.
Thank you for making the edit
 
maleas_k:

I cannot confirm it but i suggest to debug it with the Alert(); like this ?

or

And you will confirm it by yourself.


No, what i meant that is it correct to use the TICKVALUE* TICKSIZEor the TICKVALUE/ TICKSIZE as WHRoeder suggested, because the * seems more logical there.So which one is the correct one, given that my account is in EUR so we look at the base currency not the quote?

 

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

double LOT =(AccountEquity()*RISK)/(100*(MarketInfo(Symbol(),MODE_STOPLEVEL)+MYSTOPLOSS)* Point *100000 );
  1. For example EURUSD with USD account currency.
    If TickValue is $10 and Ticksize=0.0001. There for if the market moves 0.0020 the value is $10/0.0001 * 0.0020=$200 / per lot. $10 per pip * 20 pips / per lot.
    If TickValue is $1 and Ticksize=0.00001. There for if the market moves 0.0020 the value is $1/0.00001 * 0.0020=$200 / per lot still. No mistake here.
  2. It is your equation that is bogus 100 * stoploss, StopLevel, Point * 10000, etc. Reread my original equation and solve for lotsize
 

Ok, these should be the steps for the (max) VOLUME SIZE CALCULATION:

(please correct me if I'm wrong ^_^)

AccountMoneyRisk = AccountMoney * Risk%

AccountCounterQuote = Quote(AccountCurrency/CounterCurrency)

CounterCurrencyRisk = AccountMoneyRisk * AccountCounterQuote

PipValue = CounterCurrencyRisk / StopLoss

LotTickValue = LotSize * TickSize

Volume = PipValue * LotTickValue


Example:

AccountCurrency: EUR
CurrencyPair: GBPUSD
BaseCurrency: GBP
CounterCurrency: USD

AccountMoney: 5000 EUR
Risk: 1%

StopLoss: 200 pips (Counter Currency)
LotSize: 100000 (Counter Currency)
TickSize: 0.00001

AccountMoneyRisk = AccountMoney * Risk% = 5000 EUR * 1% = 50 EUR

AccountCounterQuote = Quote(AccountCurrency/CounterCurrency) = Quote(EUR/USD) = 1.5000

CounterCurrencyRisk = AccountMoneyRisk * AccountCounterQuote = 50 EUR * 1.5000 = 75 USD

PipValue = CounterCurrencyRisk / StopLoss = 75 / 200 = 0.375

LotTickValue = LotSize * TickSize = 100000 * 0.00001 = 1 USD

Volume = PipValue * LotTickValue = 0.375 * 1 USD = 0.375



 

That assumes the CounterCurrency is the same as the AccountCurrency, and doesn't include the spread, and erroneously assumes that a pip == a point on a 5 digit broker and that ticksize == point.

Not necessarily. Account Balance * percent = RISK = (OrderOpenPrice - OrderStopLoss)*DIR * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)

 

Ok this is the final version, please confirm if its correct, i dont understand why you insist on your DeltaPerlot stuff when it clearly doesnt work in my situation, because i have EUR account.

This is my lot sizing function:

extern int STOPSLIP=20;
extern double RISK=0.5;

double LOT()
{
double clot=(AccountEquity()*RISK)/(100*(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD)+STOPSLIP)* MarketInfo(Symbol(),MODE_TICKVALUE)*MarketInfo(Symbol(),MODE_TICKSIZE) *100000 );

if(clot<MarketInfo(Symbol(),MODE_MINLOT)) clot=MarketInfo(Symbol(),MODE_MINLOT);
if(clot>MarketInfo(Symbol(),MODE_MAXLOT)) clot=MarketInfo(Symbol(),MODE_MAXLOT); 
  return (clot);
} 
  • The STOPSLIP adds X amount of pips to the current stoplevel+SPREAD
  • I use TICKVALUE * TICKSIZE because i have EUR account not USD, so it makes sense the pipvalue is 0.000007 instead of 0.00001 at my 5 digit broker because its counted in the EUR exchange rate
So can please someone confirm if its correct, or if its not then please correct MY formula, dont give me links to other posts,because i dont understand them, just correct my LOT() function and i`ll be happy then, please help!
 
double clot=(AccountEquity()*RISK)/(100*(MarketInfo(Symbol(),MODE_STOPLEVEL)+MarketInfo(Symbol(),MODE_SPREAD)+STOPSLIP)
            * MarketInfo(Symbol(),MODE_TICKVALUE)*MarketInfo(Symbol(),MODE_TICKSIZE) *100000 );

This gives me a headache just trying to work out the brackets!

To be honest, I have absolutely no idea what it is that you are trying to achieve here.

I can't see how MODE_STOPLEVEL or SPREAD are relevant, surely you should be basing your calculations on the stop-loss distance from current price?

It should make no difference what the account currency is, calculation should be the same because TICKVALUE is in the account currency.

Please note, by putting your line of code on 2 lines, the post is not so wide and makes it easier to read without scrolling right and left :)