I have been trying for 15 days that not to cancel my EnterLongLimit at the end of the first candle. I tried it anyway
What is wrong here? I would appreciate some help
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class diau : Strategy
{
private double Target;
private Order myEntryOrder = null;
private int barNumberOfOrder = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "diau";
Calculate = Calculate.OnEachTick;
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;
Target = 0;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Close[1] > Open[1])
&& (myEntryOrder == null))
{
Target = (Low[1] + (-30 * TickSize)) ;
myEntryOrder = EnterLongLimit(Convert.ToInt32(DefaultQuantity), Target, "hello");
barNumberOfOrder = CurrentBar;
}
if (myEntryOrder != null && CurrentBar > barNumberOfOrder + 5 && myEntryOrder.OrderState == OrderState.Working)
{
CancelOrder(myEntryOrder);
myEntryOrder = null;
}
}
}
}
Comment