taylor_o

vol_cone

taylor_o 已更新   
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.

Limitations:

- 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.
版本注释:
- (hopefully) fixed line re-painting.
- added "lags" input: draw the cone starting from "lags" bars back.
版本注释:
- 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.
版本注释:
- 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.
版本注释:
- 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.
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?