&& ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)))
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Time Filter
Collapse
X
-
Time Filter
Why is this time filter allowing some trades to happen outside the time range.
Thanks in advance.Code:Tags: None
-
-
There is not one specific time, according to the distribution chart (entry), it happens at all times. Tick chart, volume in particular.Originally posted by NinjaTrader_Bertrand View PostWould suggest you then visually idenfiy the areas where it would evaluate to true so you can debug the condition for your setup - is this being worked from a tick or time based chart?
Comment
-
See images, which are just back tests of the codes below with the exact same parameters. Notice the slight differences in and out of the intended time filter. I am stumped on a solution.Originally posted by NinjaTrader_Bertrand View PostThe time filter you posted itself look accurate to me, would suggest simplifying your script and debugging where the additional entries are coming from - there's no ambiguity here - the code will evaluate when the conditions dictate it to.
Image, "SimplewithTimeFilter," is of this very simple code with a time filter.
Image, "SimplewithoutTimeFilter," is of this very simple code without a time filter.Code:// Condition set 1 if (Close[1] > Close[2] && Close[2] > Close[3] && Close[3] >= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1 && ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))) { EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, ""); } // Condition set 1 if (Close[1] < Close[2] && Close[2] < Close[3] && Close[3] <= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1 && ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))) { EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, ""); }
Code:// Condition set 1 if (Close[1] > Close[2] && Close[2] > Close[3] && Close[3] >= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, ""); } // Condition set 1 if (Close[1] < Close[2] && Close[2] < Close[3] && Close[3] <= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, ""); }
Comment
-
Thanks, I see - I would suggest restructuring the code to this version -
Code:if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)) { // Condition set 1 if (Close[1] > Close[2] && Close[2] > Close[3] && Close[3] >= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, ""); } // Condition set 1 if (Close[1] < Close[2] && Close[2] < Close[3] && Close[3] <= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, ""); } }
Comment
-
Thank you, but why? What if I wanted different times for long and short?Originally posted by NinjaTrader_Bertrand View PostThanks, I see - I would suggest restructuring the code to this version -
Code:if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)) { // Condition set 1 if (Close[1] > Close[2] && Close[2] > Close[3] && Close[3] >= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, ""); } // Condition set 1 if (Close[1] < Close[2] && Close[2] < Close[3] && Close[3] <= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) { EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, ""); } }
Comment
-
The reason is because of the short circuit evaluation of your boolean && + || statements here having nested the time filter into the main condition. If you would like different times for longs / shorts you can move it of course directly before the if part submitting the final order as well to make more flexible -
Code:if (Close[1] > Close[2] && Close[2] > Close[3] && Close[3] >= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) //&& ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))) { if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)) EnterLongLimit(DefaultQuantity, Close[2] + 2 * TickSize, ""); } if (Close[1] < Close[2] && Close[2] < Close[3] && Close[3] <= Close[4] && BarsSinceExit() > 2 || BarsSinceExit() == -1) //&& ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000))) { if ((ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 20000) || (ToTime(Time[0]) >= 50000 && ToTime(Time[0]) < 100000)) EnterShortLimit(DefaultQuantity, Close[2] - 2 * TickSize, ""); }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment