2024-11-16 14:28:29 +00:00
|
|
|
#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)
|
|
|
|
{
|
|
|
|
Description = @"Long only bot which bases trades on internal bar strength and lower band condition";
|
|
|
|
Name = "Internal Bar Strength Band 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;
|
|
|
|
|
|
|
|
LowerBandMultiplier = 2.5;
|
2024-11-16 14:42:34 +00:00
|
|
|
IBSEntryThreshold = 0.3;
|
2024-11-16 14:28:29 +00:00
|
|
|
}
|
|
|
|
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]);
|
2024-11-16 14:42:34 +00:00
|
|
|
if (Close[0] < lowerBand && ibs[0] < IBSEntryThreshold && Close[0] > sma[0])
|
2024-11-16 14:28:29 +00:00
|
|
|
EnterLong();
|
|
|
|
|
2024-11-16 14:42:34 +00:00
|
|
|
if (Close[0] > High[1])
|
2024-11-16 14:28:29 +00:00
|
|
|
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; }
|
2024-11-16 14:42:34 +00:00
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Display(Name = "IBS Entry Threshold", GroupName = "Internal Bar Strength Band Bot", Order = 2)]
|
|
|
|
public double IBSEntryThreshold { get; set; }
|
2024-11-16 14:28:29 +00:00
|
|
|
}
|
|
|
|
}
|