fabgonber

CHART LABELS RANK PERCENTILE for Thinkorswim

Jun 1st, 2024
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. # CHART LABELS RANK PERCENTILE - Adds handy quick-reference labels to the chart
  2. #
  3. #
  4. declare upper ;
  5. declare once_per_bar ;
  6. declare hide_on_intraday ; # most functions are only relevant for daily aggregation
  7.  
  8. input days_back = 252; # we usually do this over one year (252 trading days)
  9.  
  10.  
  11. def precios = if IsNaN(close)            # if price data doesn't exist for a particular period ...
  12.     then precios[1]                      # ... set it to the previous value so it won't taint the hi/lo
  13.     else close ;
  14.  
  15. def volatilidad = imp_volatility();
  16. # si no se encuentra de un dia, use el dia anterior
  17. def volatilidades = if !IsNaN(volatilidad) then volatilidad else volatilidad[1];
  18.  
  19. # display regular implied volatility
  20. # ---------------------------
  21. AddLabel(yes, "IV: " + Round(volatilidades * 100.0, 0), Color.BLUE);
  22.  
  23. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  24. #
  25. # IMPLIED VOLATILITY RANK - Adds a colored label to the chart showing IV Rank
  26. #
  27. input Show_IV_Rank = yes ;
  28. def low_over_timespan = Lowest(volatilidades, days_back);
  29. def high_over_timespan = Highest(volatilidades, days_back);
  30. def iv_rank = Round( (volatilidades - low_over_timespan) / (high_over_timespan - low_over_timespan) * 100.0, 0);
  31.  
  32.  
  33. # Add label, colored according to current IV rank.
  34. AddLabel(Show_IV_Rank, "IV Rank: " + iv_rank + "%", if iv_rank > 50 then Color.UPTICK else Color.DOWNTICK ) ;
  35.  
  36.  
  37.  
  38. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  39. #
  40. # IMPLIED VOLATILITY PERCENTILE - Adds label to the chart showing IV Percentile
  41. # how many dias over the past year, has IV been below the current IV
  42. #
  43. input Show_IV_Percentile = yes ;
  44.  
  45. def percentil_cuenta_bajo = fold i = 1 to days_back + 1 with contador_de_percentil = 0
  46. do
  47. if volatilidades[0] > volatilidades[i] then
  48.     contador_de_percentil + 1
  49. else
  50.     contador_de_percentil;
  51. def iv_percentile = Round(percentil_cuenta_bajo / days_back * 100.0, 0);
  52.  
  53. AddLabel(Show_IV_Percentile, "IV Percentile: " + iv_percentile + "%",  if iv_percentile > 50 then Color.UPTICK else Color.DOWNTICK  );
  54.  
  55.  
  56. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  57. #
  58. # CALCULO DE PRICE RANK
  59. input Show_Price_Rank = yes;
  60. def pHi = HighestAll(precios) ;          # highest price over range
  61. def pLo =  LowestAll(precios) ;          #  lowest price over range
  62. def price_Rank = Round( 100 * ( (precios - pLo) / (pHi - pLo) ), 0) ;
  63. AddLabel(Show_Price_Rank, "Price Rank: " + price_Rank + "%", if price_Rank > 50 then  Color.UPTICK else Color.DOWNTICK ) ;
  64.  
  65.  
  66. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  67. #
  68. # CALCULO DE PRICE PERCENTIL
  69. input Show_Price_Percentile = yes;
  70. def precio_cuenta_bajo = fold j = 1 to days_back + 1 with contador_precio = 0
  71. do
  72. if precios[0] > precios[j] then
  73.     contador_precio + 1
  74. else
  75.     contador_precio;
  76. def precio_percentile = Round(precio_cuenta_bajo / days_back * 100.0, 0);
  77.  
  78. # Calculate red and green color levels (modified by intensity) for the color function
  79. AddLabel(Show_Price_Percentile, "Price Percentile: " + precio_percentile + "%", if precio_percentile > 50 then  Color.UPTICK else Color.DOWNTICK);
  80.  
  81.  
  82. # SHOW SIGNIFICANT PRICE MOVE - pricePercent
  83. #
  84. # If the underlying has moved more than a specified amount (default 5%) in the last few (default 10) bars,
  85. # highlight that fact with a color-coded Percent Price Move label.
  86. #
  87. # Adapted from code by Shah H. Development 2013
  88. input ShowPricePercent    =   yes ;
  89. input PricePercentBars    =    10 ;
  90. input PricePercentType    = ohlc4 ;
  91. input PricePercentTrigger =   5.0 ;
  92.  
  93. def pricePercentChg = Round( 100 * ( PricePercentType / PricePercentType[PricePercentBars] - 1 ), 1 ) ;
  94.  
  95. AddLabel( ShowPricePercent and ( AbsValue(pricePercentChg) > PricePercentTrigger ),
  96.     PricePercentBars + "-Bar Price Move: " + pricePercentChg + "%",
  97.     if pricePercentChg > 0 then Color.UPTICK else Color.DOWNTICK ) ;
Advertisement
Add Comment
Please, Sign In to add comment