I am developing indicator to calculate volume on Bid and volume on Ask (on candle).
I need work with also historical data.
Below is script that works on realtime data. Is there a way to solve this on historical data? Especially OnMarketData part? I thought I saw somewhere about adding another DataSeries based on ask bid? Is there an example?
Thanks a lot
Code:
On realtime data, this approach works for me:
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate() {
if(Open[0] > Close[0])
Values[2].Set(Volume[0]);
else if(Open[0] < Close[0])
Values[3].Set(Volume[0]);
else
Values[4].Set(Volume[0]);
if (CurrentBar < activeBar)
{
return;
}
else if (CurrentBar != activeBar)
{
Print(Time[0] + " buys: " + buys + " sells: " + sells + " Close[0]: " + Close[0]);
// Sells
Values[0].Set(sells);
// Buys
Values[1].Set(buys);
buys = 0;
sells = 0;
activeBar = CurrentBar;
UpdateHistogram();
}
if (!Historical) {
// Sells
Values[0].Set(sells);
// Buys
Values[1].Set(buys);
}
}
AND:
/// <summary>
/// Called on each incoming real time market data event
/// </summary>
protected override void OnMarketData(MarketDataEventArgs e)
{
if (e.MarketDataType == MarketDataType.Ask)
askPrice = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
bidPrice = e.Price;
else if (e.MarketDataType == MarketDataType.Last)
{
if (askPrice > 0 && e.Price >= askPrice)
buys += e.Volume;
else if (bidPrice > 0 && e.Price <= bidPrice)
sells += e.Volume;
}
}
Comment