From 67dc7ee765ea093893c55485f50f46a9020bf195 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Mon, 18 Nov 2024 08:27:44 -0800 Subject: [PATCH] Initial commit of High Volume Down Days strategy --- .../high-volume-days/HighVolumeDownDays.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 strategies/high-volume-days/HighVolumeDownDays.cs diff --git a/strategies/high-volume-days/HighVolumeDownDays.cs b/strategies/high-volume-days/HighVolumeDownDays.cs new file mode 100644 index 0000000..3ab99a9 --- /dev/null +++ b/strategies/high-volume-days/HighVolumeDownDays.cs @@ -0,0 +1,62 @@ +#region Using declarations +using NinjaTrader.NinjaScript.Indicators; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class HighVolumeDownDays : Strategy + { + private MAX HighestVolume; + private SMA LongTermTrend; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "High Volume Down Days"; + Description = @"Based on chatper 6 of How Markets Really Work (2012) by Larry Connors"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + HighVolumePeriod = 5; + LongTermTrendPeriod = 200; + DaysToExit = 5; + } + else if (State == State.DataLoaded) + { + HighestVolume = MAX(Volume, HighVolumePeriod); + LongTermTrend = SMA(LongTermTrendPeriod); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < HighVolumePeriod) + return; + + if (Volume[0] == HighestVolume[0] && Close[0] > LongTermTrend[0] && Close[0] < Open[0]) + EnterLong(); + + if (BarsSinceEntryExecution() >= DaysToExit) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "High Volume Period", GroupName = "High Volume Down Days", Order = 1)] + public int HighVolumePeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Long-Term Trend Period", GroupName = "High Volume Down Days", Order = 2)] + public int LongTermTrendPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Days to Exit", GroupName = "High Volume Down Days", Order = 3)] + public int DaysToExit { get; set; } + } +}