Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Code for months in strategy
Collapse
X
-
Code for months in strategy
Hi, what code can I use in my strategy to not trade all days in march for example? Also, If I don't want my strategy to trade Fridays in February? Thanks!Tags: None
-
Hello,
Thank you for your post.
You can compare a <DateTime>.Month to a specific number, which would correspond to a month. Below is the Microsoft documentation for this.
Similarly to detect a day of the week, you could use <DateTime>.DayOfWeek.
For example,
Code://Check if it is a Friday in February. if (Time[0].Month == 2 && Time[0].DayOfWeek == DayOfWeek.Friday) //do something
-
-
My code isn't working:
if ((Times[0][0].TimeOfDay > new TimeSpan(7, 0, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(15, 55, 0))
&& (Times[0][0].DayOfWeek != DayOfWeek.Wednesday)
// Specific
&& ((Time[0].Month == 2 && Time[0].DayOfWeek != DayOfWeek.Friday)
&& (Time[0].Month != 3)
&& (Time[0].Month == 5 && Time[0].DayOfWeek != DayOfWeek.Monday)
&& (Time[0].Month == 8 && Time[0].DayOfWeek != DayOfWeek.Tuesday)
&& (Time[0].Month != 9)
&& (Time[0].Month == 11 && Time[0].DayOfWeek != DayOfWeek.Monday)))
It doesn't activate. Does is look good? Or do I need to change anything?
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
41 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment