From 8445774d7c2fc21ba97d957c332c11b21b356925 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 20 Aug 2024 06:06:20 -0700 Subject: [PATCH] Initial commit of Monthly Momentum Bot --- strategies/MonthlyMomentumBot.cs | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 strategies/MonthlyMomentumBot.cs diff --git a/strategies/MonthlyMomentumBot.cs b/strategies/MonthlyMomentumBot.cs new file mode 100644 index 0000000..7fa78dc --- /dev/null +++ b/strategies/MonthlyMomentumBot.cs @@ -0,0 +1,60 @@ +#region Using declarations +using System.ComponentModel.DataAnnotations; +using NinjaTrader.Cbi; +using NinjaTrader.NinjaScript.Indicators; +#endregion + +// This strategy is intended to be run on a monthly chart. +namespace NinjaTrader.NinjaScript.Strategies +{ + public class MonthlyMomentumBot : Strategy + { + private SMA sma; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Description = @""; + Name = "Monthly Momentum Bot"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + EntryHandling = EntryHandling.AllEntries; + IsExitOnSessionCloseStrategy = true; + 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; + + SMAPeriod = 12; + } + else if (State == State.DataLoaded) + { + sma = SMA(SMAPeriod); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < SMAPeriod) + return; + + if (CrossAbove(Close, sma, 1)) + EnterLong(); + else if (CrossBelow(Close, sma, 1)) + ExitLong(); + } + + [NinjaScriptProperty] + [Display(Name = "SMA Period", GroupName = "Monthly Momentum Bot", Order = 1)] + public int SMAPeriod { get; set; } + } +}