namespace NinjaTrader.NinjaScript.Strategies
{
public class Short15MinBO : Strategy
{
private bool ShortFirst;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Short15MinBO";
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;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
ShortFirst = false;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15);
SetProfitTarget(@"", CalculationMode.Ticks, 60);
SetStopLoss("", CalculationMode.Ticks, 40, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1
|| CurrentBars[1] < 1)
return;
// Set 1
if ((Times[0][0].TimeOfDay >= new TimeSpan(6, 30, 0))
&& (Times[0][0].TimeOfDay < new TimeSpan(6, 35, 0))
&& (ShortFirst == false))
{
ShortFirst = true;
EnterShortMIT(Convert.ToInt32(DefaultQuantity), Lows[1][0], "");
}
// Set 2
if (Bars.IsFirstBarOfSession == true)
{
ShortFirst = false;
}
}
}
}
Thank you in advance for your help!

Comment