Need help with time filter
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.
... if(Opening_condition) { if( ! (Hour()>=0 && Hour()<=4 || Hour()>=8 && Hour()<=24)) { // Open your trade... } } // Close...See also these posts about mixing of && and ||.
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.
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) );
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.
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.
Thanks Raptor, printing out really helps . Still playing around with different time filter combinations.
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.