ninjatrader/strategies/new-highs-new-lows/NasdaqNewHighsNewLowsBot.cs

65 lines
2.2 KiB
C#

#region Using declarations
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript.Indicators;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class NasdaqNewHighsNewLowsBot : Strategy
{
private NasdaqCumulativeNewHighsNewLows newHighsNewLows;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Strategy based on Nasdaq Cumulative New Highs New Lows";
Name = "Nasdaq New Highs New Lows Bot";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = false;
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;
}
else if (State == State.Configure)
{
AddDataSeries("FIQH", BarsPeriodType.Day, 1);
AddDataSeries("FIQL", BarsPeriodType.Day, 1);
}
else if (State == State.DataLoaded)
{
newHighsNewLows = NasdaqCumulativeNewHighsNewLows();
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (newHighsNewLows[0] > 0)
EnterLong();
if (Position.MarketPosition == MarketPosition.Long && newHighsNewLows[0] < 0)
ExitLong();
}
public override string DisplayName
{
get { return Name; }
}
}
}