I have a strategy that seeks to trade the spread of NQ futures vs ES futures. My conditions are very simple right now, for testing purposes. Specifically, I am recording the most recent daily close of each market, and then comparing that price to the current price called on every tick. If the NQ declines more than 0.40% from yesterdays close, and the ES is still trading above its previous days close, then I want to buy the NQ and sell the ES.
To be clear, my primary data series or BarsArray[0] is NQ daily bars.
Secondary data series BarsArray[1] is ES daily bars.
Third series BarsArray[2] is NQ 1 tick data.
Lastly BarsArray[3] is ES 1 tick data.
The first 2 data series are strictly used to record the previous days close for each respective market.
For the tick data, I want to enter as soon as my condition takes place. In the script, you will see my entry orders are placed under BarsInProgress == 2.
The script is buildable and showing no syntax errors. However it is producing no trades.
I am having trouble finding where my logic needs correcting.
I have created 2 private integers YCQ and YCE. (Yesterdays close NQ and Yesterdays close ES.
I have not included exit orders as I set ExitOnSessionClose equal to true.
else if (State == State.Configure)
{
AddDataSeries("ES 12-18", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
AddDataSeries("NQ 12-18", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
AddDataSeries("ES 12-18", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 0
|| CurrentBars[1] < 0
|| CurrentBars[2] < 0
|| CurrentBars[3] < 0)
return;
if (Open[0] > 1)
{
YCQ = Convert.ToInt32(Close[1]);
YCE = Convert.ToInt32(Closes[1][1]);
}
if (BarsInProgress == 2)
if (((Closes[2][0]) < (YCQ - (YCQ * .004)))
&& ((Closes[3][0]) > YCE))
{
EnterLong(2,1, "MyLong");
EnterShort(3,1, "MyShort");
}
Comment