Grid trading doesn't work to Multi symbol...

 

Sir ,

I want to practice this Example EA MT5.


1)

It is working  to grid Trading into One Symbol.

int Pip_Step(string symbol_2, int magic_2, double StopLoss_3, double TakeProfit_3)
  {
   double   Open_Price  =  0;
   bool     LastIsBuy   =  false;
   int      TotalBuy   =  0;
   int      TotalSell  =  0;

   double   Spread = (double)SymbolInfoInteger(symbol_2, SYMBOL_SPREAD);

   double Ask = SymbolInfoDouble(symbol_2, SYMBOL_ASK);
   double Bid = SymbolInfoDouble(symbol_2, SYMBOL_BID);

   double iclose = iClose(symbol_2, PERIOD_CURRENT, 1);


   for(int iCount = CalculateAllPositions(symbol_2) - 1; iCount >= 0; iCount--)
     {
      ulong Position_Ticket = PositionGetTicket(iCount);
      if(PositionSelectByTicket(Position_Ticket))
        {
         int Position_Type = (int)PositionGetInteger(POSITION_TYPE);
         string check_Symbol = PositionGetString(POSITION_SYMBOL);
         long magic = PositionGetInteger(POSITION_MAGIC);
         double open_price = PositionGetDouble(POSITION_PRICE_OPEN);

         if(Position_Type == POSITION_TYPE_BUY && check_Symbol == symbol_2 && magic == magic_2)
           {

            if(Open_Price == 0)
              {
               Open_Price = open_price;
              }
            if(Open_Price > open_price)
              {
               Open_Price = open_price;
              }

            LastIsBuy = true;
            TotalBuy++;

            if(TotalBuy == MaxTrade)
              {
               Print("Maximum Trade is reached");
               return(0);
              }

           }

         if(Position_Type == POSITION_TYPE_SELL && check_Symbol == symbol_2 && magic == magic_2)
           {

            if(Open_Price == 0)
              {
               Open_Price = open_price;
              }
            if(Open_Price < open_price)
              {
               Open_Price = open_price;
              }

            LastIsBuy = false; // Next Sell won't Trade
            TotalSell++;

            if(TotalSell == MaxTrade)
              {
               Print("Maximum Trade is reached");
               return(0);
              }

           }
        }
     }

   /* If the Price is downtrend to Buy Order, check the Bid */
   if(LastIsBuy)
     {

      if(Bid <= Open_Price - (Spread * point) - (PipStep * point))

        {


         if(MA[0] < Ask && iclose > MA[0])
           {
            Buy(symbol_2, magic_2, Ask, StopLoss_3, TakeProfit_3);
           }

         LastIsBuy = false;
         return(0);
        }
     }

   /* If the direction is Uptrend to Sell Order, check the value of Ask */
   else
      if(!LastIsBuy)
        {

         if(Ask >= Open_Price + (Spread * point) + (PipStep * point))

           {
            if(MA[0] > Bid && iclose < MA[0])
              {
               Sell(symbol_2, magic_2, Bid, StopLoss_3, TakeProfit_3);
              }

            return(0);
           }
        }
   return(0);
  }


2)

It has some working into grid trading to 4 multi symbol..but it doesn't work to trade in this Second symbol "EURUSD" ( Please see this 1st photo attached)

It has 2 Trade in "GBPUSD" symbol (Please see this 2nd photo attached) but I want only one Trade in GPBUSD.

It has some problem ...Please Test it & solve this code itself 👇

//+------------------------------------------------------------------+
//|                                           Example_MA_PipStep.mq5 |
//|                                            vik20011902@gmail.com |
//+------------------------------------------------------------------+
#property link      "vik20011902@gmail.com"
#property version   "1.00"


// Moving Average
int MA_Handle = 0;
double MA[];

// Point
double point = 0 ;

double StopLoss_point ;
double TakeProfit_point;

input bool First_Symbol = true;
input string Symbol_1 = "AUDUSD.s";

input bool Second_Symbol = true;
input string Symbol_2 = "EURUSD.s";

input bool Third_Symbol = true;
input string Symbol_3 = "USDCAD.s";

input bool Fourth_Symbol = true;
input string Symbol_4 = "GBPUSD.s";


input int MagicNumber = 12345;
input int MA_Period = 20;
input int MA_Shift = 1;

input int TakeProfit = 1000;
input int StopLoss = 1000;

input int MaxTrade = 3;
input int PipStep = 5;

input ENUM_TIMEFRAMES Time_Frame = PERIOD_M1;



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

// First Symbol

   if(First_Symbol == true)
     {
      MA_Handle = iMA(Symbol_1, PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE);

      if(MA_Handle == INVALID_HANDLE)
        {
         Print("Failed ", Symbol_1, " Loading this Indicator ");
         return (INIT_FAILED);
        }
     }
   else
     {
      Print(__FUNCTION__ " :- First_Symbol is Disabled");
     }


// Symbol 2

   if(Second_Symbol == true)
     {
      MA_Handle = iMA(Symbol_2, PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE);

      if(MA_Handle == INVALID_HANDLE)
        {
         Print("Failed ", Symbol_2, " Loading this Indicator ");
         return (INIT_FAILED);
        }
     }
   else
     {
      Print(__FUNCTION__ " :- Second_Symbol is Disabled");
     }


// Symbol 3

   if(Third_Symbol == true)
     {
      MA_Handle = iMA(Symbol_3, PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE);

      if(MA_Handle == INVALID_HANDLE)
        {
         Print("Failed ", Symbol_3, " Loading this Indicator ");
         return (INIT_FAILED);
        }
     }
   else
     {
      Print(__FUNCTION__ " :- Third_Symbol is Disabled");
     }


// Symbol 4

   if(Fourth_Symbol == true)
     {
      MA_Handle = iMA(Symbol_4, PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE);

      if(MA_Handle == INVALID_HANDLE)
        {
         Print("Failed ", Symbol_4, " Loading this Indicator ");
         return (INIT_FAILED);
        }
     }
   else
     {
      Print(__FUNCTION__ " :- Fourth_Symbol is Disabled");
     }



//Digits
   int digits = 1;
   if(Digits() == 3 || Digits() == 5)
     {
      digits = 10;
      point = Point() * digits;
     }
   else
      if(Digits() <= 2 || Digits() == 4)
        {
         digits = 10;
         point = Point() * 1;
        }


   StopLoss_point = StopLoss * point ;
   TakeProfit_point = TakeProfit * point ;

//---
   return(INIT_SUCCEEDED);
  }





// I removed this code because Iam Unabe to send this message forum if it says "Message may not exceed 64000 characters"
// Void Ondeinit is Removed //+------------------------------------------------------------------+ //| Expert tick function                                             | //+------------------------------------------------------------------+ void OnTick()   {    /*       Note :-       It is working 2 Symbol but it doesn't work 4 Symbol    */ // Moving Average Buffer    ArraySetAsSeries(MA, true);    int count = 3;    if(!CopyBuffer(MA_Handle, 0, 1, count, MA))      {       Print("Failed to create Indicator");      } // First Symbol    if(First_Symbol == true)      {       //Bars       if(Bars(Symbol_1, PERIOD_CURRENT) < 100)         {          Print("Bars less than 100");          return;         }       double Spread = (double)SymbolInfoInteger(Symbol_1, SYMBOL_SPREAD);       Comment("Spread = ", Spread);       double Ask = SymbolInfoDouble(Symbol_1, SYMBOL_ASK);       double Bid = SymbolInfoDouble(Symbol_1, SYMBOL_BID);       // Maximum Trade       int total = 0;       for(int i = CalculateAllPositions(Symbol_1) - 1; i >= 0; i--)         {          ulong Position_Ticket = PositionGetTicket(i);          if(!PositionSelectByTicket(Position_Ticket))            {             Print("Position Select failed");            }          string check_Symbol = PositionGetString(POSITION_SYMBOL);          if(check_Symbol == Symbol_1)            {             total++;            }          if(total > MaxTrade)            {             return;            }         }       // New Current Bar       if(New_Current_Bar(Symbol_1))         {          double iclose = iClose(Symbol_1, PERIOD_CURRENT, 1);          if(CalculateAllPositions(Symbol_1) == 0)            {             if(MA[0] < Ask && iclose > MA[0])               {                // Buy                Buy(Symbol_1, MagicNumber, Ask, StopLoss_point, TakeProfit_point);               }             else                if(MA[0] > Bid && iclose < MA[0])                  {                   // Sell                   Sell(Symbol_1, MagicNumber, Bid, StopLoss_point, TakeProfit_point);                  }            }          if(CalculateAllPositions(Symbol_1) >= 1)            {             Pip_Step(Symbol_1, MagicNumber, StopLoss_point, TakeProfit_point);            }         }      }           // Second Symbol    if(Second_Symbol == true)      {       //Bars       if(Bars(Symbol_2, PERIOD_CURRENT) < 100)         {          Print("Bars less than 100");          return;         }       double Spread = (double)SymbolInfoInteger(Symbol_2, SYMBOL_SPREAD);       Comment("Spread = ", Spread);       double Ask = SymbolInfoDouble(Symbol_2, SYMBOL_ASK);       double Bid = SymbolInfoDouble(Symbol_2, SYMBOL_BID);       // Maximum Trade       int total = 0;       for(int i = CalculateAllPositions(Symbol_2) - 1; i >= 0; i--)         {          ulong Position_Ticket = PositionGetTicket(i);          if(!PositionSelectByTicket(Position_Ticket))            {             Print("Position Select failed");            }          string check_Symbol = PositionGetString(POSITION_SYMBOL);          if(check_Symbol == Symbol_2)            {             total++;            }          if(total > MaxTrade)            {             return;            }         }       // New Current Bar       if(New_Current_Bar(Symbol_2))         {          double iclose = iClose(Symbol_2, PERIOD_CURRENT, 1);          if(CalculateAllPositions(Symbol_2) == 0)            {             if(MA[0] < Ask && iclose > MA[0])               {                // Buy                Buy(Symbol_2, MagicNumber, Ask, StopLoss_point, TakeProfit_point);               }             else                if(MA[0] > Bid && iclose < MA[0])                  {                   // Sell                   Sell(Symbol_2, MagicNumber, Bid, StopLoss_point, TakeProfit_point);                  }            }          if(CalculateAllPositions(Symbol_2) >= 1)            {             Pip_Step(Symbol_2, MagicNumber, StopLoss_point, TakeProfit_point);            }         }      }           // Third Symbol    if(Third_Symbol == true)      {       //Bars       if(Bars(Symbol_3, PERIOD_CURRENT) < 100)         {          Print("Bars less than 100");          return;         }       double Spread = (double)SymbolInfoInteger(Symbol_3, SYMBOL_SPREAD);       Comment("Spread = ", Spread);       double Ask = SymbolInfoDouble(Symbol_3, SYMBOL_ASK);       double Bid = SymbolInfoDouble(Symbol_3, SYMBOL_BID);       // Maximum Trade       int total = 0;       for(int i = CalculateAllPositions(Symbol_3) - 1; i >= 0; i--)         {          ulong Position_Ticket = PositionGetTicket(i);          if(!PositionSelectByTicket(Position_Ticket))            {             Print("Position Select failed");            }          string check_Symbol = PositionGetString(POSITION_SYMBOL);          if(check_Symbol == Symbol_3)            {             total++;            }          if(total > MaxTrade)            {             return;            }         }       // New Current Bar       if(New_Current_Bar(Symbol_3))         {          double iclose = iClose(Symbol_3, PERIOD_CURRENT, 1);          if(CalculateAllPositions(Symbol_3) == 0)            {             if(MA[0] < Ask && iclose > MA[0])               {                // Buy                Buy(Symbol_3, MagicNumber, Ask, StopLoss_point, TakeProfit_point);               }             else                if(MA[0] > Bid && iclose < MA[0])                  {                   // Sell                   Sell(Symbol_3, MagicNumber, Bid, StopLoss_point, TakeProfit_point);                  }            }          if(CalculateAllPositions(Symbol_3) >= 1)            {             Pip_Step(Symbol_3, MagicNumber, StopLoss_point, TakeProfit_point);            }         }      }     // Fourth Symbol    if(Fourth_Symbol == true)      {       //Bars       if(Bars(Symbol_4, PERIOD_CURRENT) < 100)         {          Print("Bars less than 100");          return;         }       double Spread = (double)SymbolInfoInteger(Symbol_4, SYMBOL_SPREAD);       Comment("Spread = ", Spread);       double Ask = SymbolInfoDouble(Symbol_4, SYMBOL_ASK);       double Bid = SymbolInfoDouble(Symbol_4, SYMBOL_BID);       // Maximum Trade       int total = 0;       for(int i = CalculateAllPositions(Symbol_4) - 1; i >= 0; i--)         {          ulong Position_Ticket = PositionGetTicket(i);          if(!PositionSelectByTicket(Position_Ticket))            {             Print("Position Select failed");            }          string check_Symbol = PositionGetString(POSITION_SYMBOL);          if(check_Symbol == Symbol_4)            {             total++;            }          if(total > MaxTrade)            {             return;            }         }       // New Current Bar       if(New_Current_Bar(Symbol_4))         {          double iclose = iClose(Symbol_4, PERIOD_CURRENT, 1);          if(CalculateAllPositions(Symbol_4) == 0)            {             if(MA[0] < Ask && iclose > MA[0])               {                // Buy                Buy(Symbol_4, MagicNumber, Ask, StopLoss_point, TakeProfit_point);               }             else                if(MA[0] > Bid && iclose < MA[0])                  {                   // Sell                   Sell(Symbol_4, MagicNumber, Bid, StopLoss_point, TakeProfit_point);                  }            }          if(CalculateAllPositions(Symbol_4) >= 1)            {             Pip_Step(Symbol_4, MagicNumber, StopLoss_point, TakeProfit_point);            }         }      }              return;   } //  New Current Bar bool New_Current_Bar(string symbol_1)   {    static datetime prevTime = 0;    datetime lastTime[1];    if(CopyTime(symbol_1, PERIOD_CURRENT, 0, 1, lastTime) == 1 && prevTime != lastTime[0])      {       prevTime = lastTime[0];       return true;      }    return false;   } //+------------------------------------------------------------------+ //|                                                                  | //+------------------------------------------------------------------+ int CalculateAllPositions(string symbol_name)   {    int total = 0;    for(int i = PositionsTotal() - 1; i >= 0; i--)      {       ulong Position_Ticket = PositionGetTicket(i);       if(PositionSelectByTicket(Position_Ticket))         {          ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);          string check_Symbol = PositionGetString(POSITION_SYMBOL);          if(check_Symbol == symbol_name)            {             total++;            }         }       //---      }    return(total);   } /* I removed this code because Iam Unabe to send this message forum MQL5 if it says "Message may not exceed 64000 characters" Buy & Sell Trade function */ int Pip_Step(string symbol_2, int magic_2, double StopLoss_3, double TakeProfit_3)   {    double   Open_Price  =  0;    bool     LastIsBuy   =  false;    int      TotalBuy   =  0;    int      TotalSell  =  0;    double   Spread = (double)SymbolInfoInteger(symbol_2, SYMBOL_SPREAD);    double Ask = SymbolInfoDouble(symbol_2, SYMBOL_ASK);    double Bid = SymbolInfoDouble(symbol_2, SYMBOL_BID);    double iclose = iClose(symbol_2, PERIOD_CURRENT, 1);    for(int iCount = CalculateAllPositions(symbol_2) - 1; iCount >= 0; iCount--)      {       ulong Position_Ticket = PositionGetTicket(iCount);       if(PositionSelectByTicket(Position_Ticket))         {          int Position_Type = (int)PositionGetInteger(POSITION_TYPE);          string check_Symbol = PositionGetString(POSITION_SYMBOL);          long magic = PositionGetInteger(POSITION_MAGIC);          double open_price = PositionGetDouble(POSITION_PRICE_OPEN);          if(Position_Type == POSITION_TYPE_BUY && check_Symbol == symbol_2 && magic == magic_2)            {             if(Open_Price == 0)               {                Open_Price = open_price;               }             if(Open_Price > open_price)               {                Open_Price = open_price;               }             LastIsBuy = true;             TotalBuy++;             if(TotalBuy == MaxTrade)               {                Print("Maximum Trade is reached");                return(0);               }            }          if(Position_Type == POSITION_TYPE_SELL && check_Symbol == symbol_2 && magic == magic_2)            {             if(Open_Price == 0)               {                Open_Price = open_price;               }             if(Open_Price < open_price)               {                Open_Price = open_price;               }             LastIsBuy = false; // Next Sell won't Trade             TotalSell++;             if(TotalSell == MaxTrade)               {                Print("Maximum Trade is reached");                return(0);               }            }         }      }    /* If the Price is downtrend to Buy Order, check the Bid */    if(LastIsBuy)      {       if(Bid <= Open_Price - (Spread * point) - (PipStep * point))         {          if(MA[0] < Ask && iclose > MA[0])            {             Buy(symbol_2, magic_2, Ask, StopLoss_3, TakeProfit_3);            }          LastIsBuy = false;          return(0);         }      }    /* If the direction is Uptrend to Sell Order, check the value of Ask */    else       if(!LastIsBuy)         {          if(Ask >= Open_Price + (Spread * point) + (PipStep * point))            {             if(MA[0] > Bid && iclose < MA[0])               {                Sell(symbol_2, magic_2, Bid, StopLoss_3, TakeProfit_3);               }             return(0);            }         }    return(0);   } //+------------------------------------------------------------------+
// I removed this code because Iam Unabe to send this message forum if it says "Message may not exceed 64000 characters"
// Order Send Function // Error Handling
 

The OnTick event handler is only called for new tick events of the current chart symbol. It is NOT called for any other symbol.

For multi-symbol, you need to adopt a different approach of event handling, such as using OnTimer() or using custom chart events from specialised indicators for this purpose.

Articles

The Implementation of a Multi-currency Mode in MetaTrader 5

Konstantin Gruzdev, 2011.02.18 17:58

For a long time multi-currency analysis and multi-currency trading has been of interest to people. The opportunity to implement a full fledged multi-currency regime became possible only with the public release of MetaTrader 5 and the MQL5 programming language. In this article we propose a way to analyze and process all incoming ticks for several symbols. As an illustration, let's consider a multi-currency RSI indicator of the USDx dollar index.
 

Sir,

I tried to Void OnTimer () ..

It has 3 Trade in "GBPUSD" symbol (Please see this photo attached) but I want to only one Trade in GPBUSD.

I tested but It has some problem.

Please Solve this code 👇

//+------------------------------------------------------------------+
//|                                                       MA_PipStep.mq5 |
//|                                            vik20011902@gmail.com|
//+------------------------------------------------------------------+
#property link      "vik20011902@gmail.com"
#property version   "1.00"

// Moving Average
int MA_Handle[];
double MA[];

// Point
double point = 0 ;

double StopLoss_point[] ;
double TakeProfit_point[];

double Ask[];
double Bid[];
double Spread[];


int AmountSymbols = 4;

string symbol[] = {"AUDUSD.s", "EURUSD.s", "GBPUSD.s", "USDCAD.s"};

input int MagicNumber = 12345;
input int MA_Period = 20;
input int MA_Shift = 1;

input int TakeProfit = 1000;
input int StopLoss = 1000;

input int MaxTrade = 3;
input int PipStep = 5;

input ENUM_TIMEFRAMES Time_Frame = PERIOD_M1;


double iclose[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   EventSetTimer(1);

   for(int i = 0; i < AmountSymbols; i++)
     {
      ArrayResize(MA_Handle, AmountSymbols);
      MA_Handle[i] = iMA(symbol[i], PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE);

      if(MA_Handle[i] == INVALID_HANDLE)
        {
         Print("Failed ", symbol[i], " Loading this Indicator ");
         return (INIT_FAILED);
        }

      //Digits
      int digits = 1;
      if(Digits() == 3 || Digits() == 5)
        {
         digits = 10;
         point = Point() * digits;
        }
      else
         if(Digits() <= 2 || Digits() == 4)
           {
            digits = 10;
            point = Point() * 1;
           }


      ArrayResize(StopLoss_point, AmountSymbols);
      ArrayResize(TakeProfit_point, AmountSymbols);

      StopLoss_point[i] = StopLoss * point ;
      TakeProfit_point[i] = TakeProfit * point ;

     }

//---
   return(INIT_SUCCEEDED);
  }


//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   for(int s = 0; s < AmountSymbols; s++)
     {
      ArrayResize(MA_Handle, AmountSymbols);

      if(MA_Handle[s] != INVALID_HANDLE)
        {
         IndicatorRelease(MA_Handle[s]);
        }
     }

   EventKillTimer();
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTimer()
  {

   for(int i = 0; i < AmountSymbols; i++)
     {
      // Moving Average Buffer
      ArraySetAsSeries(MA, true);

      int count = 3;

      if(!CopyBuffer(MA_Handle[i], 0, 1, count, MA))
        {
         Print("Failed to create Indicator");
        }


      //Bars
      if(Bars(symbol[i], PERIOD_CURRENT) < 100)
        {
         Print("Bars less than 100");
         return;
        }



      ArrayResize(Spread, AmountSymbols);

      Spread[i] = (double)SymbolInfoInteger(symbol[i], SYMBOL_SPREAD);

      Comment("Spread = ", Spread[i]);

      ArrayResize(Ask, AmountSymbols);
      ArrayResize(Bid, AmountSymbols);

      Ask[i] = SymbolInfoDouble(symbol[i], SYMBOL_ASK);
      Bid[i] = SymbolInfoDouble(symbol[i], SYMBOL_BID);


      // Maximum Trade
      int total = 0;

      for(int i = CalculateAllPositions(symbol[i]) - 1; i >= 0; i--)
        {
         ulong Position_Ticket = PositionGetTicket(i);
         if(PositionSelectByTicket(Position_Ticket))
           {


            string check_Symbol = PositionGetString(POSITION_SYMBOL);

            if(check_Symbol == symbol[i])
              {
               total++;
              }
            if(total > MaxTrade)
              {
               return;
              }
           }
        }


      // New Current Bar
      if(New_Current_Bar(symbol[i]))
        {
         ArrayResize(iclose, AmountSymbols);

         iclose[i] = iClose(symbol[i], PERIOD_CURRENT, 1);

         if(CalculateAllPositions(symbol[i]) == 0)
           {
            if(MA[0] < Ask[i] && iclose[i] > MA[0])
              {
               // Buy
               Buy(symbol[i], MagicNumber, Ask[i], StopLoss_point[i], TakeProfit_point[i]);
              }
            else
               if(MA[0] > Bid[i] && iclose[i] < MA[0])
                 {
                  // Sell
                  Sell(symbol[i], MagicNumber, Bid[i], StopLoss_point[i], TakeProfit_point[i]);
                 }
           }

         if(CalculateAllPositions(symbol[i]) >= 1)
           {
            Pip_Step(symbol[i], MagicNumber, StopLoss_point[i], TakeProfit_point[i]);
           }

        }
     }

  }

//  New Current Bar
bool New_Current_Bar(string symbol_name)
  {
   static datetime prevTime = 0;
   datetime lastTime[1];

   if(CopyTime(symbol_name, PERIOD_CURRENT, 0, 1, lastTime) == 1 && prevTime != lastTime[0])
     {
      prevTime = lastTime[0];
      return true;
     }
   return false;
  }



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CalculateAllPositions(string symbol_name)
  {
   int total = 0;

   for(int i = PositionsTotal() - 1; i >= 0; i--)
     {
      ulong Position_Ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(Position_Ticket))
        {
         ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
         string check_Symbol = PositionGetString(POSITION_SYMBOL);

         if(check_Symbol == symbol_name)
           {
            total++;
           }
        }
      //---

     }

   return(total);
  }

/*
void CalculateAllPositions(int &count_buys,int &count_sells)
  {
   count_buys  = 0;
   count_sells = 0;
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
           {
            if(m_position.PositionType()==POSITION_TYPE_BUY)
               count_buys++;
            else
               if(m_position.PositionType()==POSITION_TYPE_SELL)
                  count_sells++;
           }
  }
*/

/*
I removed this code because Iam Unabe to send this message forum MQL5 if it says "Message may not exceed 64000 characters"
Buy & Sell Trade function
*/

// PipStep  (it doesn't work to 4 Symbol)
int Pip_Step(string sparam, int magic_2, double StopLoss_3, double TakeProfit_3)
  {
   double   Open_Price  =  0;
   bool     LastIsBuy   =  false;
   int      TotalBuy   =  0;
   int      TotalSell  =  0;

   double Spread_1 = (double)SymbolInfoInteger(sparam, SYMBOL_SPREAD);

   double Ask_1 = SymbolInfoDouble(sparam, SYMBOL_ASK);
   double Bid_1 = SymbolInfoDouble(sparam, SYMBOL_BID);

   double iclose_1 = iClose(sparam, PERIOD_CURRENT, 1);


   for(int iCount = CalculateAllPositions(sparam) - 1; iCount >= 0; iCount--)
     {
      ulong Position_Ticket = PositionGetTicket(iCount);
      if(PositionSelectByTicket(Position_Ticket))
        {
         int Position_Type = (int)PositionGetInteger(POSITION_TYPE);
         string check_Symbol = PositionGetString(POSITION_SYMBOL);
         long magic = PositionGetInteger(POSITION_MAGIC);
         double open_price = PositionGetDouble(POSITION_PRICE_OPEN);

         if(Position_Type == POSITION_TYPE_BUY && check_Symbol == sparam && magic == magic_2)
           {

            if(Open_Price == 0)
              {
               Open_Price = open_price;
              }
            if(Open_Price > open_price)
              {
               Open_Price = open_price;
              }

            LastIsBuy = true;
            TotalBuy++;

            if(TotalBuy == MaxTrade)
              {
               Print("Maximum Trade is reached");
               return(0);
              }

           }

         if(Position_Type == POSITION_TYPE_SELL && check_Symbol == sparam && magic == magic_2)
           {

            if(Open_Price == 0)
              {
               Open_Price = open_price;
              }
            if(Open_Price < open_price)
              {
               Open_Price = open_price;
              }

            LastIsBuy = false; // Next Sell won't Trade
            TotalSell++;

            if(TotalSell == MaxTrade)
              {
               Print("Maximum Trade is reached");
               return(0);
              }

           }
        }
     }

   /* If the Price is downtrend to Buy Order, check the Bid */
   if(LastIsBuy)
     {

      if(Bid_1 <= Open_Price - (Spread_1 * point) - (PipStep * point))

        {


         if(MA[0] < Ask_1 && iclose_1 > MA[0])
           {
            Buy(sparam, magic_2, Ask_1, StopLoss_3, TakeProfit_3);
           }

         LastIsBuy = false;
         return(0);
        }
     }

   /* If the direction is Uptrend to Sell Order, check the value of Ask */
   else
      if(!LastIsBuy)
        {

         if(Ask_1 >= Open_Price + (Spread_1 * point) + (PipStep * point))

           {
            if(MA[0] > Bid_1 && iclose_1 < MA[0])
              {
               Sell(sparam, magic_2, Bid_1, StopLoss_3, TakeProfit_3);
              }

            return(0);
           }
        }
   return(0);
  }



I am sorry Sir..I don't understand this 2nd & 3rd Articles Because There is Russian Language in this 1st Website  &  2nd Website but I am from India . I translated this English language but it has some wronged this English lang in this website .


I understand this Void OnChartEvent() But I saw this Website if It is used Indicator.

I don't know how to make MT5 EA code in Void OnChartEvent() function but I am a Intermediate Programmer.

Особенности языка mql5, тонкости и приёмы работы - Попробуйте сэкономить на MQL5-оптимизации кода.
Особенности языка mql5, тонкости и приёмы работы - Попробуйте сэкономить на MQL5-оптимизации кода.
  • 2018.01.28
  • www.mql5.com
автоматическим торговым системам и тестированию торговых стратегий. Это реально работает даже без долгожданных сервисов. Индикатор из iCustom моделирует пользовательские сообщения еще в течении где-то 10 миллисекунд после последнего обращения iCustom
Files:
Reason: