Turning EA into a Martingale EA

 

Hi,

I have created this EA but unfortunately it can only place order once at a time.

How can I change it so that it can open multiple orders or turn it into a martingale EA?

Thanks.

int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if(TotalOpenOrders()==0) 
  {
     int result=0;
      if(iStochastic(NULL, PERIOD_CURRENT, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 1) > 20
      && iStochastic(NULL, PERIOD_CURRENT, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 2) < 20 //Stochastic Oscillator crosses above fixed value
      && iMACD(NULL, PERIOD_CURRENT, 12, 26, 2, PRICE_CLOSE, MODE_MAIN, 1) > 0 //MACD > fixed value
      && Close[1] > iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANA, 1) //Candlestick Close > Ichimoku Kinko Hyo
      && Close[1] > iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, 1) //Candlestick Close > Ichimoku Kinko Hyo
      )
        {
        result=OrderSend(Symbol(),OP_BUYLIMIT,Lots,(Low[1] - iATR(Symbol(),PERIOD_CURRENT,14,0)),Slippage,0,0,"Buy",MagicNumber,TimeCurrent()+10*60*60,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit= Low[1] - iATR(Symbol(),PERIOD_CURRENT,14,0)+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss= Low[1] - iATR(Symbol(),PERIOD_CURRENT,14,0)-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),TheStopLoss,TheTakeProfit,TimeCurrent()+10*60*60,Green);
        }
        return(0);
     }
      if(iStochastic(NULL, PERIOD_CURRENT, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 1) < 80
      && iStochastic(NULL, PERIOD_CURRENT, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 2) > 80 //Stochastic Oscillator crosses below fixed value
      && iMACD(NULL, PERIOD_CURRENT, 12, 26, 2, PRICE_CLOSE, MODE_MAIN, 1) < 0 //MACD < fixed value
      && Close[1] < iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANA, 1) //Candlestick Close < Ichimoku Kinko Hyo
      && Close[1] < iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, 1) //Candlestick Close < Ichimoku Kinko Hyo
      )
     {
        result=OrderSend(Symbol(),OP_SELLLIMIT,Lots,(High[1] + iATR(Symbol(),PERIOD_CURRENT,14,0)),Slippage,0,0,"Sell",MagicNumber,TimeCurrent()+10*60*60,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=High[1] + iATR(Symbol(),PERIOD_CURRENT,14,0)-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=High[1] + iATR(Symbol(),PERIOD_CURRENT,14,0)+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),TheStopLoss,TheTakeProfit,TimeCurrent()+10*60*60,Green);
        }
        return(0);
     }
  }
   return(0);
}

int TotalOpenOrders()
{
   int result = 0;
   for(int order = 0; order < OrdersTotal(); order++) 
   {
      OrderSelect(order,SELECT_BY_POS,MODE_TRADES);
      if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)
         {
            result++;
         }
   }
   return(result);
}
 
Hoang Tran:

Hi,

I have created this EA but unfortunately it can only place order once at a time.

How can I change it so that it can open multiple orders or turn it into a martingale EA?

Thanks.

that is not an EA it is a script that will process once and close....

you can use the Freelance section to get somebody to create an EA for you

https://www.mql5.com/en/job

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2021.02.02
  • www.mql5.com
The largest freelance service with MQL5 application developers
 

Hedging, grid trading, same as Martingale.
          Martingale, Hedging and Grid : MHG - General - MQL5 programming forum 2016.12.20

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

Reason: