I have a relatively simple strategy that I am backtesting, and would like to produce the most accurate results using tick data exits.
I understand it is necessary to add a secondary data series for intrabar granularity, Im just having trouble doing so.
My primary data series is NQ futures 400 tick bars.
My secondary data series is NQ futures 1 tick data.
If possible, I would like to enter conditionally on the primary data series, so once a 400 tick bar closes, meeting my conditions, I will enter long on the open of the following bar. This is a non issue.
However, when trailing out of my position, I would like to set my trail stop according to the secondary data series, tick data, in order to test these stops more precisely as it would run real time.
I am aware that EnterLong and SetTrailStop do not work for secondary data series.
My question is how would I add this trailstop command to the secondary data series, if BarsInProgress == 1, while keeping everything else the same, still entering conditionally if BarsInProgress == 0 ?
If that is not possible, could you direct me where to find the position entry and exit commands for secondary data series, since the usual EnterLong and SetTrailStop only work for primary?
I will post the code below for further detail:
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries("NQ 12-18", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
}
else if (State.DataLoaded);
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 2)
return;
// Set 3
if (((R - (Low[0])) > (2.3 * (V - R)) )
&& ((R - (Low[0])) > (2.7 * (High[0] - (V))))
&& ((High[0] - (Low[0])) > 2.5)
&& (Low[0] < Low[1])
&& (Low[0] < Low[2])
&& (Low[0] < Low[3])
&& (Low[0] < Low[4])
&& (Low[0] < Low[5]))
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"LONG");
SetStopLoss(@"LONG", CalculationMode.Ticks, 13, true);
SetProfitTarget(@"LONG", CalculationMode.Ticks, 19);
}
// Set 4
if (((High[0] - (V)) > (2.3 * (V - R)))
&& ((High[0] - (V)) > (2.7 * (R - (Low[0]))))
&& ((High[0] - (Low[0])) > 2.5)
&& (High[0] > High[1])
&& (High[0] > High[2])
&& (High[0] > High[3])
&& (High[0] > High[4])
&& (High[0] > High[5]))
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"SHORT");
SetProfitTarget(@"SHORT", CalculationMode.Ticks, 19)
SetStopLoss(@"SHORT", CalculationMode.Ticks, 13, true);
}
}
}
}
This works fine, I would just like to get rid of my SetProfitTarget and SetStopLoss for both long and short conditions, and instead add a trail stop to the secondary data series to serve as an exit for both.
Comment