63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
#region Using declarations
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class HighVolumeUpDays : Strategy
|
|
{
|
|
private MAX HighestVolume;
|
|
private SMA LongTermTrend;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Name = "High Volume Up 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 Up Days", Order = 1)]
|
|
public int HighVolumePeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Long-Term Trend Period", GroupName = "High Volume Up Days", Order = 2)]
|
|
public int LongTermTrendPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Days to Exit", GroupName = "High Volume Up Days", Order = 3)]
|
|
public int DaysToExit { get; set; }
|
|
}
|
|
}
|