OPEN-SOURCE SCRIPT

vol_cone

Aggiornato
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.
Note di rilascio
- (hopefully) fixed line re-painting.
- added "lags" input: draw the cone starting from "lags" bars back.
Note di rilascio
- 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.
Note di rilascio
- 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.
Note di rilascio
- 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.
forecastHistorical Volatilityivrealizedrvvolatilitycone

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità