Martingale Lot Increase On Next Signal

To add comments, please log in or register
Abubakar Saidu
3644
Abubakar Saidu  

Hello.. i cant figure out whats wrong with my code..

the lot decreases on next signal instead to increase

input string MartinGale = "===< MartinGale Settings >===";
input double          Risk=1.0;   
input double          Multi=0.5; 
double          MinLot,MaxLot,Contract,lot;
int             DealNumber;
long            Leverage;
int OnInit()
  {
      Leverage=AccountInfo.Leverage();
      MinLot=SymbolInfo.LotsMin();
      MaxLot=SymbolInfo.LotsMax();
      Contract=SymbolInfo.ContractSize();
      DealNumber=0;
   return(0);
  }
void OnTick()
  {
if(buysignal())
{
DealNumber++;
Lot=AccountInfoDouble(ACCOUNT_FREEMARGIN)*Risk/100*Leverage/ContractSize;
if(DealNumber>1)Lot=Lot*Multi*(DealNumber-1);Lot=NormalizeDouble(Lot,2);
if(Lot<MinLot)Lot=MinLot;if(Lot>MaxLot)Lot=MaxLot;
 
      MqlTick last_tick;
      double price = last_tick.ask;   

ticket = sendbuy(ORDER_TYPE_BUY, price,stoplossB(),Btp1(), Lot, "");
DealNumber--;

}
  }
   


   }

if i change this it will increase lot on every new signal.. but will continue to increase if Total Orders is = 0

DealNumber++;

with this.. it will restart if Total orders is =0

DealNumber--;

Ill really appreciate mod to my code

Nikolaos Pantzos
37084
Nikolaos Pantzos  
Abubakar Saidu:

Hello.. i cant figure out whats wrong with my code..

the lot decreases on next signal instead to increase

if i change this it will increase lot on every new signal.. but will continue to increase if Total Orders is = 0

with this.. it will restart if Total orders is =0

Ill really appreciate mod to my code

Hello,

try something this....

input string MartinGale = "===< MartinGale Settings >===";
input double          Risk=1.0;
input double          Multi=0.5;
double          MinLot,MaxLot,Contract,lot;
int             DealNumber;
long            Leverage;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   Leverage=AccountInfo.Leverage();
   MinLot=SymbolInfo.LotsMin();
   MaxLot=SymbolInfo.LotsMax();
   Contract=SymbolInfo.ContractSize();
   DealNumber=0;
   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(buysignal())
     {
      if(OrdersTotal()>0)
         DealNumber++;
      else
         DealNumber=0;
         
      int ticket=-1;
      
      Lot=AccountInfoDouble(ACCOUNT_FREEMARGIN)*Risk/100*Leverage/ContractSize;
      
      if(DealNumber>1)
         Lot=Lot*Multi*(DealNumber-1);
      Lot=NormalizeDouble(Lot,2);
      if(Lot<MinLot)
         Lot=MinLot;
      if(Lot>MaxLot)
         Lot=MaxLot;

      MqlTick last_tick;
      double price = last_tick.ask;

      ticket = sendbuy(ORDER_TYPE_BUY, price,stoplossB(),Btp1(), Lot, "");
     }
  }
Abubakar Saidu
3644
Abubakar Saidu  

Hi.. Thanks for your response

i tried it and it was not increasing the lot size on new signal..

instead it decrease


Abubakar Saidu
3644
Abubakar Saidu  

Tried this also lot not increasing on new signals

input string MartinGale = "===< MartinGale Settings >===";
input double          Risk=1.0;
input double          Multi=0.5;
double          MinLot,MaxLot,Contract,lot;
int             DealNumber;
long            Leverage;
input double          LotIncrease      =0.9; 
input double         StartLot=0.5;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   Leverage=AccountInfo.Leverage();
   MinLot=SymbolInfo.LotsMin();
   MaxLot=SymbolInfo.LotsMax();
   Contract=SymbolInfo.ContractSize();
   DealNumber=0;
   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(buysignal())
     {
      if(OrdersTotal()>0)
         DealNumber++;
      else
         DealNumber=0;
         
      int ticket=-1;
      
      Lot=AccountInfoDouble(ACCOUNT_FREEMARGIN)*Risk/100*Leverage/ContractSize;
      
      if(DealNumber>1)
         Lot=Lot*Multi*(DealNumber-1);
      Lot=NormalizeDouble(Lot,2);
      if(Lot<MinLot)
         Lot=MinLot;
      if(Lot>MaxLot)
         Lot=MaxLot;

      MqlTick last_tick;
      double price = last_tick.ask;

      ticket = sendbuy(ORDER_TYPE_BUY, price,stoplossB(),Btp1(), mart() , "");
     }
  }

double mart() 
  {
double ask=SymbolInfo.Ask(),bid=SymbolInfo.Bid();
double fb1,fb2;
   double lots=0;
   fb1= StartLot;
   fb2=fb1*LotIncrease;
if(nbuy()==0)
   fb1= StartLot;
else if(nbuy()>0 && ask<=fbo())
   fb1=fb1*LotIncrease;

   return(fb1);
  }
int nbuy()
  {
   int buy=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      int sb=OrderSelect(i);
      if(PositionGetInteger(POSITION_TYPE)==0 && PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
         buy++;
     }
   return buy;
  }

double fbo()
  {
   ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);    // type of the position
   double openprice = PositionGetDouble(POSITION_PRICE_OPEN);
   double z=0,zz=0;
   for(int i=OrdersTotal();i>=0;i--)
     {
      int a=OrderSelect(i);
      if(type==POSITION_TYPE_BUY && PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
        {
         z=openprice;
         if(z<zz || zz==0)zz=z;
        }
     }
   return zz;
  }


Oooohh..

el_looto
56
el_looto  

since youre counting buy orders, who not just calculate the lostize of the next buy order in that function?

each time through the loop your global buy_lotsize variable gets increased accordingly.


Although martingale is a fools errand..... Ive seen a proof that shows that probability of doubling your account is always exactly equal to the probability of a single winning outcome, and the probability of zeroing your account is equal to the probability of a single losing outcome....

Abubakar Saidu
3644
Abubakar Saidu  

i want to try something with martingale..

can you modify the wrong part of my code!!

Nikolaos Pantzos
37084
Nikolaos Pantzos  
Abubakar Saidu:

i want to try something with martingale..

can you modify the wrong part of my code!!

You code not working.

Please fix your code first.

William Roeder
21914
William Roeder  
Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
          Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11

Abubakar Saidu
3644
Abubakar Saidu  
Nikolaos Pantzos:

You code not working.

Please fix your code first.

hi.. thanks for your responses .. i have tried many possible ways .. still not working

can you highlight the wrong thing in my code

Abubakar Saidu
3644
Abubakar Saidu  
William Roeder:
Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
          Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11

Hi.. yes i know i just want to try something with it!!!
el_looto
56
el_looto  
Abubakar Saidu:
Hi.. yes i know i just want to try something with it!!!
//--// some pseudocode used in this example: do not copypasta: fix it.
double lotsize(void){
        if (OrdersTotal() == 0) return(StartLot); //does this even need a comment??
        // OrdersTotal must be >0 to get to this line
        double ret=StartLot; // ret is just short for "return value"
        for(int i=OrdersTotal();i!=0;i--){ // you may as well count down as up, often its easier and comparing to zero usually takes less clock cycles
                if(get the right order type) ret *= LotIncrease; //since you have a nice exponential lotsize formula, just use it
        }
// ret should now be the next lotsize in the sequence.
 return(ret); //ummm??
}
12
To add comments, please log in or register