Initial commit of 5-Period RSI strategy
This commit is contained in:
parent
58bb4634ab
commit
6d76ec0e77
56
strategies/5-period-rsi/FivePeriodRSI.cs
Normal file
56
strategies/5-period-rsi/FivePeriodRSI.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user