Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
2 Conditions with different Bars.BarsSinceSession
Collapse
X
-
Hello wallsteetking,
Thank you for your response.
Are you looking for the session's open or the current bar's open? Open[0] would be the current bar's open.
Setting the parameters to false will not resolve this matter. Can you provide a screenshot of your chart where the entries are made that should not be with your first example?
I look forward to your response.
-
Patrick, you are correct I am trying to check a condition on the first bar of the session and then a second condition in-between a specified number of bars. However, removingCode:protected override void OnBarUpdate() { enterLongStrat1 = false; enterLongStrat2 = false;
Code:#region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 private bool enterLongStrat1 = false; private bool enterLongStrat2 = false; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { SetProfitTarget("", CalculationMode.Ticks, 4); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 [B][COLOR="Blue"] if (Bars.BarsSinceSession == 1)[/COLOR][/B] if (Close[0] >= Open[0] + 4 * TickSize) { enterLongStrat1 = true; } // Condition set 2 [B][COLOR="blue"]if (Bars.BarsSinceSession == 7)[/COLOR][/B] if (Close[0] >= Open[0] + 4 * TickSize) { enterLongStrat2 = true; } // tally up if (Bars.BarsSinceSession == 10 && enterLongStrat1 == true && enterLongStrat2 == true) { EnterLong(DefaultQuantity, ""); } }
I also tried,
Code:#region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 private bool enterLongStrat1 = false; private bool enterLongStrat2 = false; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { SetProfitTarget("", CalculationMode.Ticks, 4); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 [B][COLOR="Blue"] if (Bars.BarsSinceSession == 1)[/COLOR][/B] if (Close[0] >= Open[0] + 4 * TickSize) { enterLongStrat1 = true; [B][COLOR="red"] enterLongStrat2 = false;[/COLOR][/B] } // Condition set 2 [B][COLOR="blue"]if (Bars.BarsSinceSession == 7)[/COLOR][/B] if (Close[0] >= Open[0] + 4 * TickSize) { enterLongStrat2 = true; [B][COLOR="Red"]enterLongStrat1 = false;[/COLOR][/B] } // tally up if (Bars.BarsSinceSession == 10 && enterLongStrat1 == true && enterLongStrat2 == true) { EnterLong(DefaultQuantity, ""); }
Leave a comment:
-
Hello wallsteetking,
Thank you for your note.
I believe you are trying to check a condition on the first bar of the session and then a second condition in-between a specified number of bars. If this is correct, the reason it does not work is the that the two bools are reset to false on each bar update:
Code:protected override void OnBarUpdate() { enterLongStrat1 = false; enterLongStrat2 = false;
Leave a comment:
-
2 Conditions with different Bars.BarsSinceSession
Hey Ninjatrader team
How can I tell ninjatrader to allow two different conditions with different Bars.BarsSinceSession rules. to add more info I want to be able to create two booleans and have different Bars.BarsSinceSession inside the code. (for strategy)
This is what I have right now. please explain how/why this does not work and how to fix it.
Code:#region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 private bool enterLongStrat1 = false; private bool enterLongStrat2 = false; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { SetProfitTarget("", CalculationMode.Ticks, 4); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { enterLongStrat1 = false; enterLongStrat2 = false; // Condition set 1 [B][COLOR="Blue"] if (Bars.BarsSinceSession >=50) if (Bars.BarsSinceSession <=84)[/COLOR][/B] if (Close[0] >= EMA(20)[0] && Close[0] >= EMA(50)[0]) { // enterLongStrat2 = true; enterLongStrat1 = true; } // Condition set 2 [B][COLOR="Blue"]if (Bars.BarsSinceSession == 1)[/COLOR][/B] if (Close[0] >= Open[0] + 4 * TickSize) { enterLongStrat2 = true; // enterLongStrat1 = false; } if (enterLongStrat2 == true && enterLongStrat1 == true) { EnterLong(DefaultQuantity, ""); } }
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Perr0Grande, Today, 08:16 PM
|
0 responses
2 views
0 likes
|
Last Post
by Perr0Grande
Today, 08:16 PM
|
||
Started by elderan, Today, 08:03 PM
|
0 responses
5 views
0 likes
|
Last Post
by elderan
Today, 08:03 PM
|
||
Started by algospoke, Today, 06:40 PM
|
0 responses
10 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
12 views
0 likes
|
Last Post Today, 05:46 PM | ||
Started by quantismo, Today, 05:13 PM
|
0 responses
7 views
0 likes
|
Last Post
by quantismo
Today, 05:13 PM
|
Leave a comment: