ninjatrader/strategies/5-period-rsi/FivePeriodRSI.cs

57 lines
1.5 KiB
C#

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