Initial commit of Short Term Highs strategy

This commit is contained in:
moshferatu 2024-10-08 07:43:30 -07:00
parent f0a82522ac
commit f2eb5b1302

View File

@ -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; }
}
}