It is easy tweak ...
You just need the function Hour_trade( ) to always return "true" value ...
Please use the attached code and notice the little difference ...
//| EA Pending Order.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, WidiPramana."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Name_EA = "PendingOrder";
//extern int Start_Hour = 0;
//extern int End_Hour = 24;
extern int TP = 100;
extern int SL = 100;
extern double Lots = 0.01;
extern int Distance = 10;
extern int Magic = 69;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
label();
if(Hour_trade()==1){
if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
}
return(0);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade = true;
// if(Start_Hour > End_Hour){
// if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true;
// } else
// if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true;
return (trade);
}
int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: Pending+Order",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Hour Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------");
}
Hi Osama,
Thank you for your coding! I am waiting for Monday to test the code you given, that seems amazing!!!
By the way, Could this code execute 5 digits currency pairs (e.g.: USDAUD, USDGBP, EURGBP...) . As Jose said we have to normalize lots?
Once again, thank you for your concern and look forward to your reply!
Lawrence
Hi Osama,
Thank you for your coding! I am waiting for Monday to test the code you given, that seems amazing!!!
By the way, Could this code execute 5 digits currency pairs (e.g.: USDAUD, USDGBP, EURGBP...) . As Jose said we have to normalize lots?
Once again, thank you for your concern and look forward to your reply!
Lawrence
Yes, it is ready to work on both 4 and 5 digits.
Always try to visually backtest EAs/indicators to reveal unknown questions. That helps a lot :)
Yes, it is ready to work on both 4 and 5 digits.
Always try to visually backtest EAs/indicators to reveal unknown questions. That helps a lot :)
Hi Osama,
I have written more code for Trailing Stop based on the code you given. Could you please have a look on it? I have no idea does it work or not. And the Trailing Stop sets at 30, does it mean 30 pips or 30 fractional pips?
//| TestingTrailing+Pending.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, WidiPramana."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Name_EA = "PendingOrder";
extern int TP = 100;
extern int SL = 100;
extern double Lots = 0.01;
extern int Distance = 10;
extern int Magic = 69;
extern double TrailStop = 30;
int digit=0;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
// ---- Trailing Stops
void TrailStops()
{
int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() )
{
if ( mode==OP_BUY )
{
if ( Bid-OrderOpenPrice()>Point*TrailStop )
{
double BuyStop = OrderOpenPrice();
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(BuyStop, digit),
OrderTakeProfit(),0,LightGreen);
}
}
if ( mode==OP_SELL )
{
if ( OrderOpenPrice()-Ask>Point*TrailStop )
{
double SellStop = OrderOpenPrice();
OrderModify(OrderTicket(),OrderOpenPrice(),
NormalizeDouble(SellStop, digit),
OrderTakeProfit(),0,Yellow);
}
}
}
}
}
// ---- Scan Trades
int ScanTrades()
{
int total = OrdersTotal();
int numords = 0;
for(int cnt=0; cnt<total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if(OrderSymbol() == Symbol() && OrderType()<=OP_SELL)
numords++;
}
return(numords);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
label();
digit = MarketInfo(Symbol(),MODE_DIGITS);
if(Hour_trade()==1){
if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
if (ScanTrades()<1) return(0);
else
if (TrailStop>0) TrailStops();
}
return(0);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade = true;
return (trade);
}
int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: Pending+Order",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Hour Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------");
}
Hello,
I have following EA running successfully, however, it works only on 3 digits currency pairs (e.g.: USDJPY, AUDJPY, GBPJPY...), but not on 5 digits currency pairs (e.g.: USDAUD, USDGBP, EURGBP...) @@
Besides, I want to remove Start_Hour and End_Hour. I want to trade every moment when I click "Auto Trading" in MT4 .
Please give me a hand to figure out how to fix it, thank you very much!
Lawrence
//| EA Pending Order.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, WidiPramana."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Name_EA = "PendingOrder";
extern int Start_Hour = 0;
extern int End_Hour = 24;
extern int TP = 100;
extern int SL = 100;
extern double Lots = 0.01;
extern int Distance = 10;
extern int Magic = 69;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
label();
if(Hour_trade()==1){
if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
}
return(0);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade = false;
if(Start_Hour > End_Hour){
if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true;
} else
if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true;
return (trade);
}
int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: Pending+Order",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Hour Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------");
}
Hello,
I have following EA running successfully, however, it works only on 3 digits currency pairs (e.g.: USDJPY, AUDJPY, GBPJPY...), but not on 5 digits currency pairs (e.g.: USDAUD, USDGBP, EURGBP...) @@
Besides, I want to remove Start_Hour and End_Hour. I want to trade every moment when I click "Auto Trading" in MT4 .
Please give me a hand to figure out how to fix it, thank you very much!
Lawrence
//| EA Pending Order.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, WidiPramana."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Name_EA = "PendingOrder";
extern int Start_Hour = 0;
extern int End_Hour = 24;
extern int TP = 100;
extern int SL = 100;
extern double Lots = 0.01;
extern int Distance = 10;
extern int Magic = 69;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
label();
if(Hour_trade()==1){
if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
}
return(0);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade = false;
if(Start_Hour > End_Hour){
if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true;
} else
if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true;
return (trade);
}
int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: Pending+Order",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Hour Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------");
}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have following EA running successfully, however, it works only on 3 digits currency pairs (e.g.: USDJPY, AUDJPY, GBPJPY...), but not on 5 digits currency pairs (e.g.: USDAUD, USDGBP, EURGBP...) @@
Besides, I want to remove Start_Hour and End_Hour. I want to trade every moment when I click "Auto Trading" in MT4 .
Please give me a hand to figure out how to fix it, thank you very much!
Lawrence
//| EA Pending Order.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, WidiPramana."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern string Name_EA = "PendingOrder";
extern int Start_Hour = 0;
extern int End_Hour = 24;
extern int TP = 100;
extern int SL = 100;
extern double Lots = 0.01;
extern int Distance = 10;
extern int Magic = 69;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
label();
if(Hour_trade()==1){
if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
}
return(0);
}
//+------------------------------------------------------------------+
int Hour_trade()
{
bool trade = false;
if(Start_Hour > End_Hour){
if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true;
} else
if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true;
return (trade);
}
int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: Pending+Order",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Hour Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------");
}