Martingale problem

 

I want to  learn and add a  martingal with my code but it's not working well

The first TP should move(but not close trade at especific value as my code now),

The lot exponent should be fixed(eg:1.4)

Add more position every Pipstep

My code and the function I used

//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
    Comment("Balance: ",AccountBalance(),"\n\nAccount Equity: ",AccountEquity());
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
//--- calculate open orders by current symbol
   if(TrailingS==true){
   if(CalculateCurrentOrders1(Symbol())==0) {CheckForOpen1();
    TrP();}
    }
   if(TrailingS==false){
   if(CalculateCurrentOrders1(Symbol())==0) {CheckForOpen1();}
    }
    Martingal();
 
//---
  }

void CheckForOpen1()
  {
int limit=1;   
for(int i=1;i<=limit;i++){
bool BullishCandle= Close[1]-Open[1]>0;
bool BearishCandle= Open[1]-Close[1]>0;
double MA13a= iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,1);
double MA50a= iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);
double MA13c= iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,3);
double MA50c= iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,3);
double MA13d= iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,4);
double MA50d= iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,4);
double MA13e= iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,5);
double MA50e= iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,5);
double MA200a= iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,1);
double MA800a= iMA(NULL,0,800,0,MODE_EMA,PRICE_CLOSE,1);
double MA13b= iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,2);
double MA50b= iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,2);
double MA200b= iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,2);
double MA800b= iMA(NULL,0,800,0,MODE_EMA,PRICE_CLOSE,2);
double ASC2a=iCustom(NULL, 0,"Indic1", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,Trade_Signal_Type, CrossDown,i);
double ASC1a=iCustom(NULL, 0,"Indic1", RSI_Period,RSI_Price,Volatility_Band,RSI_Price_Line,RSI_Price_Type,Trade_Signal_Line,Trade_Signal_Type, CrossUp,i);
bool NoSELL= Low[1]<=MA800a || Low[2]<=MA800b;
bool NoBUY= High[1]>=MA800a || High[2]>=MA800b;
    int    res;
   double lots,Lots;
   double SL;
   double TP;
   double _sl,_tp;
   
   //TIME FILTER
   string TradeStartTime = "01:05";
   string TradeStopTime = "23:00";
   //END TIME FILTER
   

//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- SELL 
   if(TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime)
     && !NoSELL && (ASC2a>0 && ASC2a!=EMPTY_VALUE && BearishCandle && ((MA13a<MA50a && MA13b<MA50b && MA13c<MA50c && MA13d<MA50d && MA13e<MA50e) || (MA13a>MA50a && MA13b>MA50b && MA13c>MA50c && MA13d>MA50d && MA13e>MA50e))))   
    {
            _sl=stoploss;
            _tp=takeprofit;
      //END HAMMER
      
      double StopLoss=_sl*Point;
      double TakeProfit=_tp*Point;
        
   if (_sl == 0) {SL = 0;} else{SL = Bid + _sl*Point;}
   if (_sl == 0){ TP = 0;} else{TP = Bid - _tp*Point;}
      Lots=(((AccountBalance() * MaximumRisk / 100) / (StopLoss)));
      lots=Lots;
      res=OrderSend(Symbol(),OP_SELL,NormalizeLots(lots,Symbol()),Bid,3,SL,TP,EA_Comment,MAGICMA1,0,Red);
      return;
     }
      //--- BUY
   if(TimeCurrent()>StrToTime(TradeStartTime) && TimeCurrent()<StrToTime(TradeStopTime)
     && !NoBUY && (ASC1a>0 && ASC1a!=EMPTY_VALUE && BullishCandle && ((MA13a<MA50a && MA13b<MA50b && MA13c<MA50c && MA13d<MA50d && MA13e<MA50e) || (MA13a>MA50a && MA13b>MA50b && MA13c>MA50c && MA13d>MA50d && MA13e>MA50e))))
     {
            _sl=stoploss;
            _tp=takeprofit;
      
       StopLoss=_sl*Point;
       TakeProfit=_tp*Point;
   if (_sl == 0){ SL = 0;} else{SL = Ask - _sl*Point;}
   if (_sl == 0){ TP = 0;} else{TP = Ask + _tp*Point;}
      Lots=(((AccountBalance() * MaximumRisk / 100) / (StopLoss)));
      lots=Lots;
      res=OrderSend(Symbol(),OP_BUY,NormalizeLots(lots,Symbol()),Ask,3,SL,TP,EA_Comment,MAGICMA1,0,Blue);
      return;
     }}
//---
  }

void Martingal()
{
   double lots;
   if(OrderType() == OP_SELL){
            if (OrdersTotal() == 1 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.01))
            { 
               int s1 = OrderSend(_Symbol,OP_SELL,NormalizeLots(lots,Symbol())*3,Bid,0,0,0,0,0,0,clrIndigo);
            }
               
            if (OrdersTotal() == 2 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.02))
            { 
               int s2 = OrderSend(_Symbol,OP_SELL,NormalizeLots(lots,Symbol())*4,Bid,0,0,0,0,0,0,clrIndigo);
            }
                  
            if (OrdersTotal() == 3 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.03))
            { 
               int s3 = OrderSend(_Symbol,OP_SELL,NormalizeLots(lots,Symbol())*5,Bid,0,0,0,0,0,0,clrIndigo);
            }
                  
            if (OrdersTotal() == 0 && Bid - Low[0] > 800 *_Point)
            { 
               int s4 = OrderSend(_Symbol,OP_SELL,NormalizeLots(lots,Symbol())*20,Bid,0,0,0,0,0,0,clrIndigo);
            }     
            }
   if(OrderType() == OP_BUY){
            if (OrdersTotal() == 1 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.01))
            { 
               int b1 = OrderSend(_Symbol,OP_BUY,NormalizeLots(lots,Symbol())*3,Bid,0,0,0,0,0,0,clrIndigo);
            }
               
            if (OrdersTotal() == 2 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.02))
            { 
               int b2 = OrderSend(_Symbol,OP_BUY,NormalizeLots(lots,Symbol())*4,Bid,0,0,0,0,0,0,clrIndigo);
            }
                  
            if (OrdersTotal() == 3 && AccountEquity() < AccountBalance()-(AccountBalance() * 0.03))
            { 
               int b3 = OrderSend(_Symbol,OP_BUY,NormalizeLots(lots,Symbol())*5,Bid,0,0,0,0,0,0,clrIndigo);
            }
                  
            if (OrdersTotal() == 0 && Bid - Low[0] > 800 *_Point)
            { 
               int b4 = OrderSend(_Symbol,OP_BUY,NormalizeLots(lots,Symbol())*20,Bid,0,0,0,0,0,0,clrIndigo);
            }     
            }


   
   if(OrdersTotal() == 2 && AccountEquity() > AccountBalance() * 1.1)
   {
      CloseTrades();
   }
   
   if(OrdersTotal() == 3 && AccountEquity() > AccountBalance() * 1.3)
   {
      CloseTrades();
   }
   
   if(OrdersTotal() == 4 && AccountEquity() > AccountBalance() * 1.6)
   {
      CloseTrades();
   }
      
   if(OrdersTotal() == 5 && AccountEquity() > AccountBalance() * 1.8)
   {
      CloseTrades();
   }   
}  

void CloseTrades()
{
   for(int i = OrdersTotal()-1; i >= 0 ; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS)==True)
      {
         bool result = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,clrRed);
      }
   }
}
 
Tolotra Ny: I want to  learn and add a  martingal

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)
          THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube

 
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)
          THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube

I just want to learn to code it sir :-)

I willl check the link you sent

 
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)
          THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube

My problem is how to calculate the value of the TP when it moves(after taking a recovering lot)

 
Tolotra Ny:

I just want to learn to code it sir :-)

I willl check the link you sent

Don't waste your time with that ... it's not a strategy ... it's a casino

 
Tolotra Ny:

I want to  learn and add a  martingal with my code but it's not working well

The first TP should move(but not close trade at especific value as my code now),

The lot exponent should be fixed(eg:1.4)

Add more position every Pipstep

My code and the function I used

Have you heard about Threshold Martingale? I've got a code from one of the ebooks in a thread here... https://www.mql5.com/en/forum/212643. It works fine with me.

Another type of Martingale is called Tie-down Method. I don't know yet where to look for it. In case you find one please let me know.

Something Interesting to Read
Something Interesting to Read
  • 2020.04.09
  • www.mql5.com
This is the thread about books related for stocks, forex, financial market and economics...
 
Meztiza Ako:

Have you heard about Threshold Martingale? I've got a code from one of the ebooks in a thread here... https://www.mql5.com/en/forum/212643. It works fine with me.

Another type of Martingale is called Tie-down Method. I don't know yet where to look for it. In case you find one please let me know.

Thanks so much, it's fixed(I got the code from spiderEA)

karp wak:

Don't waste your time with that ... it's not a strategy ... it's a casino

Yes sir, I just want to learn all about mql4  code  :-)