Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CHART LABELS RANK PERCENTILE - Adds handy quick-reference labels to the chart
- #
- #
- declare upper ;
- declare once_per_bar ;
- declare hide_on_intraday ; # most functions are only relevant for daily aggregation
- input days_back = 252; # we usually do this over one year (252 trading days)
- def precios = if IsNaN(close) # if price data doesn't exist for a particular period ...
- then precios[1] # ... set it to the previous value so it won't taint the hi/lo
- else close ;
- def volatilidad = imp_volatility();
- # si no se encuentra de un dia, use el dia anterior
- def volatilidades = if !IsNaN(volatilidad) then volatilidad else volatilidad[1];
- # display regular implied volatility
- # ---------------------------
- AddLabel(yes, "IV: " + Round(volatilidades * 100.0, 0), Color.BLUE);
- # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- #
- # IMPLIED VOLATILITY RANK - Adds a colored label to the chart showing IV Rank
- #
- input Show_IV_Rank = yes ;
- def low_over_timespan = Lowest(volatilidades, days_back);
- def high_over_timespan = Highest(volatilidades, days_back);
- def iv_rank = Round( (volatilidades - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);
- # Add label, colored according to current IV rank.
- AddLabel(Show_IV_Rank, "IV Rank: " + iv_rank + "%", if iv_rank > 50 then Color.UPTICK else Color.DOWNTICK ) ;
- # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- #
- # IMPLIED VOLATILITY PERCENTILE - Adds label to the chart showing IV Percentile
- # how many dias over the past year, has IV been below the current IV
- #
- input Show_IV_Percentile = yes ;
- def percentil_cuenta_bajo = fold i = 1 to days_back + 1 with contador_de_percentil = 0
- do
- if volatilidades[0] > volatilidades[i] then
- contador_de_percentil + 1
- else
- contador_de_percentil;
- def iv_percentile = Round(percentil_cuenta_bajo / days_back * 100.0, 0);
- AddLabel(Show_IV_Percentile, "IV Percentile: " + iv_percentile + "%", if iv_percentile > 50 then Color.UPTICK else Color.DOWNTICK );
- # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- #
- # CALCULO DE PRICE RANK
- input Show_Price_Rank = yes;
- def pHi = HighestAll(precios) ; # highest price over range
- def pLo = LowestAll(precios) ; # lowest price over range
- def price_Rank = Round( 100 * ( (precios - pLo) / (pHi - pLo) ), 0) ;
- AddLabel(Show_Price_Rank, "Price Rank: " + price_Rank + "%", if price_Rank > 50 then Color.UPTICK else Color.DOWNTICK ) ;
- # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- #
- # CALCULO DE PRICE PERCENTIL
- input Show_Price_Percentile = yes;
- def precio_cuenta_bajo = fold j = 1 to days_back + 1 with contador_precio = 0
- do
- if precios[0] > precios[j] then
- contador_precio + 1
- else
- contador_precio;
- def precio_percentile = Round(precio_cuenta_bajo / days_back * 100.0, 0);
- # Calculate red and green color levels (modified by intensity) for the color function
- AddLabel(Show_Price_Percentile, "Price Percentile: " + precio_percentile + "%", if precio_percentile > 50 then Color.UPTICK else Color.DOWNTICK);
- # SHOW SIGNIFICANT PRICE MOVE - pricePercent
- #
- # If the underlying has moved more than a specified amount (default 5%) in the last few (default 10) bars,
- # highlight that fact with a color-coded Percent Price Move label.
- #
- # Adapted from code by Shah H. Development 2013
- input ShowPricePercent = yes ;
- input PricePercentBars = 10 ;
- input PricePercentType = ohlc4 ;
- input PricePercentTrigger = 5.0 ;
- def pricePercentChg = Round( 100 * ( PricePercentType / PricePercentType[PricePercentBars] - 1 ), 1 ) ;
- AddLabel( ShowPricePercent and ( AbsValue(pricePercentChg) > PricePercentTrigger ),
- PricePercentBars + "-Bar Price Move: " + pricePercentChg + "%",
- if pricePercentChg > 0 then Color.UPTICK else Color.DOWNTICK ) ;
Advertisement
Add Comment
Please, Sign In to add comment