Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy Builder variable reference
Collapse
X
-
Strategy Builder variable reference
I have created an entry strategy in Builder where one of the conditions refers to a set of conditions that occur during premarket hours. See images below. For some reason the premarket filter is not screening the entries and gives me entries regardless of the PreMktCriteria being = 1. I may be missing something? Please advice. Thank you any suggestions welcomed.
Tags: None
-
Hi Jesse, I tried changing to 0 same issue. I also tried bool as in image 01 default as "PreMktCriteria bool false" with no change.
Comment
-
Hello designer01,
You will need to use a Print as an action to better understand when your condition is becoming true.
the way the condition is set up would work as the following:
Set 1: checks for a time range and HMA condition, if true it sets the variable to 1
Set 2: checks the HMA condition and if the variable equals 1, if true enters.
Once your set 1 becomes true once then the set 2 will be allowed any time going forward. If you meant to prevent entries in any other use case then you still need to add other logic to do that. You can reset the variable back to 0 when the condition should no longer be allowed.
An example of what may be happening could be that on a historical day the variable is set to true, then all future days the variable is still true leading to set 2 being checked all the time. You would have to make an additional set if the strategy runs more than 1 day to reset that variable on the first bar of the session.
Comment
-
Hi Jesse, Thanks I had to unlock the code and insert an else statement and it works.
I could not figure out how to do it in Builder, is there an option for an else statement in Builder see code below.
Code:// Set 1 if ((Times[0][0].TimeOfDay > new TimeSpan(9, 29, 0)) && (Times[0][0].TimeOfDay < new TimeSpan(9, 31, 0)) && (Close[0] > HMA1[0])) { BackBrush = Brushes.SandyBrown; PreMktCriteria = true; } else if ((Times[0][0].TimeOfDay > new TimeSpan(9, 29, 0)) && (Times[0][0].TimeOfDay < new TimeSpan(9, 31, 0)) && (Close[0] < HMA1[0])) { PreMktCriteria = false; }
Comment
-
Hello designer01,
There is not an option for an else statement in the builder. The alternative would be to make an always true set which comes before the first condition.
For example set 1 would set PreMktCriteria to false with no conditions or with a different set of hours to check. In set 2 you can check the condition which sets it to true. That would leave it false for all bars where set 2 is not true. This of course depends on your overall goal and how that PreMktCriteria variable should operate.
Comment
-
Hi Jesse, I did 2 separate if statements sets as shown in the code above, no need to have the else as you said. Works good. Thanks
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
51 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
129 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 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