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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
65 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
35 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
59 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
51 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment