From 1dc2ccad46bbb1b61678024d176e8c15165db954 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Tue, 10 Dec 2024 10:35:21 -0800 Subject: [PATCH] Initial commit of Triple RSI Drop strategy --- strategies/triple-rsi-drop/TripleRSIDrop.cs | 111 ++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 strategies/triple-rsi-drop/TripleRSIDrop.cs diff --git a/strategies/triple-rsi-drop/TripleRSIDrop.cs b/strategies/triple-rsi-drop/TripleRSIDrop.cs new file mode 100644 index 0000000..e410bbc --- /dev/null +++ b/strategies/triple-rsi-drop/TripleRSIDrop.cs @@ -0,0 +1,111 @@ +#region Using declarations +using NinjaTrader.Cbi; +using NinjaTrader.NinjaScript.Indicators; +using System; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class TripleRSIDrop : Strategy + { + private SMA longTermTrend; + private RSI rsi; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "Triple RSI Drop"; + Description = @"Similar to R3, credit to Larry Connors"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + LongTermTrendPeriod = 200; + RSIPeriod = 5; + RSISmoothing = 1; + ConsecutiveDays = 3; + FirstDayRSI = 60.0; + RSIEntry = 30.0; + RSIExit = 50.0; + } + else if (State == State.DataLoaded) + { + longTermTrend = SMA(LongTermTrendPeriod); + rsi = RSI(RSIPeriod, RSISmoothing); + + AddChartIndicator(longTermTrend); + AddChartIndicator(rsi); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < Math.Max(LongTermTrendPeriod, ConsecutiveDays)) + return; + + if (Close[0] > longTermTrend[0]) + { + if (RSIDrop(ConsecutiveDays) && rsi[ConsecutiveDays - 1] < FirstDayRSI && rsi[0] < RSIEntry) + EnterLong(); + } + + if (Position.MarketPosition == MarketPosition.Long && rsi[0] > RSIExit) + ExitLong(); + } + + private bool RSIDrop(int days) + { + for (int i = 0; i < days - 1; i++) + { + if (rsi[i] >= rsi[i + 1]) + return false; + } + return true; + } + + public override string DisplayName + { + get { return Name; } + } + + #region Properties + + [NinjaScriptProperty] + [Range(1, int.MaxValue)] + [Display(Name = "Long-Term Trend Period", GroupName = "Triple RSI Bot", Order = 1)] + public int LongTermTrendPeriod { get; set; } + + [NinjaScriptProperty] + [Range(1, int.MaxValue)] + [Display(Name = "RSI Period", GroupName = "Triple RSI Bot", Order = 2)] + public int RSIPeriod { get; set; } + + [NinjaScriptProperty] + [Range(1, int.MaxValue)] + [Display(Name = "RSI Smoothing", GroupName = "Triple RSI Bot", Order = 3)] + public int RSISmoothing { get; set; } + + [NinjaScriptProperty] + [Range(1, int.MaxValue)] + [Display(Name = "Consecutive Days", GroupName = "Triple RSI Bot", Order = 4)] + public int ConsecutiveDays { get; set; } + + [NinjaScriptProperty] + [Range(0.0, 100.0)] + [Display(Name = "First Day RSI", GroupName = "Triple RSI Bot", Order = 6)] + public double FirstDayRSI { get; set; } + + [NinjaScriptProperty] + [Range(0.0, 100.0)] + [Display(Name = "RSI Entry", GroupName = "Triple RSI Bot", Order = 7)] + public double RSIEntry { get; set; } + + [NinjaScriptProperty] + [Range(0.0, 100.0)] + [Display(Name = "RSI Exit", GroupName = "Triple RSI Bot", Order = 8)] + public double RSIExit { get; set; } + + #endregion + } +}