71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
#region Using declarations
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class ConnorsVIXReversal2 : Strategy
|
|
{
|
|
private const int PrimaryBars = 0;
|
|
private const int VIXBars = 1;
|
|
|
|
private RSI VIXRSI;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Name = "Connors VIX Reversal 2";
|
|
Description = @"Take from Chapter 2 of Connors on Advanced Trading Strategies (1998) by Larry Connors";
|
|
Calculate = Calculate.OnBarClose;
|
|
EntriesPerDirection = 1;
|
|
|
|
RSIPeriod = 5;
|
|
OverboughtLevel = 70;
|
|
DaysToExit = 3;
|
|
}
|
|
else if (State == State.Configure)
|
|
{
|
|
AddDataSeries("^VIX");
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
VIXRSI = RSI(Closes[VIXBars], RSIPeriod, 1);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (PrimaryBars != BarsInProgress)
|
|
return;
|
|
|
|
if (CurrentBar < RSIPeriod)
|
|
return;
|
|
|
|
if (VIXRSI[1] > OverboughtLevel && VIXRSI[0] < VIXRSI[1])
|
|
EnterLong();
|
|
|
|
if (BarsSinceEntryExecution(PrimaryBars, "", 0) >= DaysToExit)
|
|
ExitLong();
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "RSI Period", GroupName = "Connors VIX Reversal RSI Bot", Order = 1)]
|
|
public int RSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Overbought Level", GroupName = "Connors VIX Reversal RSI Bot", Order = 2)]
|
|
public int OverboughtLevel { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Days to Exit", GroupName = "Connors VIX Reversal RSI Bot", Order = 3)]
|
|
public int DaysToExit { get; set; }
|
|
}
|
|
}
|