From 6d76ec0e775bdb440f799854ca712ccc098b26f0 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Thu, 2 Jan 2025 08:58:34 -0800 Subject: [PATCH] Initial commit of 5-Period RSI strategy --- strategies/5-period-rsi/FivePeriodRSI.cs | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 strategies/5-period-rsi/FivePeriodRSI.cs diff --git a/strategies/5-period-rsi/FivePeriodRSI.cs b/strategies/5-period-rsi/FivePeriodRSI.cs new file mode 100644 index 0000000..e87d2fd --- /dev/null +++ b/strategies/5-period-rsi/FivePeriodRSI.cs @@ -0,0 +1,56 @@ +#region Using declarations +using NinjaTrader.Cbi; +using NinjaTrader.NinjaScript.Indicators; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class FivePeriodRSI : Strategy + { + private RSI rsi; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "5-Period RSI"; + Description = @"Simple strategy based on a 5-Period RSI"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + RSIPeriod = 5; + EntryThreshold = 35; + } + else if (State == State.DataLoaded) + { + rsi = RSI(RSIPeriod, 1); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < RSIPeriod) + return; + + if (rsi[0] < EntryThreshold) + EnterLong(); + + if (Position.MarketPosition == MarketPosition.Long && Close[0] > High[1]) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "RSI Period", GroupName = "5-Period RSI", Order = 1)] + public int RSIPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Entry Threshold", GroupName = "5-Period RSI", Order = 2)] + public int EntryThreshold { get; set; } + } +}