how to trade , sleep and trade again?

 

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

 

ANDs and ORs in the wrong place. Try this:


if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || TimeHour(TimeCurrent())>=23 || TimeHour(TimeCurrent())<=6)

 
blogzr3 wrote >>

ANDs and ORs in the wrong place. Try this:

if ((TimeHour(TimeCurrent())>=18 && TimeHour(TimeCurrent())<=21) || TimeHour(TimeCurrent())>=23 || TimeHour(TimeCurrent())<=6)

i tried it but, it seem they trade other than (18 - 21) and (23-6). But thank you for come.

 

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)
   )
)
 
(TimeHour(TimeCurrent())>=23)
&&
(TimeHour(TimeCurrent())<=6)

This will always be false

blogzr3's post is correct.

 
WHRoeder:

This will always be false

blogzr3's post is correct.

yes, sometimes i think to fast ;-), i have corrected it.

but the ThreadOpener should take care of parenthis, thats the main reason i added my post

greetings

 
WHRoeder:

This will always be false

blogzr3's post is correct.


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.

 

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.

 
jjc:


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

 
kieruwin wrote >>

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))
{