Martingale Lot Increase On Next Signal - page 2

 

simply..

you need to find last opened order first and find its lot amount too

after that you need to incerase last opened orders lots amount (with plus or multipy factor)

it will be next lot for your next order

 

Hi.. thanks a lot for your reply.. that is what am trying to do.... i did it with mql4.. finding it hard with mql5

https://www.mql5.com/en/forum/15083/page2

Obtain profit from last closed deal (closed)
Obtain profit from last closed deal (closed)
  • 2020.05.16
  • www.mql5.com
Good morning, I am building a function to know if the last closed deal by an expert advisor was profitable...
 
Abubakar Saidu:

Hi.. thanks a lot for your reply.. that is what am trying to do.... i did it with mql4.. finding it hard with mql5

https://www.mql5.com/en/forum/15083/page2

 dont overcomplicate things.


I literally gave you a function that needed one line changed.... and youve already got the code for that change. :it literally just returns the next lotsize in the sequence

You dont need to know anything other than the amount of currently opened trades in one direction. finding that number also gives you the mechanism to calculate the next lotsize in the sequence.

By the time you know the most recently opened trade, since you have to iterate the whole order stack to do this (and additionally keeping track of which index it is, or examining (and recording) the timestamp and lotsize), then reslecting it to get its lotsize, youve already done enough to just calculate the next lotsize, before asking for the most recent trade lotsize?

Theres no need to be both slower and more complex.


This is the exact method I used to calculate lotsize 12 years ago when playing with a martingale/grid hybrid (martingale in a range, and on breakout of that range hedge off the group, and start martingailing the next range) just for funsies.

 
el_looto:

dont overcomplicate things.


I literally gave you a function that needed one line changed.... and youve already got the code for that change. :it literally just returns the next lotsize in the sequence

You dont need to know anything other than the amount of currently opened trades in one direction. finding that number also gives you the mechanism to calculate the next lotsize in the sequence.

By the time you know the most recently opened trade, since you have to iterate the whole order stack to do this (and additionally keeping track of which index it is, or examining (and recording) the timestamp and lotsize), then reslecting it to get its lotsize, youve already done enough to just calculate the next lotsize, before asking for the most recent trade lotsize?

Theres no need to be both slower and more complex.


This is the exact method I used to calculate lotsize 12 years ago when playing with a martingale/grid hybrid (martingale in a range, and on breakout of that range hedge off the group, and start martingailing the next range) just for funsies.

Okay ill try it..

I will be greatful If you could paste the code

Thanks

 
Abubakar Saidu:

Okay ill try it..

I will be greatful If you could paste the code

Thanks

for what? the function that returns the lotsize? i already did that.

for the grid/martingale hybrid? No.

 
el_looto:

for what? the function that returns the lotsize? i already did that.

for the grid/martingale hybrid? No.

Yes please send me the function that return lot size..

Then ill continue

 
Abubakar Saidu:

Yes please send me the function that return lot size..

Then ill continue

I already gave it to you its on page one. I already said this.

Its even commented, and only needs one line changed to suit your exact circumstances. I already said this too.

I will not do more for you, your laziness is just galling at this point.

 
el_looto:

I already gave it to you its on page one. I already said this.

Its even commented, and only needs one line changed to suit your exact circumstances. I already said this too.

I will not do more for you, your laziness is just galling at this point.

Haha.. thanks.. will look at it.. 

Thanks a lot.. el_looto

 

here is the final code maybe?

it worked perfect!!

The mart code increase trades on new buys and sells..

sells mart not controlling sells only.. instead it increase lot on new buy signal.. same as buy

MT5

input string MartinGale = "===< MartinGale Settings >===";
input double          StartLot=0.5;
input double          LotIncrease      =2.0;    // (LotIncrease) Ratio for increasing the next lot

double mart()
  {
   ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE);    // type of the position
   double lots=0;
if(type==ORDER_TYPE_BUY)
 {
   lots = NormalizeDouble(StartLot * MathPow(LotIncrease, CountBuy()), LotDigits);
 }
if(type==ORDER_TYPE_SELL)
 {
   lots = NormalizeDouble(StartLot * MathPow(LotIncrease, CountSell()), LotDigits);
 }
  return lots;
  }
int CountBuy() 
{
   int total = PositionsTotal();
   for (int i = total - 1; i >= 0; i--) 
   {
      if(OrderGetInteger(ORDER_MAGIC)==MagicNumber
         &&OrderGetString(ORDER_SYMBOL)==Symbol()
         &&OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY
        )
         {
            total++;
         }
   }
   return (total);
}
int CountSell() {
   int total = PositionsTotal();
   for (int i = total - 1; i >= 0; i--) 
   {
      if(OrderGetInteger(ORDER_MAGIC)==MagicNumber
         &&OrderGetString(ORDER_SYMBOL)==Symbol()
         &&OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL
        )
         {
            total++;
         }
   }
   return (total);
}


MT4

input string MartinGale = "===< MartinGale Settings >===";
input double          StartLot=0.5;
input double          LotIncrease      =2.0;    // (LotIncrease) Ratio for increasing the next lot
double mart()
  {
   double lots=0;
   int NumOfTrades = 0,total;
bool flag;
bool TradeNow = FALSE, LongTrade = FALSE, ShortTrade = FALSE;
double LastBuyPrice, LastSellPrice;

      LastBuyPrice = FindLastBuyPrice();
      LastSellPrice = FindLastSellPrice();
if(OrderType()==OP_BUY)
 {
      total = CountBuy();
      NumOfTrades = total;
   lots = NormalizeDouble(StartLot* MathPow(LotIncrease, CountBuy()), LotDigits);
 }
if(OrderType()==OP_SELL)
 {
      total = CountSell();
      NumOfTrades = total;
   lots = NormalizeDouble(StartLot* MathPow(LotIncrease, CountSell()), LotDigits);
 }
  return lots;
  }
int CountBuy() {
   int count = 0;
   for (int i= OrdersTotal() - 1; i>= 0; i--) {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != OrderID) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == OrderID)
         if (OrderType() == OP_BUY) count++;
   }
   return (count);
}
int CountSell() {
   int count = 0;
   for (int i= OrdersTotal() - 1; i>= 0; i--) {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != OrderID) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == OrderID)
         if (OrderType() == OP_SELL) count++;
   }
   return (count);
}
 

okay here is the final code

input string Money_Management = "===< If false, 'FixedLot' will be used >==="; enum mmt   {    AutoMM=0,    Martingale=1,    fixed=2,   }; input mmt MM_Type = Martingale; input string Auto_MM = "===< Auto_MM Settings >==="; input double RiskPercent = 5.0; input string MartinGale = "===< MartinGale Settings >==="; input double          StartLot=0.01; input double          LotIncrease      =2.0;    // (LotIncrease) Ratio for increasing the next lot

input double FixedLot = 0.01;
double lot(ENUM_ORDER_TYPE type)
{
   double lotSize1=0;
   double MaxLot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX);
   double MinLot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
   double tickvalue = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_VALUE);
   double ticksize = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);
//getting types
 if(type==ORDER_TYPE_BUY || type==ORDER_TYPE_BUY_STOP)
   {
//automm
 if(MM_Type==AutoMM)
   {
   lotSize1= RiskPercent * 1.0 / 1000 * AccountInfoDouble(ACCOUNT_BALANCE) / (100* Point() / ticksize * tickvalue);
   if(lotSize1 > MaxLot) lotSize1 = MaxLot;
   if(lotSize1 < MinLot) lotSize1 = MinLot;
   }
//martingale
 else if(MM_Type==Martingale)lotSize1=NormalizeDouble(StartLot * MathPow(LotIncrease, nbuy()), LotDigits);
//fixed
 else if(MM_Type==fixed)lotSize1=FixedLot;
}
//getting types
else if(type==ORDER_TYPE_SELL || type==ORDER_TYPE_SELL_STOP)
 {
//automm
  if(MM_Type==AutoMM)
  {
   lotSize1= RiskPercent * 1.0 / 1000 * AccountInfoDouble(ACCOUNT_BALANCE) / (100* Point() / ticksize * tickvalue);
   if(lotSize1 > MaxLot) lotSize1 = MaxLot;
   if(lotSize1 < MinLot) lotSize1 = MinLot;
  }
//martingale
 else if(MM_Type==Martingale)lotSize1=NormalizeDouble(StartLot * MathPow(LotIncrease, nsell()), LotDigits);
//fixed
 else if(MM_Type==fixed)lotSize1=FixedLot;
 }
return lotSize1;
}

int nbuy()
  {
   ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);    // type of the position
   ulong order_ticket; 
   int buy=0;
   int total = PositionsTotal();
   for (int i = total-1; i >= 0; i--)
      {
      if((order_ticket=PositionGetTicket(i))>0) 
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
         buy++;
     }
   return buy;
  }
int nsell()
  {
   ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);    // type of the position
   ulong order_ticket; 
   int sel=0;
   int total = PositionsTotal();
   for(int x = total-1; x >= 0; x--)
     {
      if((order_ticket=PositionGetTicket(x))>0) 
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
         sel++;

     }
   return sel;
  }

did not code mart for stop orders

Thanks to you all for your feedbacks