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.
#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, ""); } }
Comment