diff --git a/strategies/short-term-highs-and-lows/ShortTermHighs.cs b/strategies/short-term-highs-and-lows/ShortTermHighs.cs new file mode 100644 index 0000000..56a8118 --- /dev/null +++ b/strategies/short-term-highs-and-lows/ShortTermHighs.cs @@ -0,0 +1,57 @@ +#region Using declarations +using NinjaTrader.NinjaScript.Indicators; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class ShortTermHighs : Strategy + { + private MAX shortTermHighs; + private SMA longTermTrend; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "Short-Term Highs"; + Description = @"Based on chatper 2 of How Markets Really Work (2012) by Larry Connors"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + HighPeriod = 10; + LongTermTrendPeriod = 200; + } + else if (State == State.DataLoaded) + { + shortTermHighs = MAX(High, HighPeriod); + longTermTrend = SMA(LongTermTrendPeriod); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < HighPeriod) + return; + + if (High[0] == shortTermHighs[0]) + EnterLong(); + + if (BarsSinceEntryExecution() >= 5) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "High Period", GroupName = "Short-Term Highs", Order = 1)] + public int HighPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Long-Term Trend Period", GroupName = "Short-Term Highs", Order = 2)] + public int LongTermTrendPeriod { get; set; } + } +}