ninjatrader/strategies/higher-highs-and-lower-lows/HigherHighs.cs

63 lines
1.7 KiB
C#

#region Using declarations
using System.ComponentModel.DataAnnotations;
using NinjaTrader.NinjaScript.Indicators;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class HigherHighs : Strategy
{
private SMA longTermTrend;
private int higherHighStreak;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "Higher Highs";
Description = @"Based on chatper 3 of How Markets Really Work (2012) by Larry Connors";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
ConsecutiveHigherHighs = 3;
LongTermTrendPeriod = 200;
}
else if (State == State.DataLoaded)
{
longTermTrend = SMA(LongTermTrendPeriod);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < ConsecutiveHigherHighs)
return;
if (High[0] > High[1])
higherHighStreak++;
else
higherHighStreak = 0;
if (higherHighStreak >= ConsecutiveHigherHighs)
EnterLong();
if (BarsSinceEntryExecution() >= 5)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
[NinjaScriptProperty]
[Display(Name = "Consecutive Higher Highs", GroupName = "Higher Highs", Order = 1)]
public int ConsecutiveHigherHighs { get; set; }
[NinjaScriptProperty]
[Display(Name = "Long-Term Trend Period", GroupName = "Higher Highs", Order = 2)]
public int LongTermTrendPeriod { get; set; }
}
}