My purpose is to enter Long or Short 1 contract each 2 times for multiple profit target. My strategy is being detected and no problem getting into positions with 2 contracts. My backtest data position and profit taking/ stop loss seems fine. The problem is when I run it live on the simulation, it correctly sends out 4 orders, 2 profit takers and 2 stop loss but it end up being canceled just a few bars either up or down the trade without any execution all 4 OCO orders are canceled leaving me with an full open position and no orders. Below is a snippet of my strategy regarding the orders.
namespace NinjaTrader.NinjaScript.Strategies
{
public class teststrategy : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "DarvasBothT2";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
EntryHandling = EntryHandling.UniqueEntries;
DaysToLoad = 3;
IncludeCommission = true;
IsInstantiatedOnEachOptimizationIteration = true;
dRange = 20;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
list of AddChartIndicators
SetProfitTarget("Short1", CalculationMode.Ticks, dRange/2);
SetTrailStop("Short1",CalculationMode.Ticks, dRange, true);
SetProfitTarget("Short2", CalculationMode.Ticks, dRange);
SetTrailStop("Short2",CalculationMode.Ticks, dRange, true);
SetProfitTarget("Long1", CalculationMode.Ticks, dRange2/2);
SetTrailStop("Long1",CalculationMode.Ticks, dRange2, true);
SetProfitTarget("Long2", CalculationMode.Ticks, dRange2);
SetTrailStop("Long2",CalculationMode.Ticks, dRange2, true);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
if
(
criteria for short
)
{
EnterShort(NumContract, "Short1");
EnterShort(NumContract, "Short2");
}
else if
(
citeria for long
)
{
EnterLong(NumContract, "Long1");
EnterLong(NumContract, "Long2");
}
}
Comment