From c62c3b75000556acf68b7c6301cbfd38872812d8 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Mon, 25 Nov 2024 09:09:10 -0800 Subject: [PATCH] Initial commit of IBS + RSI strategy --- strategies/ibs-rsi/IBSRSI.cs | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 strategies/ibs-rsi/IBSRSI.cs diff --git a/strategies/ibs-rsi/IBSRSI.cs b/strategies/ibs-rsi/IBSRSI.cs new file mode 100644 index 0000000..e3f8f96 --- /dev/null +++ b/strategies/ibs-rsi/IBSRSI.cs @@ -0,0 +1,63 @@ +#region Using declarations +using NinjaTrader.Cbi; +using NinjaTrader.NinjaScript.Indicators; +using System.ComponentModel.DataAnnotations; +#endregion + +namespace NinjaTrader.NinjaScript.Strategies +{ + public class IBSRSI : Strategy + { + private InternalBarStrength ibs; + private RSI rsi; + + protected override void OnStateChange() + { + if (State == State.SetDefaults) + { + Name = "IBS + RSI"; + Description = @"Mean reversion strategy based on the IBS and RSI indicators"; + Calculate = Calculate.OnBarClose; + EntriesPerDirection = 1; + + RSIPeriod = 21; + IBSThreshold = 0.25; + RSIThreshold = 45.0; + } + else if (State == State.DataLoaded) + { + ibs = InternalBarStrength(); + rsi = RSI(RSIPeriod, 1); + } + } + + protected override void OnBarUpdate() + { + if (CurrentBar < 21) + return; + + if (ibs[0] < IBSThreshold && rsi[0] < RSIThreshold) + EnterLong(); + + if (Position.MarketPosition == MarketPosition.Long && Close[0] > Close[1]) + ExitLong(); + } + + public override string DisplayName + { + get { return Name; } + } + + [NinjaScriptProperty] + [Display(Name = "RSI Period", GroupName = "IBS + RSI", Order = 1)] + public int RSIPeriod { get; set; } + + [NinjaScriptProperty] + [Display(Name = "IBS Threshold", GroupName = "IBS + RSI", Order = 2)] + public double IBSThreshold { get; set; } + + [NinjaScriptProperty] + [Display(Name = "RSI Threshold", GroupName = "IBS + RSI", Order = 3)] + public double RSIThreshold { get; set; } + } +}