ninjatrader/strategies/vxx-trend/VXXTrendBot.cs

63 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-10-06 13:21:58 +00:00
#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;
2024-10-06 13:21:58 +00:00
private SMA longTermTrend;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
2024-10-06 13:21:58 +00:00
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)
{
2024-10-06 13:21:58 +00:00
shortTermTrend = SMA(ShortTermTrendPeriod);
longTermTrend = SMA(LongTermTrendPeriod);
}
}
2024-10-06 13:21:58 +00:00
protected override void OnBarUpdate()
{
2024-10-06 13:21:58 +00:00
if (CurrentBar < Math.Max(ShortTermTrendPeriod, LongTermTrendPeriod))
return;
if (CrossBelow(shortTermTrend, longTermTrend, 1))
EnterShort();
if (CrossAbove(shortTermTrend, longTermTrend, 1))
ExitShort();
}
public override string DisplayName
{
get { return Name; }
}
2024-10-06 13:21:58 +00:00
#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
}
}