Download MetaTrader 5

How can i convert mq4 to mq5?

To add comments, please log in or register
550128294
8
550128294  

extern int     Step           = 15;
extern double  ProfitClose    = 1.0,
               lot            = 0.01;
extern int     slippage       = 3,     //The maximum permissible deviation of the price for market orders (orders to buy or sell).
               magic          = 0;     //The magic number order. Can be used as a user-defined identifier.
//--------------------------------------------------------------------
int init()
{
   Comment("Start EA ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
}
//--------------------------------------------------------------------
int start()
{
   double OOP,Price,Lot,Profit,MaxLot;
   int OT,n,oo,Order;
   for (int i=0; i<OrdersTotal(); i++)
   {   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            OT = OrderType();
            OOP = NormalizeDouble(OrderOpenPrice(),Digits);
            if (OT==OP_BUY)            
            { 
               Price = OOP;
               Lot = OrderLots();
               Profit+=OrderProfit()+OrderSwap()+OrderCommission();
               if (MaxLot<Lot) {MaxLot=Lot; Order= 1;}
               n++;
            }                                        
            if (OT==OP_SELL)       
            {
               Price = OOP;
               Lot = OrderLots();
               Profit+=OrderProfit()+OrderSwap()+OrderCommission();
               if (MaxLot<Lot) {MaxLot=Lot; Order=-1;}
               n++;
            }
            if (OT>1) oo++;
         }
      }
   }
   Comment("Profit ",DoubleToStr(Profit,2));
   if (Profit>ProfitClose)
   {
      CloseAllOrders(OP_BUY);
      CloseAllOrders(OP_SELL);
   }
   if (Order==1 && Bid+n*Step*Point<Price)
   {
      if(OrderSend(Symbol(),OP_SELL,Lot*2,NormalizeDouble(Bid,Digits),slippage,0,0,"",magic,0,Red)!=-1) return;
   }
  
   if (Order==-1 && Ask-n*Step*Point>Price)
   {
      if(OrderSend(Symbol(),OP_BUY,Lot*2,NormalizeDouble(Ask,Digits),slippage,0,0,"",magic,0,Blue)!=-1) return;
   }
  
   if (n==0 && oo==0)
   {
      OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-4*Point,Digits),slippage,0,0,"",magic,0,Red);
      OrderSend(Symbol(),OP_BUYSTOP ,lot,NormalizeDouble(Ask+4*Point,Digits),slippage,0,0,"",magic,0,Blue);
   }
   if (n!=0) DeleteAll(0);
   return(0);
}
//-----------------------------------------------------------------
bool CloseAllOrders(int tip)
{
   bool error=true;
   int err,nn,OT,OMN;
   while(true)
   {
      for (int j = OrdersTotal()-1; j >= 0; j--)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT != tip) continue;
               if (OT==OP_BUY)
               {
                  error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Blue);
                  if (error) Comment("Close order N ",OrderTicket(),"  Profit ",OrderProfit(),
                                     "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
               if (OT==OP_SELL)
               {
                  error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,Red);
                  if (error) Comment("Close order N ",OrderTicket(),"  Profit ",OrderProfit(),
                                     "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
               if (!error)
               {
                  err = GetLastError();
                  if (err<2) continue;
                  if (err==129)
                  {  Comment("Wrong price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
                     RefreshRates();
                     continue;
                  }
                  if (err==146)
                  {
                     if (IsTradeContextBusy()) Sleep(2000);
                     continue;
                  }
                  Comment("Error ",err," close order N ",OrderTicket(),
                          "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
            }
         }
      }
      int n=0;
      for (j = 0; j < OrdersTotal(); j++)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT != tip) continue;
               if (OT==OP_BUY || OT==OP_SELL) n++;
            }
         } 
      }
      if (n==0) break;
      nn++;
      if (nn>10) {Alert(Symbol()," Failed to close all trades, there are still ",n);return(0);}
      Sleep(1000);
      RefreshRates();
   }
   return(1);
}
//--------------------------------------------------------------------
bool DeleteAll(int tip)
{
   bool error;
   int err,n,OMN,OT;
   while(true)
   {
      error=true;
      for (int j = OrdersTotal()-1; j >= 0; j--)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
            }
         }
      }
      if (error) break;
      n++;
      if (n>10) break;
      Sleep(1000);
   }
   return(1);
}
//--------------------------------------------------------------------

 

Please help me convert mq4 to mq5?   

Achmad Hidayat
14768
Achmad Hidayat  

Lets's wait, maybe forumer will help you.

Note : Next time you should write the code using "SRC" :


the result like this :

extern int     Step           = 15;
extern double  ProfitClose    = 1.0,
               lot            = 0.01;
extern int     slippage       = 3,     //The maximum permissible deviation of the price for market orders (orders to buy or sell).
               magic          = 0;     //The magic number order. Can be used as a user-defined identifier.
//--------------------------------------------------------------------
int init()
{
   Comment("Start EA ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
}
//--------------------------------------------------------------------
int start()
{
   double OOP,Price,Lot,Profit,MaxLot;
   int OT,n,oo,Order;
   for (int i=0; i<OrdersTotal(); i++)
   {   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            OT = OrderType();
            OOP = NormalizeDouble(OrderOpenPrice(),Digits);
            if (OT==OP_BUY)            
            { 
               Price = OOP;
               Lot = OrderLots();
               Profit+=OrderProfit()+OrderSwap()+OrderCommission();
               if (MaxLot<Lot) {MaxLot=Lot; Order= 1;}
               n++;
            }                                        
            if (OT==OP_SELL)       
            {
               Price = OOP;
               Lot = OrderLots();
               Profit+=OrderProfit()+OrderSwap()+OrderCommission();
               if (MaxLot<Lot) {MaxLot=Lot; Order=-1;}
               n++;
            }
            if (OT>1) oo++;
         }
      }
   }
   Comment("Profit ",DoubleToStr(Profit,2));
   if (Profit>ProfitClose)
   {
      CloseAllOrders(OP_BUY);
      CloseAllOrders(OP_SELL);
   }
   if (Order==1 && Bid+n*Step*Point<Price)
   {
      if(OrderSend(Symbol(),OP_SELL,Lot*2,NormalizeDouble(Bid,Digits),slippage,0,0,"",magic,0,Red)!=-1) return;
   }
  
   if (Order==-1 && Ask-n*Step*Point>Price)
   {
      if(OrderSend(Symbol(),OP_BUY,Lot*2,NormalizeDouble(Ask,Digits),slippage,0,0,"",magic,0,Blue)!=-1) return;
   }
  
   if (n==0 && oo==0)
   {
      OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-4*Point,Digits),slippage,0,0,"",magic,0,Red);
      OrderSend(Symbol(),OP_BUYSTOP ,lot,NormalizeDouble(Ask+4*Point,Digits),slippage,0,0,"",magic,0,Blue);
   }
   if (n!=0) DeleteAll(0);
   return(0);
}
//-----------------------------------------------------------------
bool CloseAllOrders(int tip)
{
   bool error=true;
   int err,nn,OT,OMN;
   while(true)
   {
      for (int j = OrdersTotal()-1; j >= 0; j--)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT != tip) continue;
               if (OT==OP_BUY)
               {
                  error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,Blue);
                  if (error) Comment("Close order N ",OrderTicket(),"  Profit ",OrderProfit(),
                                     "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
               if (OT==OP_SELL)
               {
                  error=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,Red);
                  if (error) Comment("Close order N ",OrderTicket(),"  Profit ",OrderProfit(),
                                     "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
               if (!error)
               {
                  err = GetLastError();
                  if (err<2) continue;
                  if (err==129)
                  {  Comment("Wrong price ",TimeToStr(TimeCurrent(),TIME_SECONDS));
                     RefreshRates();
                     continue;
                  }
                  if (err==146)
                  {
                     if (IsTradeContextBusy()) Sleep(2000);
                     continue;
                  }
                  Comment("Error ",err," close order N ",OrderTicket(),
                          "     ",TimeToStr(TimeCurrent(),TIME_SECONDS));
               }
            }
         }
      }
      int n=0;
      for (j = 0; j < OrdersTotal(); j++)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT != tip) continue;
               if (OT==OP_BUY || OT==OP_SELL) n++;
            }
         } 
      }
      if (n==0) break;
      nn++;
      if (nn>10) {Alert(Symbol()," Failed to close all trades, there are still ",n);return(0);}
      Sleep(1000);
      RefreshRates();
   }
   return(1);
}
//--------------------------------------------------------------------
bool DeleteAll(int tip)
{
   bool error;
   int err,n,OMN,OT;
   while(true)
   {
      error=true;
      for (int j = OrdersTotal()-1; j >= 0; j--)
      {
         if (OrderSelect(j, SELECT_BY_POS))
         {
            OMN = OrderMagicNumber();
            if (OrderSymbol() == Symbol() && OMN == magic)
            {
               OT = OrderType();
               if (OT>1 && (tip==0 || OT==tip)) error=OrderDelete(OrderTicket());
            }
         }
      }
      if (error) break;
      n++;
      if (n>10) break;
      Sleep(1000);
   }
   return(1);
}
//--------------------------------------------------------------------
Gabor Torma
2692
Gabor Torma  
I can help you.

Please create a new job.

Gábor

phi nuts
2184
phi nuts  
VincentX:
I can help you.

Please create a new job.

Gábor

Please don't do that. Than's not a kind of help we expect around here.


550128294:


Please help me convert mq4 to mq5?   

 If you expecting a free help, then you probably won't get any help at all. To get a free help, for a start, you should show some code to show your effort in coding this to mql5 code

BTW, this is very simple code, it will be too expensive if you pay $1 in job section.

svinoth
24
svinoth  

Dude,,

 

 

Can u tell me the special features of these EA.....Is it working as profitable for u. 

To add comments, please log in or register