I am trying to program/back test a simple strat that enters at the exact time twice a day. I am using the builder and the issue I am running into is that It enters time after time again. I want to enter at 2 different times with 2 different entries and then after those are done it waits until the next time slot, here is the code below I am sure its a simple fix but I cannot figure it out and after trying multiple times I figured I'd ask for a little help. Any suggestions/fixes would be great thank you
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Buyclosesellopen : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"everynight the system will buy the close of the previous day and sell the open at the rth open ";
Name = "Buyclosesellopen";
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;
Close = DateTime.Parse("16:30", System.Globalization.CultureInfo.InvariantCulture) ;
Open = DateTime.Parse("09:30", System.Globalization.CultureInfo.InvariantCulture) ;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 1);
SetProfitTarget("", CalculationMode.Ticks, 40);
SetStopLoss("", CalculationMode.Ticks, 40, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (new TimeSpan(16, 45, 0) == Close.TimeOfDay)
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"");
}
// Set 2
if (new TimeSpan(9, 30, 0) == Open.TimeOfDay)
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
}
#region Properties
[NinjaScriptProperty]
[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
[Display(Name="Close", Description="buy", Order=1, GroupName="Parameters")]
public DateTime Close
{ get; set; }
[NinjaScriptProperty]
[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKe y")]
[Display(Name="Open", Description="sell", Order=2, GroupName="Parameters")]
public DateTime Open
{ get; set; }
#endregion
}
}
Comment