# Programming Problem (MM) !

33188

Hello,

MT4, EAs

I am using the code below to make MM (or Auto Lot Size), it is working perfectly. but...

for example:

when the trading account balance is 10k and I defined the lot size to be 0.01 then it keeps opening the lot size of 0.01 till the balance is 15k then the Lot Size will be 0.02

!!

The lot 0.02 should be handled when the amount is 20k not 15k

what is the solution?

```   if (LotType == Auto)
{
LotSize = AccountBalance() / calculated_amount * calculated_lot;
LotSize = NormalizeDouble(LotSize,2);
}
else  LotSize = FixedLot;
//
if(LotSize<MinLot) Print("ForexFlakesBasic: Lot size "+DoubleToString(LotSize,Digits)+"  less than the minimum trading  "+DoubleToString(MinLot,Digits));
if(LotSize>MaxLot && MaxLot>0.0) Print("ForexFlakesBasic: Lot size  "+DoubleToString(LotSize,Digits)+"  beyond the maximum allowed for trade  "+DoubleToString(MaxLot));
```

Thanks for all
:)
33188

Moderator
6061

Incomplete code.

33188

What is remaining!!
Moderator
6061

What is

`FixedLot`

What is

` calculated_amount`

What is

`calculated_lot`

### What are those ?

```// External variables
input bool DynamicLotSize = true;
input double EquityPercent = 2;
input double FixedLotSize = 0.1;

// Start function
if(DynamicLotSize == true)
{
double RiskAmount = AccountEquity() * (EquityPercent / 100);
double TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
if(Digits == 3 || Digits == 5) TickValue *= 10;
double CalcLots = (RiskAmount / StopLoss) / TickValue;
double LotSize = CalcLots;
}
else LotSize = FixedLotSize;```
```if(LotSize < MarketInfo(Symbol(),MODE_MINLOT))
{
LotSize = MarketInfo(Symbol(),MODE_MINLOT);
}

else if(LotSize > MarketInfo(Symbol(),MODE_MAXLOT))
{
LotSize = MarketInfo(Symbol(),MODE_MAXLOT);
}```
33188

Marco vd Heijden:

What is

What is

What is

### What are those ?

```//EA Enumerations
enum ENUM_LOT_TYPE         { Auto, Fixed };

//---
extern ENUM_LOT_TYPE LotType           =  Auto;       //Lot Type
input double      calculated_amount    =  10000;      //Amount For AUTO Lot
input double      calculated_lot       =  0.01;       //Auto Lot Size Each Amount
input double      FixedLot             =  0.01;       //Fixed Lot Size```
1586

It is hard for me to track a code is not mine, but the below code I use sometimes could insight you

to something ...

```input double                  Lots = 0.01;
input bool                   UseMM = true;
input double             LotFactor = 0.0005;

void Call_Lots() {
if(UseMM)
Lot = NormalizeDouble(LotFactor * AccountBalance(),LotDigits);
else
Lot = Lots;
}```

You need to show "Lot" on chart (or print in journal) to check the right "LotFactor" to start trading.

This function gives you a sensitive "Lot" change according to balance increment !.

Moderator
6061

or you can simply use the classic approach

```//Gearbox//
Balance=AccountInfoDouble(ACCOUNT_BALANCE);

if(Balance>10000)
{Lots=10;Print(" Gear Two");}
if(Balance>100000)
{Lots=100;Print(" Gear Three");}
if(Balance>1000000)
{Lots=1000;Print(" Gear Four");}
if(Balance>10000000)
{Lots=10000;Print(" Gear Five");}

if(Balance<10000000)
{Lots=1000;Print(" Gear Four");}
if(Balance<1000000)
{Lots=100;Print(" Gear Three");}
if(Balance<100000)
{Lots=10;Print(" Gear Two");}
if(Balance<10000)
{Lots=1;Print(" Gear One");}
if(Balance>1000000000)
{Lots=0;}```
2092

Hello,

MT4, EAs

I am using the code below to make MM (or Auto Lot Size), it is working perfectly. but...

for example:

when the trading account balance is 10k and I defined the lot size to be 0.01 then it keeps opening the lot size of 0.01 till the balance is 15k then the Lot Size will be 0.02!!

The lot 0.02 should be handled when the amount is 20k not 15k

what is the solution?

Thanks for all
:)

Just remove :

`LotSize = NormalizeDouble(LotSize,2);`

It will work, You can simply see it by Creating an Object on the Chart like this:

```ObjectCreate("LotSize", OBJ_LABEL, 0, 0, 0);
ObjectSetText("LotSize", "  Using Lot = " + DoubleToString(LotSize,Digits), 7, "Arial", Silver);
ObjectSet("LotSize", OBJPROP_CORNER, 0);
ObjectSet("LotSize", OBJPROP_XDISTANCE, 0);
ObjectSet("LotSize", OBJPROP_YDISTANCE, 15);```
33188

All not solve the trick
But thanks for all tries
2092