From 533fd9383d9763f14ff31a961b1de1c63c85f0a1 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Mon, 9 Sep 2024 08:41:45 -0700 Subject: [PATCH] Add a configuration setting to only allow long trades to 2-Period RSI strategy --- strategies/2-period-rsi/TwoPeriodRSI.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/strategies/2-period-rsi/TwoPeriodRSI.cs b/strategies/2-period-rsi/TwoPeriodRSI.cs index f8d9332..ed1a062 100644 --- a/strategies/2-period-rsi/TwoPeriodRSI.cs +++ b/strategies/2-period-rsi/TwoPeriodRSI.cs @@ -43,6 +43,7 @@ namespace NinjaTrader.NinjaScript.Strategies ShortTermTrendPeriod = 5; UseFixedPositionSizing = false; FixedPositionSize = 10000; + LongOnly = false; } else if (State == State.DataLoaded) { @@ -68,7 +69,7 @@ namespace NinjaTrader.NinjaScript.Strategies if (Position.MarketPosition != MarketPosition.Long) EnterLong(quantity); } - else if (Close[0] < longTermTrend[0] && rsi[0] > ShortEntryThreshold) + else if (Close[0] < longTermTrend[0] && rsi[0] > ShortEntryThreshold && !LongOnly) { if (Position.MarketPosition != MarketPosition.Short) EnterShort(quantity); @@ -116,5 +117,9 @@ namespace NinjaTrader.NinjaScript.Strategies [NinjaScriptProperty] [Display(Name = "Fixed Position Size", GroupName = "2 Period RSI", Order = 8)] public int FixedPositionSize { get; set; } + + [NinjaScriptProperty] + [Display(Name = "Long Only", GroupName = "2 Period RSI", Order = 9)] + public bool LongOnly { get; set; } } }