How to increment Lotsize by 0.1?

 

Hi All

I want to increment my lot size by 0.1 but the first lot size has to be my default lot size calculation and then the 2nd lot just increment by 0.1 so on and so forth. 

I've tried to back test but the increment is incorrect, if there's any better way to do this your help will be appreciated.

double LotSize()
 {
  double Lots=0;
  double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
  double TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
  
  Lots=AccountBalance()*Risk*LotStep*TickValue/100;
  Lots+=0.1;
  
  if(Lots<MarketInfo(Symbol(),MODE_MINLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MINLOT);
  }
  
  else if(Lots>MarketInfo(Symbol(),MODE_MAXLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MAXLOT);
  }
  
  return(Lots);
 }
 

Hi

This is only calculation for the second lot, since you add 0.1 once. When you want to calculate lot sizes based on previous positions’ lot you need to do this in “loop” or recurrency. 

Here you can add a function which calculate lot but add a “counter” of existed trades as a parameter (it will work if account balance is the same during adding new trades): 

double LotSize(int counter)
 {
  double Lots=0;
  double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
  double TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
  
  Lots=AccountBalance()*Risk*LotStep*TickValue/100;
  if(counter>0) Lots+=counter*0.1;

  if(Lots<MarketInfo(Symbol(),MODE_MINLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MINLOT);
  }
  
  else if(Lots>MarketInfo(Symbol(),MODE_MAXLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MAXLOT);
  }
  
  return(Lots);
 }

So when you calculate the lot for the 2nd position, you just use LotSize(1) since you have already 1st position, etc...

Best Regards

 
  Lots=AccountBalance()*Risk*LotStep*TickValue/100;

Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin or leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% account total.

  1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support. Then you compute your lot size.

  2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)

  3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
              MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
              Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
              Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

  4. You must normalize lots properly and check against min and max.

  5. You must also check Free Margin to avoid stop out

  6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

 
Marzena Maria Szmit #:

Hi

This is only calculation for the second lot, since you add 0.1 once. When you want to calculate lot sizes based on previous positions’ lot you need to do this in “loop” or recurrency. 

Here you can add a function which calculate lot but add a “counter” of existed trades as a parameter (it will work if account balance is the same during adding new trades): 

So when you calculate the lot for the 2nd position, you just use LotSize(1) since you have already 1st position, etc...

Best Regards

Thanks for your response Marzena. When you mention I need to do this in a loop do you mean it should be like this?

double LotSize24(int counter)
 {
  double Lots=0;
 
  double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);
  double TickValue=MarketInfo(Symbol(),MODE_TICKVALUE);
  
  Lots=AccountBalance()*Risk*LotStep*TickValue/100;
      
  for(int o=OrdersTotal()-1;o>=0;o--)
  {
   if(OrderSelect(o,SELECT_BY_POS,MODE_HISTORY))
   if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
   {
    if(counter>0) Lots+=counter*0.1;
   }
  }
  
  if(Lots<MarketInfo(Symbol(),MODE_MINLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MINLOT);
  }
  
  else if(Lots>MarketInfo(Symbol(),MODE_MAXLOT))
  {
   Lots=MarketInfo(Symbol(),MODE_MAXLOT);
  }
  
  return(Lots);
 } 
Reason: