How to convert mt4 to mt5

 
Hi, i have written a code in mt4 and trying to make the same ea in mt5. However, i am having trouble converting it to mt5. Thank you in advance in helping me.  dont know how to close the trade  in mt5. Thanks
void OnTick()
  {
  
      //curent chart, current period, 20 candles,no shift, simple, close price
      double SlowMovingAverage15 = iMA(NULL, 1,20,0,MODE_EMA,PRICE_CLOSE,0);
      
      //curent chart, current period, 20 candles,no shift, simple, close price
      double LastSlowMovingAverage15 = iMA(NULL, 1,20,0,MODE_EMA,PRICE_CLOSE,1);
            
      //curent chart, current period, 10 candles,no shift, simple, close price
      double FastMovingAverage15 = iMA(NULL, 1,10,0,MODE_EMA,PRICE_CLOSE,0);
            
      //curent chart, current period, 10 candles,no shift, simple, close price
      double LastFastMovingAverage15 = iMA(NULL, 1,10,0,MODE_EMA,PRICE_CLOSE,1);
            
      //curent chart, current period, 8 candles,no shift, simple, close price
      double SlowMovingAverage = iMA(NULL, 1,8,0,MODE_EMA,PRICE_CLOSE,0);
            
      //curent chart, current period, 8 candles,no shift, simple, close price
      double LastSlowMovingAverage = iMA(NULL, 1,8,0,MODE_EMA,PRICE_CLOSE,1);
            
      //curent chart, current period, 4 candles,no shift, simple, close price
      double FastMovingAverage = iMA(NULL, 1,4,0,MODE_EMA,PRICE_CLOSE,0);
            
      //curent chart, current period, 4 candles,no shift, simple, close price
      double LastFastMovingAverage = iMA(NULL, 1,4,0,MODE_EMA,PRICE_CLOSE,1);
      
      
      bool firstpart_buy = LastFastMovingAverage15 < LastSlowMovingAverage15
               && FastMovingAverage15 > SlowMovingAverage15 ;
               
      bool firstpart_sell = LastFastMovingAverage15 > LastSlowMovingAverage15
               && FastMovingAverage15 < SlowMovingAverage15 ;
               
      bool secondpart_buy =  LastFastMovingAverage > LastSlowMovingAverage 
               && FastMovingAverage < SlowMovingAverage ;
               
      bool secondpart_sell = LastFastMovingAverage < LastSlowMovingAverage 
               && FastMovingAverage > SlowMovingAverage ; 
  
      enum State {idle, c2b, c2s};
      static State state = idle;
      
      
    
      if (firstpart_buy == true)  
      {    
         state = c2b;
         
         return state;
         
         
       }   
       
        
      if (firstpart_sell == true)  
      {
      
         state = c2s;
         return state;
      }
      
      
      if (secondpart_buy == true)
      {
      
         if (state == c2b)
         {
            for (int i= OrdersTotal()-1; i>=0; i--)
                  {
                     if (OrderSelect(i, SELECT_BY_POS)== true)
                     
                     //if (OrderSymbol() == Symbol())
                     {
                        if (OrderType() == OP_BUY)
                        {
                        OrderClose( OrderTicket(), OrderLots(),Bid,3, NULL );
                        }
                        
                        if (OrderType() == OP_SELL)
                        {
                        OrderClose(OrderTicket(), OrderLots(),Ask,3,NULL);
                        }
                     }
                     
                     state = idle;
                     return state;
                  }   
         
         }
      
      
            
         if (state == idle)
         {
            state = idle;
            return state;
         }
       }    
      
      
      
      if (secondpart_sell == true)
      {
         if(state == c2s) 
         {
            for (int c= OrdersTotal(); c>=0; c--)
                  {
                     if (OrderSelect(c, SELECT_BY_POS)== true)
                     
                     //if (OrderSymbol() == Symbol())
                     {
                        if (OrderType() == OP_BUY)
                        {
                        OrderClose( OrderTicket(), OrderLots(),Bid,3, NULL );
                        }
                        
                        if (OrderType() == OP_SELL)
                        {
                        OrderClose( OrderTicket(), OrderLots(),Ask,3, NULL );
                        }
                     }
                     
                     state = idle;
                     return state;
                  }     
         }
         
         
         if(state == idle)
         {
            state = idle;
            return state;
         }
      
      }

//////above is my mt4 code/////


////////below is my mt5 code

void OnTick()
  {

   double SlowMovingAverage15     = iMA(NULL, PERIOD_M1,20,0,MODE_EMA,PRICE_CLOSE);
   double FastMovingAverage15     = iMA(NULL, PERIOD_M1,10,0,MODE_EMA,PRICE_CLOSE);
   double SlowMovingAverage       = iMA(NULL, PERIOD_M1,8,0,MODE_EMA,PRICE_CLOSE);
   double FastMovingAverage       = iMA(NULL, PERIOD_M1,4,0,MODE_EMA,PRICE_CLOSE);
   
   bool firstbuy = SlowMovingAverage15 < FastMovingAverage15 ;
   bool firstsell = SlowMovingAverage15 > FastMovingAverage15;
   bool secondpart_buy = SlowMovingAverage < FastMovingAverage;
   bool secondpart_sell = SlowMovingAverage> FastMovingAverage;
   
   enum State {idle, c2b, c2s};
   static State state = idle;
   
   if (firstbuy == true)
   {
      state = c2b;
      return;
   }
   
   if (firstsell == true)
   {
      state = c2s;
      return;
   }
   
   if (secondpart_buy == true)
   {
      if (state == c2b)
      {
         bool success = true;
         for (int i= PositionsTotal()-1; i>=0; i--)
         {
            if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY);
            {
              trade.Positionclose(posTicket))
            }
            
            if ((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL);
         }
      }
   }
   
   
  }
     
      
}
 
Progmt4:
Hi, i have written a code in mt4 and trying to make the same ea in mt5. However, i am having trouble converting it to mt5. Thank you in advance in helping me.  dont know how to close the trade  in mt5. Thanks

Hi, maybe these 2 articles can help you knowing what to convert?

https://www.mql5.com/en/articles/81&nbsp;  

https://www.mql5.com/en/articles/66

Transferring Indicators from MQL4 to MQL5
Transferring Indicators from MQL4 to MQL5
  • www.mql5.com
This article is dedicated to peculiarities of transferring price constructions written in MQL4 to MQL5. To make the process of transferring indicator calculations from MQL4 to MQL5 easier, the mql4_2_mql5.mqh library of functions is suggested. Its usage is described on the basis of transferring of the MACD, Stochastic and RSI indicators.
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893