From fea73a7f89d07abc6fedcbe67bb6dfc7e6c0b754 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Fri, 5 Jul 2024 07:53:44 -0700 Subject: [PATCH] Add Nasdaq cumulative 52 week new highs new lows strategy --- .../NasdaqNewHighsNewLowsBot.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 strategies/new-highs-new-lows/NasdaqNewHighsNewLowsBot.cs diff --git a/strategies/new-highs-new-lows/NasdaqNewHighsNewLowsBot.cs b/strategies/new-highs-new-lows/NasdaqNewHighsNewLowsBot.cs new file mode 100644 index 0000000..651400a --- /dev/null +++ b/strategies/new-highs-new-lows/NasdaqNewHighsNewLowsBot.cs @@ -0,0 +1,64 @@ +#region Using declarations +using NinjaTrader.Cbi; +using NinjaTrader.Data; +using NinjaTrader.NinjaScript.Indicators; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class NasdaqNewHighsNewLowsBot : Strategy + { + private NasdaqCumulativeNewHighsNewLows newHighsNewLows; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Description = @"Strategy based on Nasdaq Cumulative New Highs New Lows"; + Name = "Nasdaq New Highs New Lows Bot"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + EntryHandling = EntryHandling.AllEntries; + IsExitOnSessionCloseStrategy = false; + ExitOnSessionCloseSeconds = 30; + IsFillLimitOnTouch = false; + MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; + OrderFillResolution = OrderFillResolution.Standard; + Slippage = 0; + StartBehavior = StartBehavior.WaitUntilFlat; + TimeInForce = TimeInForce.Gtc; + TraceOrders = false; + RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; + StopTargetHandling = StopTargetHandling.PerEntryExecution; + BarsRequiredToTrade = 20; + IsInstantiatedOnEachOptimizationIteration = true; + } + else if (State == State.Configure) + { + AddDataSeries("FIQH", BarsPeriodType.Day, 1); + AddDataSeries("FIQL", BarsPeriodType.Day, 1); + } + else if (State == State.DataLoaded) + { + newHighsNewLows = NasdaqCumulativeNewHighsNewLows(); + } + } + + protected override void OnBarUpdate() + { + if (BarsInProgress != 0) + return; + + if (newHighsNewLows[0] > 0) + EnterLong(); + + if (Position.MarketPosition == MarketPosition.Long && newHighsNewLows[0] < 0) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + } +}