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;
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; }
}
}