2024-11-09 13:34:48 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
|
|
{
|
|
|
|
public class ConnorsVIXReversal3 : Strategy
|
|
|
|
{
|
|
|
|
private const int PrimaryBars = 0;
|
|
|
|
private const int VIXBars = 1;
|
|
|
|
|
|
|
|
private SMA ShortTermTrend;
|
|
|
|
|
|
|
|
protected override void OnStateChange()
|
|
|
|
{
|
|
|
|
if (State == State.SetDefaults)
|
|
|
|
{
|
|
|
|
Name = "Connors VIX Reversal 3";
|
2024-11-19 03:34:20 +00:00
|
|
|
Description = @"Taken from Chapter 2 of Connors on Advanced Trading Strategies (1998) by Larry Connors";
|
2024-11-09 13:34:48 +00:00
|
|
|
Calculate = Calculate.OnBarClose;
|
|
|
|
EntriesPerDirection = 1;
|
|
|
|
|
2024-11-13 15:14:51 +00:00
|
|
|
ShortTermTrendPeriod = 50;
|
2024-11-09 13:34:48 +00:00
|
|
|
PercentAbove = 10;
|
|
|
|
}
|
|
|
|
else if (State == State.Configure)
|
|
|
|
{
|
|
|
|
AddDataSeries("^VIX");
|
|
|
|
}
|
|
|
|
else if (State == State.DataLoaded)
|
|
|
|
{
|
|
|
|
ShortTermTrend = SMA(Closes[VIXBars], ShortTermTrendPeriod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnBarUpdate()
|
|
|
|
{
|
|
|
|
if (PrimaryBars != BarsInProgress)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (CurrentBar < ShortTermTrendPeriod)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Lows[VIXBars][0] > ShortTermTrend[0] && Closes[VIXBars][0] >= ShortTermTrend[0] * (1 + PercentAbove / 100))
|
|
|
|
EnterLong();
|
|
|
|
|
2024-11-13 15:10:19 +00:00
|
|
|
if (Lows[VIXBars][0] < ShortTermTrend[1])
|
2024-11-09 13:34:48 +00:00
|
|
|
ExitLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string DisplayName
|
|
|
|
{
|
|
|
|
get { return Name; }
|
|
|
|
}
|
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Display(Name = "Short-Term Trend Period", GroupName = "Connors VIX Reversal 3 Bot", Order = 1)]
|
|
|
|
public int ShortTermTrendPeriod { get; set; }
|
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Display(Name = "Percent Above", GroupName = "Connors VIX Reversal 3 Bot", Order = 2)]
|
|
|
|
public double PercentAbove{ get; set; }
|
|
|
|
}
|
|
|
|
}
|