91 lines
3.2 KiB
C#
91 lines
3.2 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Cbi;
|
|
using NinjaTrader.NinjaScript.Indicators;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public class RSITwentyFiveBot : Strategy
|
|
{
|
|
private SMA longTermTrend;
|
|
private RSI rsi;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Taken from chapter 3 of High Probability ETF Trading (2009) by Larry Connors";
|
|
Name = "RSI 25 / 75 Bot";
|
|
Calculate = Calculate.OnBarClose;
|
|
EntriesPerDirection = 1;
|
|
EntryHandling = EntryHandling.AllEntries;
|
|
IsExitOnSessionCloseStrategy = true;
|
|
ExitOnSessionCloseSeconds = 30;
|
|
IsFillLimitOnTouch = false;
|
|
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
|
|
OrderFillResolution = OrderFillResolution.Standard;
|
|
Slippage = 0;
|
|
StartBehavior = StartBehavior.WaitUntilFlat;
|
|
TimeInForce = TimeInForce.Gtc;
|
|
TraceOrders = false;
|
|
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
|
|
StopTargetHandling = StopTargetHandling.PerEntryExecution;
|
|
BarsRequiredToTrade = 20;
|
|
IsInstantiatedOnEachOptimizationIteration = true;
|
|
|
|
LongTermTrendPeriod = 200;
|
|
RSIPeriod = 4;
|
|
RSISmoothing = 1;
|
|
EnableLongTrades = true;
|
|
EnableShortTrades = true;
|
|
EnableAggressiveEntries = true;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
longTermTrend = SMA(LongTermTrendPeriod);
|
|
rsi = RSI(RSIPeriod, RSISmoothing);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < Math.Max(LongTermTrendPeriod, RSIPeriod))
|
|
return;
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "Long-Term Trend Period", GroupName = "RSI 25 / 75 Bot", Order = 1)]
|
|
public int LongTermTrendPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "RSI Period", GroupName = "RSI 25 / 75 Bot", Order = 2)]
|
|
public int RSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "RSI Smoothing", GroupName = "RSI 25 / 75 Bot", Order = 3)]
|
|
public int RSISmoothing { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Enable Long Trades", GroupName = "RSI 25 / 75 Bot", Order = 4)]
|
|
public bool EnableLongTrades { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Enable Short Trades", GroupName = "RSI 25 / 75 Bot", Order = 5)]
|
|
public bool EnableShortTrades { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Display(Name = "Enable Aggressive Entries", GroupName = "RSI 25 / 75 Bot", Order = 6)]
|
|
public bool EnableAggressiveEntries { get; set; }
|
|
}
|
|
}
|