#region Using declarations using NinjaTrader.NinjaScript.Indicators; using System.ComponentModel.DataAnnotations; #endregion namespace NinjaTrader.NinjaScript.Strategies { public class InternalBarStrengthBandBot : Strategy { private InternalBarStrength ibs; private MAX highestHigh; private SMA highMinusLowAverage; private SMA longTermTrend; private Series highMinusLow; protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "Internal Bar Strength Band Bot"; Description = @"Long only bot which bases trades on internal bar strength and lower band condition"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; LowerBandMultiplier = 2.5; IBSEntryThreshold = 0.3; RollingHighPeriod = 10; HighMinusLowPeriod = 25; LongTermTrendPeriod = 200; } else if (State == State.DataLoaded) { highMinusLow = new Series(this); ibs = InternalBarStrength(); highestHigh = MAX(High, RollingHighPeriod); highMinusLowAverage = SMA(highMinusLow, HighMinusLowPeriod); longTermTrend = SMA(LongTermTrendPeriod); } } protected override void OnBarUpdate() { highMinusLow[0] = High[0] - Low[0]; if (CurrentBar < BarsRequiredToTrade) return; double lowerBand = highestHigh[0] - (LowerBandMultiplier * highMinusLowAverage[0]); if (Close[0] < lowerBand && ibs[0] < IBSEntryThreshold && Close[0] > longTermTrend[0]) EnterLong(); if (Close[0] > High[1]) ExitLong(); } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [Display(Name = "Lower Band Multiplier", GroupName = "Internal Bar Strength Band Bot", Order = 1)] public double LowerBandMultiplier { get; set; } [NinjaScriptProperty] [Display(Name = "IBS Entry Threshold", GroupName = "Internal Bar Strength Band Bot", Order = 2)] public double IBSEntryThreshold { get; set; } [NinjaScriptProperty] [Display(Name = "Rolling High Period", GroupName = "Internal Bar Strength Band Bot", Order = 3)] public int RollingHighPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "High Minus Low Period", GroupName = "Internal Bar Strength Band Bot", Order = 4)] public int HighMinusLowPeriod { get; set; } [NinjaScriptProperty] [Display(Name = "Long-Term Trend Period", GroupName = "Internal Bar Strength Band Bot", Order = 5)] public int LongTermTrendPeriod { get; set; } } }