Calculating bid/ask spread accurately & efficiently  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Calculating bid/ask spread accurately & efficiently

Postby JoshM » 21 Nov 2013

How does one calculate the bid/ask spread in an efficient and accurate manner?

Bars.StatusLine.Ask - Bars.StatusLine.Bid gives the bid/ask spread, but:
  • CalcBar() is only evaluated on a incoming tick. Even with a chart set to Bid prices, the bid/ask spread calculation will not be accurate (e.g., when the ask changes but bid remains the same).
  • ExecControl.RecalcLastBarAfter() provides the option to recalculate CalcBar() on a fixed time interval, but
    (a) this is not efficient to do this a couple of times per second when the instrument is not that actively trading (e.g., outside RTH), and
    (b) there is still the chance that bid/ask updates are missed if the TimeSpan is not low enough.
I'm looking for something like NT's MarketDataEventArgs since that would be both accurate and efficient, i.e.:

Code: Select all

protected override void OnMarketData(MarketDataEventArgs e)
{
// Print some data to the Output window
if (e.MarketDataType == MarketDataType.Last)
Print("Last = " + e.Price + " " + e.Volume);
else if (e.MarketDataType == MarketDataType.Ask)
Print("Ask = " + e.Price + " " + e.Volume);
else if (e.MarketDataType == MarketDataType.Bid)
Print("Bid = " + e.Price + " " + e.Volume);
}
Can MultiCharts .NET do this?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Calculating bid/ask spread accurately & efficiently

Postby Henry MultiСharts » 21 Nov 2013

Hello Josh,

As it was already mentiond on the forum - the most efficient way is to plot two data series on the chart.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Calculating bid/ask spread accurately & efficiently

Postby JoshM » 22 Nov 2013

As it was already mentiond on the forum - the most efficient way is to plot two data series on the chart.
Thanks Henry. I'm aware of that option, but I don't consider it very efficient to add two data series to multiple charts (this also does not work for the Real-time scanner).

That way does not solve this:
Even with a chart set to Bid prices, the bid/ask spread calculation will not be accurate (e.g., when the ask changes but bid remains the same).
If the Spread_Dif indicator is based on data series 1 (bid prices), data series 2 can still update (i.e. new ask price) but if data series 1 will not update, this new bid/ask spread will not register, right? (Since calculation is performed on data series 1 updates)

Setting Real-time history matching off does not appear to solve this:
“Real-Time History Matching” is turned off (the box is cleared), the data series 1 stopped updating, the data series 2 continues updating: a script will be calculated on the latest bar of data series 1 and will not be calculated until new ticks/bars come in on data series 1, no matter if data series 2 is updating or not.

“Real-Time History Matching” is turned on (the box is checked), the data series 1 stopped updating, the data series 2 continues updating: a script will be calculated on the latest bar of data series 1 and will not be calculated until new ticks/bars come in on data series 1, no matter if data series 2 is updating or not.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Calculating bid/ask spread accurately & efficiently  [SOLVED]

Postby Henry MultiСharts » 22 Nov 2013

I'm looking for something like NT's MarketDataEventArgs since that would be both accurate and efficient, i.e.:

Code: Select all

protected override void OnMarketData(MarketDataEventArgs e)
{
// Print some data to the Output window
if (e.MarketDataType == MarketDataType.Last)
Print("Last = " + e.Price + " " + e.Volume);
else if (e.MarketDataType == MarketDataType.Ask)
Print("Ask = " + e.Price + " " + e.Volume);
else if (e.MarketDataType == MarketDataType.Bid)
Print("Bid = " + e.Price + " " + e.Volume);
}
Can MultiCharts .NET do this?
Similar functionality is available in DataLoader - Subscribe2RT. Example here.


Return to “MultiCharts .NET”