64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Cbi;
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class IBSRSI : Strategy
|
|
{
|
|
private InternalBarStrength ibs;
|
|
private RSI rsi;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Name = "IBS + RSI";
|
|
Description = @"Mean reversion strategy based on the IBS and RSI indicators";
|
|
Calculate = Calculate.OnBarClose;
|
|
EntriesPerDirection = 1;
|
|
|
|
RSIPeriod = 21;
|
|
IBSThreshold = 0.25;
|
|
RSIThreshold = 45.0;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
ibs = InternalBarStrength();
|
|
rsi = RSI(RSIPeriod, 1);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < 21)
|
|
return;
|
|
|
|
if (ibs[0] < IBSThreshold && rsi[0] < RSIThreshold)
|
|
EnterLong();
|
|
|
|
if (Position.MarketPosition == MarketPosition.Long && Close[0] > Close[1])
|
|
ExitLong();
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "RSI Period", GroupName = "IBS + RSI", Order = 1)]
|
|
public int RSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "IBS Threshold", GroupName = "IBS + RSI", Order = 2)]
|
|
public double IBSThreshold { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "RSI Threshold", GroupName = "IBS + RSI", Order = 3)]
|
|
public double RSIThreshold { get; set; }
|
|
}
|
|
}
|