taylor_o Updated   
Draws a volatility cone on the chart, using the contract's realized volatility (rv). The inputs are:

- window: the number of past periods to use for computing the realized volatility. VIX uses 30 calendar days, which is 21 trading days, so 21 is the default.
- stdevs: the number of standard deviations that the cone will cover.
- periods to project: the length of the volatility cone.
- periods per year: the number of periods in a year. for a daily chart, this is 252. for a thirty minute chart on a contract that trades 23 hours a day, this is 23 * 2 * 252 = 11592. for an accurate cone, this input must be set correctly, according to the chart's time frame.
- history: show the lagged projections. in other words, if the cone is set to project 21 periods in the future, the lines drawn show the top and bottom edges of the cone from 23 periods ago.
- rate: the current interest or discount rate. this is used to compute the forward price of the underlying contract. using an accurate forward price allows you to compare the realized volatility projection to the implied volatility projections derived from options prices.

Example settings for a 30 minute chart of a contract that trades 23 hours per day, with 1 standard deviation, a 21 day rv calculation, and half a day projected:

- stdevs: 1
- periods to project: 23
- window: 23 * 2 * 21 = 966
- periods per year: 23 * 2 * 252 = 11592

Additionally, a table is drawn in the upper right hand corner, with several values:

- rv: the contract's current realized volatility.
- rnk: the rv's percentile rank, compared to the rv values on past bars.
- acc: the proportion of times price settled inside, versus outside, the volatility cone, "periods to project" into the future. this should be around 65-70% for most contracts when the cone is set to 1 standard deviation.
- up: the upper bound of the cone for the projection period.
- dn: the lower bound of the cone for the projection period.


- pinescript only seems to be able to draw a limited distance into the future. If you choose too many "periods to project", the cone will start drawing vertically at some limit.
- the cone is not totally smooth owing to the facts a) it is comprised of a limited number of lines and b) each bar does not represent the same amount of time in pinescript, as some cross weekends, session gaps, etc.
Release Notes:
- (hopefully) fixed line re-painting.
- added "lags" input: draw the cone starting from "lags" bars back.
Release Notes:
- updated cone to use bar index instead of bar time, which results in a smoother cone that doesn't have problems with gaps.
- added a second cone, for a second standard deviation setting. by default, the first cone is 1 stdev, the second is 2 stdevs.
Release Notes:
- updated the table to show the second cone's terminal values.

note that "acc" and "rnk" apply to cone 1 (controlled by stdevs setting) only.
Release Notes:
- added "anchor_to_session_start". for intraday charts, this will set the cone on the first bar of the current session (RTH or ETH).

i'm not sure if it works for every time frame. the session must have at least 3 bars. if this setting is checked, "lags" has no effect -- the cones are always lagged to the session start. this setting has no effect on daily or higher timeframes.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?