Thesis is simple, You take High and Low of 4PM Candle and once we get a 2Min candle close above or below the 4PM Candle, it should enter.
Would appreciate any help to fix this issue!
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class MyStrategy : Strategy { private bool tradeExecuted = false; protected override void OnBarUpdate() { // Check if it's the last bar and 4 PM EST if (Bars.Count > 0 && CurrentBar == Bars.Count - 1 && Time[0].Hour == 16 && Time[0].Minute == 0) { // Get the high and low of the 2-minute candle at 4 PM EST double high = Highs[1][0]; double low = Lows[1][0]; // Calculate stop loss and take profit levels double stopLoss = low - 10 * TickSize; double takeProfit = high + 10 * TickSize; // Check if the closing price is below the low of the 4 PM candle if (Close[0] < low && !tradeExecuted) { // Go short with stop loss and take profit EnterShort(); SetStopLoss(CalculationMode.Price, stopLoss); SetProfitTarget(CalculationMode.Price, takeProfit); tradeExecuted = true; } // Check if the closing price is above the high of the 4 PM candle else if (Close[0] > high && !tradeExecuted) { // Go long with stop loss and take profit EnterLong(); SetStopLoss(CalculationMode.Price, stopLoss); SetProfitTarget(CalculationMode.Price, takeProfit); tradeExecuted = true; } } else { tradeExecuted = false; } } } }
Comment