Help me edit the EA.Thank you very much, I will be very grateful to you

 

Help me edit the EA. If Number of Trades = 1, profit = 20, If Number of Trades > 1, profit = 1.

//+------------------------------------------------------------------+

//|                                                  demo_hedging.mq4|

//|                                                    Copyright 2021|

//|                                                                  |

//+------------------------------------------------------------------+

#property copyright "Copyright 2021"

#property link      ""

#property version   "1.00"

#property strict



//--- Inputs

extern double Loss           = 3000;      //loss in currency

extern double Profit         = 10;        // profit in currency

extern double Lots           = 0.1;       // lot

extern double KLot           = 2;         // increase the lot

extern double MaxLot         = 10;        // maximum lot

extern int    StopLoss       = 2000;      // stoploss

extern int    TakeProfit     = 3000;      // Takeprofit

extern int    Delta          = 333;       // Delta

extern int    Shift          = 1;         // indicator bar

extern int    Slip           = 30;        // slippage

extern int    Magic          = 123;       // magic



extern int    MA1            = 10;        // MA1

extern ENUM_MA_METHOD Met1   = 1;         // method MA1

extern int    MA2            = 50;        // MA2

extern ENUM_MA_METHOD Met2   = 1;         // method MA2

extern int    MA3            = 100;       // MA3

extern ENUM_MA_METHOD Met3   = 1;         // method MA3



int num=0;

datetime t=0;

//+------------------------------------------------------------------+

//| Expert initialization function/ khoi tao ham                     |

//+------------------------------------------------------------------+

int OnInit()

  {

//---



//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---



  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void PutOrder(int type,double price)

  {

   int r=0;

   color clr=Green;

   double sl=0,tp=0;



   if(type==1 || type==3 || type==5)

     {

      clr=Red;

      if(StopLoss>0)

         sl=NormalizeDouble(price+StopLoss*_Point,_Digits);

      if(TakeProfit>0)

         tp=NormalizeDouble(price-TakeProfit*_Point,_Digits);

     }



   if(type==0 || type==2 || type==4)

     {

      clr=Blue;

      if(StopLoss>0)

         sl=NormalizeDouble(price-StopLoss*_Point,_Digits);

      if(TakeProfit>0)

         tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);

     }



   r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);

   return;

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int CountTrades()

  {

   int count=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()<2)

               count++;

           }

        }

     }

   return(count);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int LastOrderType()

  {

   int type=0;



   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()==0)

              {

               type=1; //buy

               break;

              }

            if(OrderType()==1)

              {

               type=2; //sell

               break;

              }

           }

        }

     }

   return(type);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CloseAll(int ot=-1)

  {

   bool cl;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()==0 && (ot==0 || ot==-1))

              {

               RefreshRates();

               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);

              }

            if(OrderType()==1 && (ot==1 || ot==-1))

              {

               RefreshRates();

               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);

              }

           }

        }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double AllProfit()

  {

   double profit=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()<2)

               profit+=OrderProfit()+OrderSwap()+OrderCommission();

           }

        }

     }

   return(profit);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double Lot()

  {

   double lot=Lots;

   if(CountTrades()>0)

      lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);

   if(lot>MaxLot)

      lot=Lots;

   return(lot);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int CountOrders(int type)

  {

   int count=0;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()==type)

               count++;

           }

        }

     }

   return(count);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void DelOrder()

  {

   bool del;

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)

           {

            if(OrderType()>1)

               del=OrderDelete(OrderTicket());

           }

        }

     }

   return;

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

   double ma1=iMA(NULL,0,MA1,0,Met1,0,Shift);

   double ma2=iMA(NULL,0,MA2,0,Met2,0,Shift);

   double ma3=iMA(NULL,0,MA3,0,Met3,0,Shift);



   if(AllProfit()>Profit || AllProfit()<-Loss)

     {

      CloseAll();

      DelOrder();

     }



   if(CountTrades()<1 && t!=Time[0])

     {

      if(ma1>ma2 && ma2>ma3)

        {

         PutOrder(0,Ask);

         PutOrder(5,Bid-Delta*_Point);

        }



      if(ma1<ma2 && ma2<ma3)

        {

         PutOrder(1,Bid);

         PutOrder(4,Bid+Delta*_Point);

        }

      t=Time[0];

     }



// открытие последующих ордеров

   if(num!=CountTrades())

     {

      if(LastOrderType()==1)

        {

         DelOrder();

         if(CountOrders(5)<1)

            PutOrder(5,Bid-Delta*_Point);

        }



      if(LastOrderType()==2)

        {

         DelOrder();

         if(CountOrders(4)<1)

            PutOrder(4,Bid+Delta*_Point);

        }

      num=CountTrades();

     }





   Comment("\n Profit: ",DoubleToString(AllProfit(),2),

           "\n Last Order Type: ",LastOrderType(),

           "\n Count Trades: ",CountTrades());

  }

//+------------------------------------------------------------------+



Files:
 
Hòa Nguyễn:


we might help you if you go and read the rules for posting in the forum, including using the code button when inserting code.

 
Revo Trades # :

Chúng tôi có thể giúp bạn nếu bạn truy cập và đọc các bài đăng quy tắc trong diễn đàn, bao gồm cả việc sử dụng mã hóa nút khi chèn mã .

I'm very sorry for not knowing the forum rules, I will read it and come back. Thank you so much
 
Hòa Nguyễn #:
I'm very sorry for not knowing the forum rules, I will read it and come back. Thank you so much

Try this, change this line

  if(AllProfit()>Profit || AllProfit()<-Loss)

to

double total_profit = AllProfit();
if((total_profit>=20 && CountTrades() == 1) || (total_profit>1 && CountTrades() > 1) || total_profit<-Loss)