Initial commit of HILO Index Highs and HILO Index Lows strategies
This commit is contained in:
parent
5d5426e014
commit
5ddb96dccc
73
strategies/new-52-week-highs-and-lows/HILOIndexHighs.cs
Normal file
73
strategies/new-52-week-highs-and-lows/HILOIndexHighs.cs
Normal file
@ -0,0 +1,73 @@
|
||||
#region Using declarations
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
#endregion
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public class HILOIndexHighs : Strategy
|
||||
{
|
||||
private const int PrimaryBars = 0;
|
||||
|
||||
private HILOIndex HILO;
|
||||
private MAX HILOHighs;
|
||||
private SMA LongTermTrend;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Name = "HILO Index Highs";
|
||||
Description = @"Based on chatper 8 of How Markets Really Work (2012) by Larry Connors";
|
||||
Calculate = Calculate.OnBarClose;
|
||||
EntriesPerDirection = 1;
|
||||
|
||||
HighPeriod = 5;
|
||||
LongTermTrendPeriod = 200;
|
||||
DaysToExit = 5;
|
||||
}
|
||||
else if (State == State.Configure)
|
||||
{
|
||||
AddDataSeries("FINH");
|
||||
AddDataSeries("FINL");
|
||||
|
||||
BarsRequiredToTrade = HighPeriod;
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
{
|
||||
HILO = HILOIndex();
|
||||
HILOHighs = MAX(HILO, HighPeriod);
|
||||
LongTermTrend = SMA(LongTermTrendPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (PrimaryBars != BarsInProgress || CurrentBar < HighPeriod)
|
||||
return;
|
||||
|
||||
if (HILO[0] == HILOHighs[0] && Close[0] > LongTermTrend[0])
|
||||
EnterLong();
|
||||
|
||||
if (BarsSinceEntryExecution(PrimaryBars, "", 0) >= DaysToExit)
|
||||
ExitLong();
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return Name; }
|
||||
}
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "High Period", GroupName = "HILO Index Highs", Order = 1)]
|
||||
public int HighPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Long-Term Trend Period", GroupName = "HILO Index Highs", Order = 2)]
|
||||
public int LongTermTrendPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Days to Exit", GroupName = "HILO Index Highs", Order = 3)]
|
||||
public int DaysToExit { get; set; }
|
||||
}
|
||||
}
|
73
strategies/new-52-week-highs-and-lows/HILOIndexLows.cs
Normal file
73
strategies/new-52-week-highs-and-lows/HILOIndexLows.cs
Normal file
@ -0,0 +1,73 @@
|
||||
#region Using declarations
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
#endregion
|
||||
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public class HILOIndexLows : Strategy
|
||||
{
|
||||
private const int PrimaryBars = 0;
|
||||
|
||||
private HILOIndex HILO;
|
||||
private MIN HILOLows;
|
||||
private SMA LongTermTrend;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Name = "HILO Index Lows";
|
||||
Description = @"Based on chatper 8 of How Markets Really Work (2012) by Larry Connors";
|
||||
Calculate = Calculate.OnBarClose;
|
||||
EntriesPerDirection = 1;
|
||||
|
||||
LowPeriod = 5;
|
||||
LongTermTrendPeriod = 200;
|
||||
DaysToExit = 5;
|
||||
}
|
||||
else if (State == State.Configure)
|
||||
{
|
||||
AddDataSeries("FINH");
|
||||
AddDataSeries("FINL");
|
||||
|
||||
BarsRequiredToTrade = LowPeriod;
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
{
|
||||
HILO = HILOIndex();
|
||||
HILOLows = MIN(HILO, LowPeriod);
|
||||
LongTermTrend = SMA(LongTermTrendPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
if (PrimaryBars != BarsInProgress || CurrentBar < LowPeriod)
|
||||
return;
|
||||
|
||||
if (HILO[0] == HILOLows[0] && Close[0] > LongTermTrend[0])
|
||||
EnterLong();
|
||||
|
||||
if (BarsSinceEntryExecution(PrimaryBars, "", 0) >= DaysToExit)
|
||||
ExitLong();
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get { return Name; }
|
||||
}
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Low Period", GroupName = "HILO Index Lows", Order = 1)]
|
||||
public int LowPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Long-Term Trend Period", GroupName = "HILO Index Lows", Order = 2)]
|
||||
public int LongTermTrendPeriod { get; set; }
|
||||
|
||||
[NinjaScriptProperty]
|
||||
[Display(Name = "Days to Exit", GroupName = "HILO Index Lows", Order = 3)]
|
||||
public int DaysToExit { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user