Roll Spread Estimator TradingView Indicator

Roll Spread Estimator turns a 1984 market microstructure result into a chart overlay. As a liquidity cost indicator TradingView traders can add to any symbol, it infers an effective spread from price behaviour rather than from a quote feed. Bid-ask bounce leaves a fingerprint: negative serial covariance between consecutive price changes. Also, the script measures that covariance over 40 bars, then converts it into a spread estimate.

It is free and open source. Indeed, you can add it to any chart from the Roll Spread Estimator script page on TradingView, and the full Pine source is published there for you to read.

What Roll Spread Estimator plots on the price chart

Two silver lines run either side of the close, half a spread away each, so the band width shows the current estimate at a glance. Still, the chart background tints whenever the regime reads tight – aquamarine above the EMA, coral below. Signals print as stacked flags: three layers below the bar for a long, tagged RSE up, and three above for a short, tagged RSE dn. Signal bars change colour. A seven-row dashboard lists the spread, the quantile cutoff, the raw covariance, the regime, the position state and bars since the last flag.

How Roll Spread Estimator is built

Roll’s estimator, bar by bar

Richard Roll published the idea in 1984. Thus, trades alternate between hitting the bid and lifting the offer, so observed prices bounce back and forth even when nothing changes underneath. That bounce shows up as negative covariance between one price change and the next. Hence, roll’s formula converts it: spread equals two times the square root of the negative covariance.

The script builds it directly. Next, it takes the current bar’s price change and the previous bar’s change, then computes their covariance over a 40-bar window using the mean-of-products minus product-of-means form. When the covariance comes out negative, it applies the formula. Then, when it comes out positive, the model does not apply and the script sets the spread to zero.

One caveat matters here. Yet, this works on candle closes, not on tick quotes. The number is a synthetic estimate of round-trip friction at the bar scale. Truly, it is not the spread your broker quotes, and you should not read it as one.

From spread reading to entry

Absolute spread values mean nothing across symbols, so the script ranks instead. Plainly, it takes the 70th percentile of the last 40 spread readings with linear interpolation. Any current reading at or below that cutoff counts as tight. Also, you can move the quantile between 0.20 and 0.95, and a lower setting makes the filter fussier.

The trigger itself stays simple. Indeed, an 8-period EMA sits on price. A close crossing above it during a tight regime arms a long. Still, a close crossing below arms a short. The tight filter is the whole point, since the crossover only counts when recent price action shows little bounce.

Three gates then run. Thus, the bar must close, because every signal carries barstate.isconfirmed. The position state must flip, so the script never stacks two longs. Hence, and four bars must pass since the last flag. Note the zero case: when covariance turns positive the spread reads zero, and zero always sits below the cutoff, so a strongly trending stretch also registers as tight.

How to read the signals

Read the band width, not the band levels. Next, the two silver lines sit half a spread either side of the close, so they track price exactly. Their separation carries the message. Then, a narrow band with the dashboard reading TIGHT SPREAD says recent closes show little bounce.

Check the Cov(r,r-1) row before you trust the regime. Yet, a negative covariance means Roll’s model applies and the spread number means something. A positive covariance means the model breaks down and the script reports zero. Truly, both states tint the background the same way, so the dashboard is where you tell them apart.

Treat the flag as a pullback entry inside a quiet stretch. Plainly, price crossing an 8-period EMA is a fast trigger on its own. The spread filter is what makes it selective. In markets that bounce hard – thin sessions, the minutes after news – the regime reads wide and the flags stop.

Every Roll Spread Estimator setting explained

The script exposes 9 inputs, grouped in the settings panel exactly as shown below. Defaults are the published values.

Roll Spread

SettingWhat it doesDefaultRange
Cov WindowSets the cov window used in the calculation.4015 to 120

Signal

SettingWhat it doesDefaultRange
Tight Spread QuantileSpread must be below the kth quantile of recent values to be ‘tight’.0.70.20 to 0.95
Pullback EMA LengthSets the pullback ema length used in the calculation.83 to 50
Cooldown BarsSets the cooldown bars used in the calculation.41 to 20

Visual

SettingWhat it doesDefaultRange
Show DashboardToggles show dashboard on the chart.onon / off
Show 3-Layer GlowToggles show 3-layer glow on the chart.onon / off
Show Spread ChannelToggles show spread channel on the chart.onon / off
Buy Color (Aquamarine)Colour used for buy color (aquamarine).#a7ffeb
Sell Color (Light Coral)Colour used for sell color (light coral).#ff8a80

Alerts built into Roll Spread Estimator

The script ships 11 alert conditions. Also, open the alert dialog on the chart, pick the indicator as the condition source, then choose the event you want. Alerts fire on the close of the bar, so they follow the same confirmed-bar rule the on-chart signals use.

  • RSE Buy
  • RSE Sell
  • RSE Any Signal
  • RSE Tight Start
  • RSE Tight End
  • RSE Bounce
  • RSE EMA Up
  • RSE EMA Down
  • RSE Webhook JSON

Other markets and timeframes

The comparison is entirely relative. Indeed, the script ranks each spread reading against its own last 40, so a 5-digit forex pair and a four-figure index both work on the defaults. Nothing needs retuning per symbol. Still, the one input to revisit is the cooldown. On a 1-minute chart four bars pass quickly and flags cluster, so raise it. Thus, volume plays no part anywhere in the calculation, which means spot forex tick volume never distorts the reading.

Limitations worth knowing

This does not read your broker’s spread. Hence, it infers one from the serial covariance of closes. For the real quoted spread, use your platform’s own data feed. Next, the estimate also reports in raw price units, so you cannot compare the number across instruments directly – only against its own recent history.

The zero case deserves care. Roll’s model needs negative covariance. During a strong trend the covariance turns positive, the script writes zero, and zero always clears the tight cutoff. Then, so the filter passes trending stretches as well as genuinely quiet ones. The Cov row on the dashboard is the only place that distinction shows.

There is no stop, no target and no sizing here. Yet, the EMA cross is a plain trigger with no trend context, so it flags against a strong move as readily as with it. The 40-bar covariance window also lags, which means the regime label describes the recent past.

Get Roll Spread Estimator on TradingView

Open Roll Spread Estimator on TradingView

If you also trade MetaTrader, the MT4 and MT5 indicator library is available below.

Get the complete indicator library

One email unlocks the full MT4 and MT5 indicator library. Truly, this TradingView script stays free on TradingView – the button above adds it to your chart.

Using it alongside MetaTrader

Adding a script on TradingView takes one click, so there is no install step here. Plainly, if you want the same idea on MetaTrader, the MT4 and MT5 indicator installation guide walks through copying files into the data folder and attaching them to a chart. You can also browse the full MetaTrader indicator library, the MT4 indicators section, or the other free TradingView scripts published on this profile. For related chart tools see the MT5 indicators section and the forex trading strategies guides.

External references

Frequently asked questions

Does the Roll Spread Estimator repaint?

No. Also, both signal flags require barstate.isconfirmed, and the plotshape calls draw from those flags, so a flag appears only after the bar closes. The spread channel and the dashboard update live during the bar. Indeed, the flags themselves stay exactly where they printed.

Is this the same as the spread my broker charges?

No. Still, roll’s estimator infers an effective round-trip cost from price behaviour, specifically from negative covariance between consecutive close-to-close changes. It uses candle data, not quotes. Thus, treat it as a relative measure of bar-scale friction, and read your platform’s quote feed for the actual dealing spread.

Why does the spread sometimes read exactly zero?

Roll’s formula only applies when the covariance is negative. Hence, when consecutive price changes trend together the covariance turns positive, the square root has no real solution, and the script writes zero. That is information in itself. Next, it says price is moving directionally rather than bouncing. Check the Cov(r,r-1) row to see which state you are in.

Which timeframe works best?

The estimator behaves best where bar-to-bar bounce dominates, which favours intraday charts from M5 to H1. On a daily chart the bounce component is tiny next to real price movement, so the covariance turns positive more often and the spread pins at zero. If you move up, widen the covariance window past the default 40.

How much should I rely on this indicator?

Treat it as one input, not a decision. Then, it is a chart analysis tool, not trading advice. Test it on your own markets and timeframes before relying on it. Results are not guaranteed; past performance is not indicative of future results.

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

Leave a Comment