From 908be34febf71c8ecfe1e48dbff1a6a6955cd7b6 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 30 Oct 2024 10:10:32 -0700 Subject: [PATCH] Initial commit of Up Days in a Row strategy --- .../up-and-down-days-in-a-row/UpDaysInARow.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 strategies/up-and-down-days-in-a-row/UpDaysInARow.cs diff --git a/strategies/up-and-down-days-in-a-row/UpDaysInARow.cs b/strategies/up-and-down-days-in-a-row/UpDaysInARow.cs new file mode 100644 index 0000000..1854a7a --- /dev/null +++ b/strategies/up-and-down-days-in-a-row/UpDaysInARow.cs @@ -0,0 +1,55 @@ +#region Using declarations +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class UpDaysInARow : Strategy + { + private int upDayStreak; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "Up Days in a Row"; + Description = @"Based on chatper 4 of How Markets Really Work (2012) by Larry Connors"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + DaysInARow = 3; + DaysToExit = 5; + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < DaysInARow) + return; + + if (Close[0] > Close[1]) + upDayStreak++; + else + upDayStreak = 0; + + if (upDayStreak >= DaysInARow) + EnterLong(); + + if (BarsSinceEntryExecution() >= DaysToExit) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "Days in a Row", GroupName = "Up Days in a Row", Order = 1)] + public int DaysInARow { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Days to Exit", GroupName = "Up Days in a Row", Order = 2)] + public int DaysToExit { get; set; } + } +}