Programming Problem (MM) !

 

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
:)
 
Could anyone reply please ???
 
Mohammad Soubra:
Could anyone reply please ???

Incomplete code.

 
What is remaining!!
 

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);
 }
 
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
 

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 !. 

 

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;}
 
Mohammad Soubra:

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);
 
All not solve the trick
But thanks for all tries
 
Mohammad Soubra:
All not solve the trick
But thanks for all tries

It works 100% look at this.


Reason: