58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
|
#region Using declarations
|
||
|
using NinjaTrader.NinjaScript.Indicators;
|
||
|
using System;
|
||
|
using System.ComponentModel.DataAnnotations;
|
||
|
#endregion
|
||
|
|
||
|
namespace NinjaTrader.NinjaScript.Strategies
|
||
|
{
|
||
|
public class VXXTrendBot : Strategy
|
||
|
{
|
||
|
private SMA shortTermTrend;
|
||
|
private SMA longTermTrend;
|
||
|
|
||
|
protected override void OnStateChange()
|
||
|
{
|
||
|
if (State == State.SetDefaults)
|
||
|
{
|
||
|
Name = "VXX Trend Bot";
|
||
|
Description = @"Taken from chapter 6 of Buy the Fear, Sell the Greed (2018) by Larry Connors";
|
||
|
Calculate = Calculate.OnBarClose;
|
||
|
EntriesPerDirection = 1;
|
||
|
|
||
|
ShortTermTrendPeriod = 10;
|
||
|
LongTermTrendPeriod = 30;
|
||
|
}
|
||
|
else if (State == State.DataLoaded)
|
||
|
{
|
||
|
shortTermTrend = SMA(ShortTermTrendPeriod);
|
||
|
longTermTrend = SMA(LongTermTrendPeriod);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected override void OnBarUpdate()
|
||
|
{
|
||
|
if (CurrentBar < Math.Max(ShortTermTrendPeriod, LongTermTrendPeriod))
|
||
|
return;
|
||
|
|
||
|
if (CrossBelow(shortTermTrend, longTermTrend, 1))
|
||
|
EnterShort();
|
||
|
|
||
|
if (CrossAbove(shortTermTrend, longTermTrend, 1))
|
||
|
ExitShort();
|
||
|
}
|
||
|
|
||
|
#region Properties
|
||
|
|
||
|
[NinjaScriptProperty]
|
||
|
[Display(Name = "Short-Term Trend Period", GroupName = "VXX Trend Bot", Order = 1)]
|
||
|
public int ShortTermTrendPeriod { get; set; }
|
||
|
|
||
|
[NinjaScriptProperty]
|
||
|
[Display(Name = "Long-Term Trend Period", GroupName = "VXX Trend Bot", Order = 2)]
|
||
|
public int LongTermTrendPeriod { get; set; }
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|