ninjatrader/strategies/internal-bar-strength-band/InternalBarStrengthBandBot.cs

70 lines
2.2 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
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 sma;
private Series<double> 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;
}
else if (State == State.DataLoaded)
{
highMinusLow = new Series<double>(this);
ibs = InternalBarStrength();
highestHigh = MAX(High, 10);
highMinusLowAverage = SMA(highMinusLow, 25);
sma = SMA(200); // Regime filter.
}
}
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] > sma[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; }
}
}