# How can i convert mq4 to mq5?

8

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 (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
OT = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
{
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_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 (n==0 && oo==0)
{
OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-4*Point,Digits),slippage,0,0,"",magic,0,Red);
}
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;
{
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)
{
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)
{
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 (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);
}
//--------------------------------------------------------------------

15316

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 (OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
{
OT = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
{
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_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 (n==0 && oo==0)
{
OrderSend(Symbol(),OP_SELLSTOP,lot,NormalizeDouble(Bid-4*Point,Digits),slippage,0,0,"",magic,0,Red);
}
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;
{
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)
{
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)
{
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 (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);
}
//--------------------------------------------------------------------```
2816

Gábor

2181

VincentX:

Gábor

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

550128294:

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.

24

Dude,,

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