Conditional Value At Risk Bands
A value-at-risk quantile answers "how big is the worst move at this probability" and stops there. Conditional value at risk (expected shortfall) answers the more useful question: given that the move is in that worst tail, how bad does it typically get. That is the number a stop distance actually needs. For every bar this indicator takes the trailing InpLookback bar-to-bar price moves, sorts them, and averages the worst InpTailProbability fraction on each side. The average of the worst downside moves becomes the lower band; the average of the worst upside moves becomes the upper band. Both are added directly to the current close, so the bands sit in price units and can be read as a stop or target distance without further conversion. The distribution is rebuilt fresh on every bar from only the trailing window, so the bands adapt as volatility regimes change instead of carrying a fixed historical assumption forward. That also means a market that has just gone through a genuine volatility shift will show bands that widen or narrow with a lag equal to roughly the lookback window - the price for staying purely empirical rather than fitting a distributional model. Notes and limitations - This is a statistical read of recent history, not a volatility forecast - it says nothing about tomorrow that is not already implied by the trailing window. - A short InpLookback with a small InpTailProbability can leave very few moves in each tail, making the band noisy from bar to bar. - Bands rebuild independently every bar; they do not smooth or interpolate between readings. - This does not account for spread, commission, swap or slippage - add those separately when sizing an actual stop.
Indicator · MT5 · v1.0 · Free
About Conditional Value At Risk Bands
Conditional Value At Risk Bands is an indicator for MetaTrader 5. It has 2 settings, such as Lookback and Tail probability. MQL source code included.
Files in the download: ConditionalValueAtRiskBands.ex5, ConditionalValueAtRiskBands.mq5, ConditionalValueAtRiskBands.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback | 100 | Bars of history used to build the move distribution |
| Tail probability | 0.05 | Tail fraction averaged into each band (0.05 = worst/best 5%) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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: Trailing Stop & Break-even · MT5 Indicator · MQL5 Source Code