OPEN-SOURCE SCRIPT

Rolling Sharpe Ratio Oscillator | Astral Vision

1 846
Rolling Sharpe Ratio Oscillator | Astral Vision 🌠💠

The Sharpe Ratio measures risk-adjusted return: how much excess return is being generated per unit of volatility. Applied as a rolling oscillator to Bitcoin's daily log returns, it answers a question that neither price nor momentum indicators address: is the current appreciation being earned efficiently relative to the risk being taken, or is it a volatile, noisy move that consumes large drawdowns to produce modest gains?

High rolling Sharpe values indicate sustained, low-volatility uptrends where return per unit of risk is structurally elevated, historically coinciding with the most efficient phases of Bitcoin's bull runs. Negative Sharpe values indicate periods where volatility exceeds returns, marking drawdowns and bear phases.

This indicator plots the annualized rolling Sharpe as a smoothed oscillator with configurable thresholds, and back-projects those thresholds onto the price chart as dynamic levels representing the price that would produce each Sharpe extreme given current return and volatility conditions.

Calculation ⚙️

`Log Return = log(close / close[1])`

`Rolling Sharpe = (SMA(Log Return, length) / StdDev(Log Return, length)) × √365`

The ratio is annualized by multiplying by the square root of 365, expressing it in standard annual terms. An EMA of configurable length is then applied to smooth the raw Sharpe before threshold evaluation and coloring.

The price bands invert the Sharpe thresholds back to price space:

`Band Price = close[length] × exp(threshold × StdDev / √365 × length)`

This produces a dynamic price level representing what price would need to be, given current volatility, to produce the specified Sharpe value.

Plots 📊
  • Smoothed Sharpe oscillator line in the indicator panel, colored by regime or continuous gradient
  • Overbought and oversold threshold lines
  • Fill between oscillator and overbought threshold when breached (distribution zone)
  • Fill between oscillator and oversold threshold when breached (accumulation zone)
  • Dynamic overbought and oversold price bands on the price chart, EMA-smoothed
  • Candle coloring on the price chart by regime or gradient
  • Background highlight on the price chart when either threshold is active


Inputs 🎛️
  • `Lookback Period (days)`: rolling window for mean and standard deviation of log returns (default 365)
  • `Smoothing EMA Length`: EMA applied to the raw Sharpe before all output (default 30)
  • `Oversold Threshold`: Sharpe level marking risk-adjusted accumulation extremes (default −1.5)
  • `Overbought Threshold`: Sharpe level marking risk-adjusted distribution extremes (default 2.8)
  • `Use Gradient Color`: toggles between continuous gradient coloring across the −2 to +2 range and discrete regime-based coloring


Colors 🎨

5 Astral Vision presets + custom override. Default: Futura. In gradient mode, color transitions continuously from negative to positive across the Sharpe range. In discrete mode, positive color activates above the overbought threshold, negative below the oversold threshold, and neutral between them.

Purpose 🎯

Standard momentum indicators like RSI and MACD measure price direction and speed, but are blind to whether that directional move is being achieved efficiently. A 30% Bitcoin rally with 80% annualized volatility carries very different risk-adjusted implications than the same rally with 40% volatility, yet both look identical on a price or momentum chart.

The rolling Sharpe makes that distinction explicit. The price band back-projection eliminates the need to mentally translate Sharpe values into price context: the bands show directly on the chart what price level corresponds to each statistical extreme given current volatility, updating dynamically as the volatility regime evolves.
The gradient coloring option provides a continuous read of risk-adjusted efficiency across the entire oscillator range, not just at binary threshold crossings.

Disclaimer ⭕️

It is not financial advice, not an investment recommendation, and not affiliated with any financial institution, research firm, or organization of any kind. All content is provided for educational and informational purposes only. Always conduct your own research before making any financial decision.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.