Rolling Sharpe Oscillator
A price chart shows displacement, not efficiency. A market can travel the same net distance by grinding smoothly in one direction or by whipsawing violently around a flat average - a trend-following system does well in the first case and gets chopped up in the second, even though both look like "the market moved" on a plain price chart. The Sharpe ratio - mean return divided by the standard deviation of return over the same window - is exactly the statistic that tells these two cases apart: it stays near zero when the moves cancel out and rises when the moves compound in one direction with low dispersion. This indicator computes that ratio on a rolling basis over InpLookback bars of simple bar-to-bar returns, using a risk-free rate of zero rather than asking for a benchmark yield most traders would leave at zero anyway. A sustained reading well above +1 or below -1 marks a stretch where the market has been trending efficiently; readings clustered near zero mark choppy, mean-reverting conditions where a trend system is more likely to be whipsawed. Notes and limitations - Uses a zero risk-free rate. This is a market-efficiency gauge, not a literal portfolio Sharpe ratio measured against a benchmark yield. - Returns are simple percentage bar-to-bar returns, not log returns; over the short lookback windows this indicator is designed for the difference is negligible. - A flat or zero close in the lookback window is skipped rather than causing a division error, which can slightly shrink the effective sample on illiquid symbols with occasional zero-volume bars. - Does not repaint - each bar's value only ever uses bars at or before it.
Indicator · MT4 · v1.0 · Free
About Rolling Sharpe Oscillator
Rolling Sharpe Oscillator is an indicator for MetaTrader 4. It has 1 setting, such as Lookback. MQL source code included.
Files in the download: RollingSharpeOscillator.mq4, RollingSharpeOscillator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback | 20 | Bars of returns used for the rolling mean/stdev window |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Oscillator · Trend · MT4 Indicator · MQL4 Source Code