Add a configuration setting to only allow long trades to 2-Period RSI strategy

This commit is contained in:
moshferatu 2024-09-09 08:41:45 -07:00
parent fce0a9dd38
commit 533fd9383d

View File

@ -43,6 +43,7 @@ namespace NinjaTrader.NinjaScript.Strategies
ShortTermTrendPeriod = 5; ShortTermTrendPeriod = 5;
UseFixedPositionSizing = false; UseFixedPositionSizing = false;
FixedPositionSize = 10000; FixedPositionSize = 10000;
LongOnly = false;
} }
else if (State == State.DataLoaded) else if (State == State.DataLoaded)
{ {
@ -68,7 +69,7 @@ namespace NinjaTrader.NinjaScript.Strategies
if (Position.MarketPosition != MarketPosition.Long) if (Position.MarketPosition != MarketPosition.Long)
EnterLong(quantity); 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) if (Position.MarketPosition != MarketPosition.Short)
EnterShort(quantity); EnterShort(quantity);
@ -116,5 +117,9 @@ namespace NinjaTrader.NinjaScript.Strategies
[NinjaScriptProperty] [NinjaScriptProperty]
[Display(Name = "Fixed Position Size", GroupName = "2 Period RSI", Order = 8)] [Display(Name = "Fixed Position Size", GroupName = "2 Period RSI", Order = 8)]
public int FixedPositionSize { get; set; } public int FixedPositionSize { get; set; }
[NinjaScriptProperty]
[Display(Name = "Long Only", GroupName = "2 Period RSI", Order = 9)]
public bool LongOnly { get; set; }
} }
} }