ANDs and ORs in the wrong place. Try this:
if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || TimeHour(TimeCurrent())>=23 || TimeHour(TimeCurrent())<=6)
instead of 21 use 20
instead of 6 use 5
because 21.59/6.59 are one hour to late ;-)
if ( ( (TimeHour(TimeCurrent())>=18) && (TimeHour(TimeCurrent())<=20) ) || ( (TimeHour(TimeCurrent())>=23) //&& yes, this is wrong thanks WHRoeder ;-) || (TimeHour(TimeCurrent())<=5) ) )
Thank you for meikel, WHRoeder, jjc and blogzr3 for quick answer, you had the same idea. Maybe my code is wrong, i will try to fix it first.
Sorry i am just a tweaker not a great coder.
Thanks again friends.
Strictly speaking, isn't "TimeHour(TimeCurrent())<=6" wrong? This evaluates as true up until 06:59, whereas the original comment specifies 06:00 as the end time.
Yes that is wrong 6:59 is outside the end of 6:00 but TimeHour is still 6
How to trade on several hours then sleep and continue again ? for example start at 18.00 to 21.00, sleep for 2 hours, then cotinue again at 23.00 to 6.00 in the next morning.
I tried with this, but why on tester it only trade at 18.00 to 21.00?
if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || (TimeHour(TimeCurrent())>=23 && TimeHour(TimeCurrent())<=6))
{
Thanks
The clock stops at 23:59.
To take care of 11pm to midnight, TimeHour(TimeCurrent())=23.
To take care of midnight to 6:59am, TimeHour(TimeCurrent())>=00 && TimeHour(TimeCurrent())<=06).
if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || (TimeHour(TimeCurrent())=23)||(TimeHour(TimeCurrent())>=00 && TimeHour(TimeCurrent())<=06))
{
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to trade on several hours then sleep and continue again ? for example start at 18.00 to 21.00, sleep for 2 hours, then continue again at 23.00 to 6.00 in the next morning.
I tried with this, but why on tester it only trade at 18.00 to 21.00?
if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || (TimeHour(TimeCurrent())>=23 && TimeHour(TimeCurrent())<=6))
{
Thanks