To: Qone0 who wrote (141 ) 4/16/2025 2:15:31 PM From: Qone0 Read Replies (1) | Respond to of 143 #region Using declarations using System; using NinjaTrader.Gui.Tools; using NinjaTrader.Cbi; using NinjaTrader.NinjaScript.Strategies; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class EnhancedESFuturesStrategy : Strategy { private EMA emaShort; private SMA smaLong; private RSI rsi; private ATR atr; private VWAP vwap; private double priorDayHigh; private double priorDayLow; private double priorDayClose; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enhanced ES futures day trading strategy with advanced indicators and risk management."; Name = "EnhancedESFuturesStrategy"; Calculate = Calculate.OnEachTick; IsUnmanaged = false; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; StopTargetHandling = StopTargetHandling.PerEntryExecution; Slippage = 1; TimeInForce = TimeInForce.Gtc; MinBarsRequired = 20; // Default Risk Management Parameters SetStopLoss(CalculationMode.Percent, 0.5); // Risk 0.5% of account equity SetProfitTarget(CalculationMode.Percent, 1.0); // Target 1% of account equity } else if (State == State.Configure) { // Add necessary indicators AddDataSeries(DataSeriesType.Minute, 5); emaShort = EMA(9); smaLong = SMA(50); rsi = RSI(14, 3); atr = ATR(14); // Average True Range for volatility analysis vwap = VWAP(); } else if (State == State.DataLoaded) { // Initialize prior day levels priorDayHigh = Highs[1][0]; priorDayLow = Lows[1][0]; priorDayClose = Closes[1][0]; } } protected override void OnBarUpdate() { if (CurrentBars[0] < MinBarsRequired) return; // Calculate market context bool isTrending = Math.Abs(emaShort[0] - smaLong[0]) > atr[0] * 0.5; bool isInRange = Close[0] > priorDayLow && Close[0] < priorDayHigh; // Trend-following strategy if (isTrending) { if (CrossAbove(emaShort, smaLong, 1) && rsi[0] < 70) { EnterLong(Convert.ToInt32(1000 / atr[0]), "TrendLong"); // Position size based on volatility } else if (CrossBelow(emaShort, smaLong, 1) && rsi[0] > 30) { EnterShort(Convert.ToInt32(1000 / atr[0]), "TrendShort"); } } // Range-bound strategy if (isInRange) { if (Close[0] <= priorDayLow && rsi[0] < 30) { EnterLong("RangeLong"); } else if (Close[0] >= priorDayHigh && rsi[0] > 70) { EnterShort("RangeShort"); } } // Manage Exits if (Position.MarketPosition == MarketPosition.Long) { if (Close[0] >= priorDayHigh || Close[0] < vwap[0]) { ExitLong("ExitLongVWAP"); } } else if (Position.MarketPosition == MarketPosition.Short) { if (Close[0] <= priorDayLow || Close[0] > vwap[0]) { ExitShort("ExitShortVWAP"); } } } } }