Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
I want strategy to run from 6:00 PM local until 10:00 AM local only
Collapse
X
-
I want strategy to run from 6:00 PM local until 10:00 AM local only
Hi, I want my strategy to only run or generate signals for me from 6:00 PM local time until 10:00 am local time, how do I program in these time stipulations? So I do NOT want it to run or generate signals from 10:01 AM until 5:59 PM.Tags: None
-
Jim, I use the following code snippet. You need to set interger variables for PitOpenTime and PitCloseTime in the format HHMMSS (e.g. 183000 for 6:30:00 pm)
The link below has the code I used for the StopStrategy method. I used a modified version of SampleHaltAdvancedStrategyPHP Code:[SIZE=1]if (PitOpenTime == -1) // Strategy set to run 24 hours a day[/SIZE] [SIZE=1]{[/SIZE] [SIZE=1] if (Bars.FirstBarOfSession == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE] [SIZE=1] haltProcessing = false;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] // Stop all strategy logic in the OnBarUpdate() method.[/SIZE] [SIZE=1] if (haltProcessing == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] return;[/SIZE] [SIZE=1] } [/SIZE] [SIZE=1]}[/SIZE] [SIZE=1]else if (PitCloseTime > PitOpenTime)[/SIZE] [SIZE=1]{[/SIZE] [SIZE=1] if (ToTime(Time[0]) <= PitOpenTime &&[/SIZE] [SIZE=1] ToTime(Time[0]) >= 0 &&[/SIZE] [SIZE=1] haltProcessing == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE] [SIZE=1] haltProcessing = false;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] if (ToTime(Time[0]) < PitOpenTime ||[/SIZE] [SIZE=1] (ToTime(Time[0]) > PitOpenTime && haltProcessing == true))[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] return;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] // Stop all strategy logic in the OnBarUpdate() method.[/SIZE] [SIZE=1] if (haltProcessing == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] return;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] if (ToTime(Time[0]) > PitCloseTime)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] StopStrategy("EndOfSession"); // Call custom method to close all open positions and cancel all working orders[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1]}[/SIZE] [SIZE=1]else if (PitCloseTime < PitOpenTime)[/SIZE] [SIZE=1]{[/SIZE] [SIZE=1] if (ToTime(Time[0]) >= PitOpenTime &&[/SIZE] [SIZE=1] haltProcessing == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] Print(TimeStamp+"\tStart Processing Strategy Again");[/SIZE] [SIZE=1] haltProcessing = false;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] // Stop all strategy logic in the OnBarUpdate() method.[/SIZE] [SIZE=1] if (haltProcessing == true)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] return;[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1] if (ToTime(Time[0]) < PitOpenTime && [/SIZE] [SIZE=1] ToTime(Time[0]) > PitCloseTime)[/SIZE] [SIZE=1] {[/SIZE] [SIZE=1] StopStrategy("EndOfSession"); // Call custom method to close all open positions and cancel all working orders[/SIZE] [SIZE=1] }[/SIZE] [SIZE=1]}[/SIZE] [SIZE=1]else[/SIZE] [SIZE=1]{[/SIZE] [SIZE=1] Print(TimeStamp+"\tError - PitOpenTime equals PitCloseTime");[/SIZE] [SIZE=1]}[/SIZE] [SIZE=1][/SIZE]
Greg
-
My bad on formatting the post. Don't include any [/SIZE] or [SIZE=1] statements in the code.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
571 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
331 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 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
549 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
549 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment