78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
#region Using declarations
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class TradingNewHighs : Strategy
|
|
{
|
|
private const int FiftyTwoWeeksInDays = 252;
|
|
|
|
private ConnorsRSI connorsRSI;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Name = "Trading New Highs";
|
|
Description = @"Taken from chapter 7 of Buy the Fear, Sell the Greed (2018) by Larry Connors";
|
|
Calculate = Calculate.OnBarClose;
|
|
EntriesPerDirection = 1;
|
|
|
|
MaxDaysSinceHigh = 20;
|
|
RSIPeriod = 3;
|
|
StreakRSIPeriod = 2;
|
|
PercentRankPeriod = 100;
|
|
EntryThreshold = 15;
|
|
ExitThreshold = 70;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
connorsRSI = ConnorsRSI(RSIPeriod, StreakRSIPeriod, PercentRankPeriod);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < FiftyTwoWeeksInDays)
|
|
return;
|
|
|
|
int barsAgo52WeekHigh = HighestBar(Highs[0], FiftyTwoWeeksInDays);
|
|
if (barsAgo52WeekHigh <= MaxDaysSinceHigh && connorsRSI[0] < EntryThreshold)
|
|
EnterLong();
|
|
else if (connorsRSI[0] > ExitThreshold)
|
|
ExitLong();
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Max Days Since High", GroupName = "Trading New Highs", Order = 1)]
|
|
public double MaxDaysSinceHigh { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "RSI Period", GroupName = "Trading New Highs", Order = 2)]
|
|
public int RSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Streak RSI Period", GroupName = "Trading New Highs", Order = 3)]
|
|
public int StreakRSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Percent Rank Period", GroupName = "Trading New Highs", Order = 4)]
|
|
public int PercentRankPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "ConnorsRSI Entry Threshold", GroupName = "Trading New Highs", Order = 5)]
|
|
public double EntryThreshold { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "ConnorsRSI Exit Threshold", GroupName = "Trading New Highs", Order = 6)]
|
|
public double ExitThreshold { get; set; }
|
|
}
|
|
}
|