Hi Guys please help me i would like my system to trade only between 7am-5pm. how do i work with this coding. the person that made it for me does not respond anymore.
string separator1 = "------ GMT Trading Days ------";
int ppi_GMT_Offset = 0;//Your Broker Trade Server time offset relativly to GMT
input int ppi_Sunday = 0;
input int ppi_Monday = 1;
input int ppi_Tuesday = 1;
input int ppi_Wednesday = 1;
input int ppi_Thursday = 1;
input int ppi_Friday = 1;
input int ppi_Saturday = 0;
input bool pb_TradeSession1 = true;//Enable trade in session1
input int pi_StartHoursSession1 = 0;//Trade session 1 start hours,trade server time
input int pi_StartMinutesSession1 = 5;//Trade session 1 start minutes,trade server time
input int pi_StopHoursSession1 = 23;//Trade session 1 stop hours,trade server time
input int pi_StopMinutesSession1 = 59;//Trade session 1 stop minutes,trade server time
input bool pb_TradeSession2 = false;//Enable trade in session2
input int pi_StartHoursSession2 = 16;//Trade session 2 start hours,trade server time
input int pi_StartMinutesSession2 = 20;//Trade session 2 start minutes,trade server time
input int pi_StopHoursSession2 = 0;//Trade session 2 stop hours,trade server time
input int pi_StopMinutesSession2 = 0;//Trade session 2 stop minutes,trade server time
inputbool pb_TradeSession1 = true;//Enable trade in session1inputint pi_StartHoursSession1 = 0;//Trade session 1 start hours,trade server time inputint pi_StartMinutesSession1 = 5;//Trade session 1 start minutes,trade server time inputint pi_StopHoursSession1 = 23;//Trade session 1 stop hours,trade server time inputint pi_StopMinutesSession1 = 59;//Trade session 1 stop minutes,trade server time
All you've posted are inputs. If a trading times function has been implemented, just change the values to what you want. Otherwise, you have only four
choices:
learntocodeit. If you don't learn MQL4/5, there is no common language
for us to communicate. If we tell you what you need, you can't code it. If we
give you the code, you don't know how to integrate it into yours.
We're not going to code it for you
(although it could happen if you are lucky or the problem is interesting.)
We are willing to help you when you
post your attempt (using CODE button) and state the nature of your problem.
No free help urgent help.
First, I'd follow William Roeder's requests (remove duplicate post, etc.) Then I'd simply use his morninghours/afternoonhours code from
2011 found on the previous page. Of course it needs a little tweaking to make it work in MQL5. Something like changing the Hour()
functions to TimeHourMQL4() found
here.
ZCI-FX:
Hi Guys please help me i would like my system to trade only between 7am-5pm. how do i work with this coding. the person that made it for
me does not respond anymore.
bool goodtimetotrade()
{
string badtimes[] = {"08:16-10:30","15:25-16:15"};
string sep="-";
ushort u_sep=StringGetCharacter(sep,0);
string result[];
int size = ArraySize(badtimes);
int time=TimeLocal();
for(int i=0; i<size; i++)
{
StringSplit(badtimes[i],u_sep,result);
int timefrom = StrToTime(result[0]);
int timeto = StrToTime(result[1]);
if(time>timefrom && time<timeto)
{
returnfalse; // not a good time
}
}
returntrue; // time is fine
}
This is currently working as expected. If is outside this time range the EA does not trade. if((Hour()<=StartTime || Hour()>EndTime))return(0); //Preferd Trading Hours
From an older EA, which I believed tested successfully but is not working. if((Hour()<=7 || Hour()>=10) || (Hour()<=14 || Hour()>=18))return(0); //Prefer Trading Hours
Any Ideas why the second option is not working?
I am assuming I can configure & test the following, but was looking for a cleaner solution. if(Hour()==7 || Hour()==8 || Hour()==9 || Hour()==10 || Hour()==14 || Hour()==15 || Hour()==16 || Hour()==17 || Hour()==18)return(0); //Prefer Trading Hours
Thank you.
I'm decades late to this chain but I wondered the same thing and saw @Simon Gniadkowski's function which works for a single time frame. With a little tweak it works for the 2 time frames letting the user specify. Just tested it with the EA I'm building.
bool AllowTradesByTime(int Start_Time, int Finish_Time, int Start_Time2, int Finish_Time2)
{
datetime Current_Time = TimeHour(TimeCurrent());
if (Start_Time == 0) Start_Time = 24; if (Finish_Time == 0) Finish_Time = 24; if (Current_Time == 0) Current_Time = 24;
if (Start_Time2 == 0) Start_Time2 = 24; if (Finish_Time2 == 0) Finish_Time2 = 24; if (Current_Time == 0) Current_Time = 24;
if (Start_Time < Finish_Time && Start_Time2 < Finish_Time2)
if ((Current_Time < Start_Time) || (Current_Time >= Finish_Time && Current_Time < Start_Time2) || (Current_Time >= Finish_Time2)) return(false);
if (Start_Time > Finish_Time && Start_Time2 > Finish_Time2)
if ((Current_Time < Start_Time) || (Current_Time >= Finish_Time && Current_Time < Start_Time2) || (Current_Time >= Finish_Time2)) return(false);
return(true);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
string separator1 = "------ GMT Trading Days ------";
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor
-
Search for it,
-
Beg at
- Coding help -
MQL4 and MetaTrader 4 - MQL4 programming forum
-
Requests & Ideas (MQL5 only!) -
Trade FX - Expert Advisors and Automated Trading -
MQL5 programming forum
-
Free coding for your
trading system.. - Easy Trading Strategy - General -
MQL5 programming forum
-
I will code & automate your
strategy for free - Options Trading Strategies - General -
MQL5 programming forum
-
Make It No Repaint Please! -
MetaTrader 5 - MQL4 and MetaTrader 4 -
MQL4 programming forum
-
learn
to code it. If you don't learn MQL4/5, there is no common language
for us to communicate. If we tell you what you need, you can't code it. If we
give you the code, you don't know how to integrate it into yours.
-
or pay (Freelance)
someone to code it.
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.No free help
urgent help.
First, I'd follow William Roeder's requests (remove duplicate post, etc.) Then I'd simply use his morninghours/afternoonhours code from 2011 found on the previous page. Of course it needs a little tweaking to make it work in MQL5. Something like changing the Hour() functions to TimeHourMQL4() found here.
This is currently working as expected. If is outside this time range the EA does not trade.
if((Hour()<=StartTime || Hour()>EndTime))return(0); //Preferd Trading Hours
From an older EA, which I believed tested successfully but is not working.
if((Hour()<=7 || Hour()>=10) || (Hour()<=14 || Hour()>=18))return(0); //Prefer Trading Hours
Any Ideas why the second option is not working?
I am assuming I can configure & test the following, but was looking for a cleaner solution.
if(Hour()==7 || Hour()==8 || Hour()==9 || Hour()==10 || Hour()==14 || Hour()==15 || Hour()==16 || Hour()==17 || Hour()==18)return(0); //Prefer Trading Hours
Thank you.
I'm decades late to this chain but I wondered the same thing and saw @Simon Gniadkowski's function which works for a single time frame. With a little tweak it works for the 2 time frames letting the user specify. Just tested it with the EA I'm building.