Could this snippet of code work if i try to open a trade at the next bar open when Calculate = Calculate.OnBarClose ?
If this works, can we assume it will process much faster using this technique than using Calculate = Calculate.OnEachTick and
checking if IsFirstTickOfBar is true if we do a backtest on a large amount of data like a 10 years backtest on a daily chart ?
private bool isOkToProcess == false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Calculate = Calculate.OnBarClose;
}
}
protected override void OnBarUpdate()
{
isOkToProcess == true;
}
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
// if MarketDataType == MarketDataType.Last is true and isOkToProcess is true
// then we can theorically assume we are dealing with the next bar open, right ?
if (isOkToProcess && marketDataUpdate.MarketDataType == MarketDataType.Last)
// enter long if the last bar closed higher than the bar before it
if (Close[1] > High[2])
{
EnterLong();
isOkToProcess = false;
}
}

Comment