I'm trying to run a backtest - working with historical data - with my indicator. However, something is wrong.
My real-time data logic - OnMarketData:
if (e.MarketDataType == MarketDataType.Last)
lastVolume = e.Volume;
lastPrice = e.Price;
else if (e.MarketDataType == MarketDataType.Ask)
priceAsk = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
priceBid = e.Price;
//My method
myMethod(lastPrice, lastVolume);
I've moved that logic to OnBarUpdate, now it's looks like this:
protected override void Initialize()
{
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 1)
{
lastVolume = Volume[0];
lastPrice = Close[0];
myMethod(lastPrice, lastVolume);
}
if (BarsInProgress == 2)
{
priceAsk = Close[0];
}
if (BarsInProgress == 3)
{
priceBid = Close[0];
}
}
I would really appreciate any help you can give me.
Cheers,
Ronald.
Comment