Advertisement
PineCoders

Correlation Ribbon

Sep 6th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. //@version=4
  2. //@author=LucF
  3.  
  4. // Correlation Ribbon [LucF]
  5. // v1.2, 2019.09.11 08:21 — LucF
  6. // Thx to midtownsk8rguy for colors.
  7.  
  8. study(title="Correlation Ribbon [LucF]", shorttitle="Correlation Ribbon")
  9.  
  10. otherSymbol = input(true, "Correlate against other symbol")
  11. symb = input("SP:SPX", type = input.symbol)
  12. singleLine = input(false, "Single Line instead of ribbon")
  13. price = input(close, "Source")
  14. offset = input(0, "Offest", minval=0)
  15. period = input(50, "Period", minval=3)
  16. invert = input(false, "Invert")
  17. step = input(1, "Bar Step between lines", minval=1)
  18.  
  19. // Correlation with same symbol.
  20. Corr(Series, _i, Offset, Period, Invert) =>
  21. correlation(Series, Series[_i + Offset], Period) * (Invert ? -1.0 : 1.0)
  22.  
  23. // Correlation with another symbol.
  24. CorrS(Series, _i, Offset, Period, Invert) =>
  25. correlation(Series, security(symb, timeframe.period, Series)[_i + Offset], Period) * (Invert ? -1.0 : 1.0)
  26.  
  27. plot( singleLine ? otherSymbol ? CorrS(price, 0 , offset, period, invert) : Corr(price, 0 , offset, period, invert) : na, " 0", color=#00FF00FF, linewidth=2)
  28. plot(not singleLine ? otherSymbol ? CorrS(price, 2 + step, offset, period, invert) : Corr(price, 2 + step, offset, period, invert) : na, " 2", color=#00FF00FF, linewidth=2)
  29. plot(not singleLine ? otherSymbol ? CorrS(price, 3 + step, offset, period, invert) : Corr(price, 3 + step, offset, period, invert) : na, " 3", color=#0FFF00FF)
  30. plot(not singleLine ? otherSymbol ? CorrS(price, 4 + step, offset, period, invert) : Corr(price, 4 + step, offset, period, invert) : na, " 4", color=#1FFF00FF)
  31. plot(not singleLine ? otherSymbol ? CorrS(price, 5 + step, offset, period, invert) : Corr(price, 5 + step, offset, period, invert) : na, " 5", color=#2FFF00FF)
  32. plot(not singleLine ? otherSymbol ? CorrS(price, 6 + step, offset, period, invert) : Corr(price, 6 + step, offset, period, invert) : na, " 6", color=#3FFF00FF)
  33. plot(not singleLine ? otherSymbol ? CorrS(price, 7 + step, offset, period, invert) : Corr(price, 7 + step, offset, period, invert) : na, " 7", color=#4FFF00FF)
  34. plot(not singleLine ? otherSymbol ? CorrS(price, 8 + step, offset, period, invert) : Corr(price, 8 + step, offset, period, invert) : na, " 8", color=#5FFF00FF)
  35. plot(not singleLine ? otherSymbol ? CorrS(price, 9 + step, offset, period, invert) : Corr(price, 9 + step, offset, period, invert) : na, " 9", color=#6FFF00FF)
  36. plot(not singleLine ? otherSymbol ? CorrS(price,10 + step, offset, period, invert) : Corr(price,10 + step, offset, period, invert) : na, "10", color=#7FFF00FF, linewidth=2)
  37. plot(not singleLine ? otherSymbol ? CorrS(price,11 + step, offset, period, invert) : Corr(price,11 + step, offset, period, invert) : na, "11", color=#8FFF00FF)
  38. plot(not singleLine ? otherSymbol ? CorrS(price,12 + step, offset, period, invert) : Corr(price,12 + step, offset, period, invert) : na, "12", color=#9FFF00FF)
  39. plot(not singleLine ? otherSymbol ? CorrS(price,13 + step, offset, period, invert) : Corr(price,13 + step, offset, period, invert) : na, "13", color=#AFFF00FF)
  40. plot(not singleLine ? otherSymbol ? CorrS(price,14 + step, offset, period, invert) : Corr(price,14 + step, offset, period, invert) : na, "14", color=#BFFF00FF)
  41. plot(not singleLine ? otherSymbol ? CorrS(price,15 + step, offset, period, invert) : Corr(price,15 + step, offset, period, invert) : na, "15", color=#CFFF00FF)
  42. plot(not singleLine ? otherSymbol ? CorrS(price,16 + step, offset, period, invert) : Corr(price,16 + step, offset, period, invert) : na, "16", color=#DFFF00FF)
  43. plot(not singleLine ? otherSymbol ? CorrS(price,17 + step, offset, period, invert) : Corr(price,17 + step, offset, period, invert) : na, "17", color=#EFFF00FF)
  44. plot(not singleLine ? otherSymbol ? CorrS(price,18 + step, offset, period, invert) : Corr(price,18 + step, offset, period, invert) : na, "18", color=#FFFF00FF)
  45. plot(not singleLine ? otherSymbol ? CorrS(price,19 + step, offset, period, invert) : Corr(price,19 + step, offset, period, invert) : na, "19", color=#FFEF00FF)
  46. plot(not singleLine ? otherSymbol ? CorrS(price,20 + step, offset, period, invert) : Corr(price,20 + step, offset, period, invert) : na, "20", color=#FFDF00FF, linewidth=2)
  47. plot(not singleLine ? otherSymbol ? CorrS(price,21 + step, offset, period, invert) : Corr(price,21 + step, offset, period, invert) : na, "21", color=#FFCF00FF)
  48. plot(not singleLine ? otherSymbol ? CorrS(price,22 + step, offset, period, invert) : Corr(price,22 + step, offset, period, invert) : na, "22", color=#FFBF00FF)
  49. plot(not singleLine ? otherSymbol ? CorrS(price,23 + step, offset, period, invert) : Corr(price,23 + step, offset, period, invert) : na, "23", color=#FFAF00FF)
  50. plot(not singleLine ? otherSymbol ? CorrS(price,24 + step, offset, period, invert) : Corr(price,24 + step, offset, period, invert) : na, "24", color=#FF9F00FF)
  51. plot(not singleLine ? otherSymbol ? CorrS(price,25 + step, offset, period, invert) : Corr(price,25 + step, offset, period, invert) : na, "25", color=#FF8F00FF)
  52. plot(not singleLine ? otherSymbol ? CorrS(price,26 + step, offset, period, invert) : Corr(price,26 + step, offset, period, invert) : na, "26", color=#FF7F00FF)
  53. plot(not singleLine ? otherSymbol ? CorrS(price,27 + step, offset, period, invert) : Corr(price,27 + step, offset, period, invert) : na, "27", color=#FF6F00FF)
  54. plot(not singleLine ? otherSymbol ? CorrS(price,28 + step, offset, period, invert) : Corr(price,28 + step, offset, period, invert) : na, "28", color=#FF5F00FF)
  55. plot(not singleLine ? otherSymbol ? CorrS(price,29 + step, offset, period, invert) : Corr(price,29 + step, offset, period, invert) : na, "29", color=#FF4F00FF)
  56. plot(not singleLine ? otherSymbol ? CorrS(price,30 + step, offset, period, invert) : Corr(price,30 + step, offset, period, invert) : na, "30", color=#FF3F00FF, linewidth=2)
  57. plot(not singleLine ? otherSymbol ? CorrS(price,31 + step, offset, period, invert) : Corr(price,31 + step, offset, period, invert) : na, "31", color=#FF2F00FF)
  58. plot(not singleLine ? otherSymbol ? CorrS(price,32 + step, offset, period, invert) : Corr(price,32 + step, offset, period, invert) : na, "32", color=#FF1F00FF)
  59. plot(not singleLine ? otherSymbol ? CorrS(price,33 + step, offset, period, invert) : Corr(price,33 + step, offset, period, invert) : na, "33", color=#FF0F00FF)
  60. plot(not singleLine ? otherSymbol ? CorrS(price,34 + step, offset, period, invert) : Corr(price,34 + step, offset, period, invert) : na, "34", color=#FF0000FF)
  61. plot(not singleLine ? otherSymbol ? CorrS(price,35 + step, offset, period, invert) : Corr(price,35 + step, offset, period, invert) : na, "35", color=#FF000FFF)
  62. plot(not singleLine ? otherSymbol ? CorrS(price,36 + step, offset, period, invert) : Corr(price,36 + step, offset, period, invert) : na, "36", color=#FF001FFF)
  63. plot(not singleLine ? otherSymbol ? CorrS(price,37 + step, offset, period, invert) : Corr(price,37 + step, offset, period, invert) : na, "37", color=#FF002FFF)
  64. plot(not singleLine ? otherSymbol ? CorrS(price,38 + step, offset, period, invert) : Corr(price,38 + step, offset, period, invert) : na, "38", color=#FF003FFF)
  65. plot(not singleLine ? otherSymbol ? CorrS(price,39 + step, offset, period, invert) : Corr(price,39 + step, offset, period, invert) : na, "39", color=#FF004FFF)
  66. plot(not singleLine ? otherSymbol ? CorrS(price,40 + step, offset, period, invert) : Corr(price,40 + step, offset, period, invert) : na, "40", color=#FF005FFF, linewidth=2)
  67. plot(not singleLine ? otherSymbol ? CorrS(price,41 + step, offset, period, invert) : Corr(price,41 + step, offset, period, invert) : na, "41", color=#FF006FFF)
  68. plot(not singleLine ? otherSymbol ? CorrS(price,42 + step, offset, period, invert) : Corr(price,42 + step, offset, period, invert) : na, "42", color=#FF007FFF)
  69. plot(not singleLine ? otherSymbol ? CorrS(price,43 + step, offset, period, invert) : Corr(price,43 + step, offset, period, invert) : na, "43", color=#FF008FFF)
  70. plot(not singleLine ? otherSymbol ? CorrS(price,44 + step, offset, period, invert) : Corr(price,44 + step, offset, period, invert) : na, "44", color=#FF009FFF)
  71. plot(not singleLine ? otherSymbol ? CorrS(price,45 + step, offset, period, invert) : Corr(price,45 + step, offset, period, invert) : na, "45", color=#FF00AFFF)
  72. plot(not singleLine ? otherSymbol ? CorrS(price,46 + step, offset, period, invert) : Corr(price,46 + step, offset, period, invert) : na, "46", color=#FF00BFFF)
  73. plot(not singleLine ? otherSymbol ? CorrS(price,47 + step, offset, period, invert) : Corr(price,47 + step, offset, period, invert) : na, "47", color=#FF00CFFF)
  74. plot(not singleLine ? otherSymbol ? CorrS(price,48 + step, offset, period, invert) : Corr(price,48 + step, offset, period, invert) : na, "48", color=#FF00DFFF)
  75. plot(not singleLine ? otherSymbol ? CorrS(price,49 + step, offset, period, invert) : Corr(price,49 + step, offset, period, invert) : na, "49", color=#FF00EFFF)
  76. plot(not singleLine ? otherSymbol ? CorrS(price,50 + step, offset, period, invert) : Corr(price,50 + step, offset, period, invert) : na, "50", color=#FF00FFFF, linewidth=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement