Need help with time filter

 
Hi all,

Having an issue closing orders .

Here is the code for filtering:
if((Hour()>=0 && Hour()<=4 || Hour()>=8  && Hour()<=24))return(false);

This is working fine, new trades are not opening. The issue is getting out of the trade. Ie. trade is placed at 7:45am gmt and exit is signaled at 8:15am. Nothing will happen, no tp, breakeven etc..

This is how I normally get out of a trade:

if  (abc>0 ) {

  close=true;

}
And have tried:
if (abc >0 || Hour()>=7 && Minute()>=50 ) {

close=true;

}


The above basically closes the trade exactly at 7:50am. Not what I am looking from. I want to exit the trade at my normal exit above bypassing the time filter.

 
zzdream:
Hi all,

Having an issue closing orders .

Here is the code for filtering:

This is working fine, new trades are not opening. The issue is getting out of the trade. Ie. trade is placed at 7:45am gmt and exit is signaled at 8:15am. Nothing will happen, no tp, breakeven etc..

This is how I normally get out of a trade:

And have tried:


The above basically closes the trade exactly at 7:50am. Not what I am looking from. I want to exit the trade at my normal exit above bypassing the time filter.

Apply only your filter to your opening then.

...

if(Opening_condition)
{
   if( ! (Hour()>=0 && Hour()<=4 || Hour()>=8  && Hour()<=24))
   {
     // Open your trade...
   }
}

// Close...
See also these posts about mixing of && and ||.
 
Thanks for the reply. Makes sense :)
 
Question:

Why is condition being evaluated as true:
if (abc>0 && hour()>=4 && hour()<=5) {

buy=true;

} 
Testing this, and trying to only trade from 4am gmt to 5am gmt. Trades are being opened at 6:05am.
 
zzdream:
Question:

Why is condition being evaluated as true: Testing this, and trying to only trade from 4am gmt to 5am gmt. Trades are being opened at 6:05am.

Because it is true . . . Print() hour() and see what you get . . . better still . . .

Print("Hour() returns: ", Hour(), " current time is : ", TimeToStr(TimeCurrent(), TIME_DATE|TIME_MINUTES) );
 
Thanks for replying,

I'll test the above when I get a chance. Can you please explain why ? Please excuse my ignornance ..totally new to this stuff..however find it extremely fascinating. I thought the code above will build a block around the two hours 4 & 5, nothing above or below.
 
zzdream:
Thanks for replying,

I'll test the above when I get a chance. Can you please explain why ? Please excuse my ignornance ..totally new to this stuff..however find it extremely fascinating. I thought the code above will build a block around the two hours 4 & 5, nothing above or below.
I have seen Hour() not work as many people expect, others have reported that it works just fine . . . how is it working for you ? and . . . when you say between 4 & 5 you actually mean 4 and 5:59 . . . 5:59 has an Hour() of 5
 
Right so 4 and 5:59 is ok,but 6:05 should return false..I'm confused.
 
zzdream:
Right so 4 and 5:59 is ok,but 6:05 should return false..I'm confused.
So test it and remove your confusion . . . it's very simple, test and see what is wrong.
 
Thanks Raptor, printing out really helps . Still playing around with different time filter combinations.
 
zzdream:
Thanks Raptor, printing out really helps . Still playing around with different time filter combinations.
So was Hour() correct ?
Reason: