# Money Management

4506

I have been looking around for some straight forward method to calculate the lot size based on a percentage of Equity or Free margin.

I found som examples but I did not really like them or understand if they really where "universal" and they had other "bells and whistles" I did not like.

What variables do I need to calculate the lotsize. It should work for all pairs and on any base currency and what is the formula?

I dont need the code, just the formula and the variables.

1331

ingvar_e:

I have been looking around for some straight forward method to calculate the lot size based on a percentage of Equity or Free margin.

I found som examples but I did not really like them or understand if they really where "universal" and they had other "bells and whistles" I did not like.

What variables do I need to calculate the lotsize. It should work for all pairs and on any base currency and what is the formula?

I dont need the code, just the formula and the variables.

double Risk = PercentToRisk / 100;
if (AutoMoneyManagement)
Lots = NormalizeDouble(AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);
if (Lots >= MaxLots)
Lots = (MaxLots);
if (Lots <= MinLots)
Lots = (MinLots);
5000

ingvar_e:

I have been looking around for some straight forward method to calculate the lot size based on a percentage of Equity or Free margin.

I found som examples but I did not really like them or understand if they really where "universal" and they had other "bells and whistles" I did not like.

What variables do I need to calculate the lotsize. It should work for all pairs and on any base currency and what is the formula?

I dont need the code, just the formula and the variables.

A idea...

```// nLote = volume at the start of execution of the EA
// loteFinal = volume to run current order
// multBalnc = factor multiplying the initial balance to apply increased lot

if(multBalnc>0)
{
mrgLibre= margenLibreCuenta();
loteFinal= (mrgLibre > balanceInical*multBalnc)?
(MathSqrt(mrgLibre/1000))*nLote:  //nLote= 0.01 1000; nLote= 0.1 10000
nLote;
}
else loteFinal= nLote;```
Moderator
10104

ingvar_e:

I have been looking around for some straight forward method to calculate the lot size based on a percentage of Equity or Free margin.

I found som examples but I did not really like them or understand if they really where "universal" and they had other "bells and whistles" I did not like.

What variables do I need to calculate the lotsize. It should work for all pairs and on any base currency and what is the formula?

I dont need the code, just the formula and the variables.

Hello ingvar_e, I don't think there is a "universal" method for calculating lot sizes. It's exactly the opposite... there are several different methods to calculate it, and you have to select a priori which one you want to use inside your expert advisors.

For a not comprehensive list os position sizing methods, please take a look at this external link.

4506

Makeprofitsuper:
double Risk = PercentToRisk / 100;
if (AutoMoneyManagement)
Lots = NormalizeDouble(AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2);
if (Lots >= MaxLots)
Lots = (MaxLots);
if (Lots <= MinLots)
Lots = (MinLots);

Makeprofitsuper

That looks like MQL4  not MQL5

4506

josemiguel1812:

A idea...

j1812osemiguel

Not really what I was looking for

4506

Malacarne:

Hello ingvar_e, I don't think there is a "universal" method for calculating lot sizes. It's exactly the opposite... there are several different methods to calculate it, and you have to select a priori which one you want to use inside your expert advisors.

For a not comprehensive list os position sizing methods, please take a look at this external link.

Malacarne.

The page you refer to list various methods to calculate lot size.  I know what method I want to use. Based on pair to trade, base currency, type of account  (micro, mini, standard) and the stoploss I have calculated I want to risk

1 or 2 percent of my current free margin

4506

I have code that works for most pairs and also on XAGUSD (Silver)

These pairs does not work properly but that is pairs I have no plan to trade anyway. Might be other too

- MXNJPY

- USDHKD

- USDZAR

Code:

```double CCalcLotSize2::Calc()
{

if(maxRisk2<0)                 //Fixed lot size  -0.40 is lotsize 0.40  +2 is 2% risk
{
lots = NormalizeDouble(-maxRisk2,2);
return lots;
}

// Risk in percent

//Calculate Tick Value
if(SymbolInfoDouble(pair2,SYMBOL_TRADE_TICK_VALUE,tickvalue) == false)   // Give up
return 0;

MoneyToRisk = maxRisk2*FreeMargin/100;    //How much money to risk on this trade, MaxRisk2 is percentage, typically 1 or 2

MoneyRiskTrade = StopLoss2*tickvalue;     //How much one mini lot would cost if loss

lots = NormalizeDouble(lots,2);

// Print("LotSize  :" + DoubleToString(lots,2));

return lots;
}```
6451

ingvar_e:

I have code that works for most pairs and also on XAGUSD (Silver)

These pairs does not work properly but that is pairs I have no plan to trade anyway. Might be other too

- MXNJPY

- USDHKD

- USDZAR

Code:

I also want to contribute with my version for a percentage on Account Balance! - You can always just change AccountBalance(); for AccountFreeMargin();

As you can see, the "risk" is based on the Stop Loss!

```int AccountBalance();

int SL;

int TP;

double MinLots=MarketInfo(Symbol(), MODE_MINLOT);

double VeryMaxLots=MarketInfo(Symbol(), MODE_MAXLOT);

extern double MaxLots=100;

int start()

{

//+------------------------------------------------------------------+

//  Calculate Volume Size                                            |

//-------------------------------------------------------------------+

double LotCalc= NormalizeDouble(risk*1/SL*AccountBalance(),2);

if(LotCalc>=MaxLots)

{

Lots=MaxLots;

}

if(LotCalc>=VeryMaxLots)

{

Lots=VeryMaxLots;

}

if(MinLots<LotCalc && LotCalc<MaxLots)

{

Lots=LotCalc;

}

if(LotCalc<=MinLots)

{

Lots=MinLots;

} ```
Moderator
32022