SavingFace

MVRV Short Term Holders.

Sep 21st, 2024 (edited)
330
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | Cryptocurrency | 0 0
  1. //@version=6
  2. indicator('STH MVRV Moving Average with EMA', shorttitle = 'STHMVRV', overlay = false)
  3.  
  4. // Input for the SMA length and EMA length
  5. smaLengthInput = input.int(100, title = 'SMA Length')
  6. emaLengthInput = input.int(55, title = 'EMA Length')
  7.  
  8. // Smoothing option for SMA
  9. smoothingType = input.string('None', title = 'Smoothing Type', options = ['None', 'EMA', 'SMA'])
  10. smoothingLength = input.int(20, title = 'Smoothing Length', minval = 1)
  11.  
  12. // Selectable option for MVRVMA color mode
  13. mvrvMAColorMode = input.string('Normal', title = 'MVRVMA Color Mode', options = ['Normal', 'DI+ vs DI-'])
  14.  
  15. // Calculate the market value only on the daily time frame
  16. isDaily = ta.change(time('D'))
  17. marketValue = request.security(syminfo.tickerid, 'D', close)
  18.  
  19. // Get the realized value
  20. realValue = ta.sma(na(marketValue) ? ta.valuewhen(bool(isDaily), close, 0) : marketValue, smaLengthInput)
  21.  
  22. // Calculate the STH MVRV
  23. mvrv = marketValue / realValue
  24.  
  25. // Calculate the moving average of the STH MVRV on the daily time frame
  26. mvrvMA = request.security(syminfo.tickerid, 'D', ta.sma(mvrv, 2))
  27.  
  28. // Calculate the EMA of the MVRVMA
  29. emaMVRVMA = ta.ema(mvrvMA, emaLengthInput)
  30.  
  31. // Levels
  32. plot(1, color = color.new(color.purple, 0), title = 'LvL 1', linewidth = 2)
  33. hline(1, title = 'Profit line', color = color.new(color.purple, 0), linewidth = 1, linestyle = hline.style_dashed)
  34.  
  35. // STH Channel with 100-Day SMA
  36. sma_100 = ta.sma(close, smaLengthInput)
  37. sma_smoothed = switch smoothingType
  38. 'None' => sma_100
  39. 'EMA' => ta.ema(sma_100, smoothingLength)
  40. 'SMA' => ta.sma(sma_100, smoothingLength)
  41.  
  42. deviation_percent = input.float(8.0, title = 'Deviation (%)', step = 1) / 100
  43. deviation_up = sma_smoothed * (1 + deviation_percent)
  44. deviation_down = sma_smoothed * (1 - deviation_percent)
  45.  
  46. // Directional Movement calculations for DI+ and DI-
  47. len = input.int(14, title = 'DI Length')
  48. TrueRange = ta.tr
  49. DirectionalMovementPlus = math.max(high - high[1], 0)
  50. DirectionalMovementMinus = math.max(low[1] - low, 0)
  51.  
  52. // Declare Smoothed Variables
  53. var float SmoothedTrueRange = na
  54. var float SmoothedDirectionalMovementPlus = na
  55. var float SmoothedDirectionalMovementMinus = na
  56.  
  57. // Compute Smoothed Values
  58. SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1]) / len) + TrueRange
  59. SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1]) / len) + DirectionalMovementPlus
  60. SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1]) / len) + DirectionalMovementMinus
  61.  
  62. DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
  63. DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
  64.  
  65. // Color logic for MVRVMA based on selection
  66. normalColor = mvrvMA[1] > 1 ? #ffebba : #b13e00
  67. diColor = DIPlus > DIMinus ? #ffebba : #b13e00
  68. mvrvMA_final_color = mvrvMAColorMode == 'DI+ vs DI-' ? diColor : normalColor
  69.  
  70. // Plot the STH MVRV moving average with selectable color mode
  71. plot(mvrvMA, title = 'STH MVRV MA', color = mvrvMA_final_color, linewidth = 2)
  72.  
  73. // Plot the EMA of the MVRVMA
  74. plot(emaMVRVMA, title = 'MVRVMA EMA', color = #da00ff, linewidth = 1)
  75.  
  76. // Change deviation_up line color based on DI+ > DI-
  77. deviationColor = DIPlus > DIMinus ? #ffebba : #b13e00
  78.  
  79. plot(sma_smoothed, color = #5d606b, linewidth = 2, title = '100-Day SMA (Smoothed)', force_overlay = true)
  80. plot(deviation_up, color = deviationColor, linewidth = 2, title = 'Upper Deviation', force_overlay = true)
  81. plot(deviation_down, color = deviationColor, linewidth = 2, title = 'Lower Deviation', force_overlay = true)
  82.  
  83. // Bar color logic
  84. isAbove = mvrvMA > emaMVRVMA
  85. isBelow = mvrvMA < emaMVRVMA
  86. barcolor(isAbove ? color.green : isBelow ? color.red : na)
  87.  
  88.  
  89. // Create a table for statistics
  90. var table statsTable = table.new(position = position.top_right, columns = 2, rows = 6, bgcolor = color.black)
  91.  
  92. // Define table values
  93. table.cell(statsTable, 0, 0, "Trend", text_color = color.white)
  94. table.cell(statsTable, 1, 0, mvrvMA > emaMVRVMA ? "↑ Uptrend" : "↓ Downtrend", text_color = mvrvMA > emaMVRVMA ? color.green : color.red)
  95.  
  96. table.cell(statsTable, 0, 1, "DI+ vs DI-", text_color = color.white)
  97. table.cell(statsTable, 1, 1, DIPlus > DIMinus ? "Bullish" : "Bearish", text_color = DIPlus > DIMinus ? color.green : color.red)
  98.  
  99. table.cell(statsTable, 0, 2, "Deviation Up", text_color = color.white)
  100. table.cell(statsTable, 1, 2, str.tostring(deviation_up, "#.##"), text_color = color.green)
  101.  
  102. table.cell(statsTable, 0, 3, "100-Day SMA", text_color = color.white)
  103. table.cell(statsTable, 1, 3, str.tostring(sma_smoothed, "#.##"), text_color = color.blue)
  104.  
  105. table.cell(statsTable, 0, 4, "Deviation Down", text_color = color.white)
  106. table.cell(statsTable, 1, 4, str.tostring(deviation_down, "#.##"), text_color = color.red)
  107.  
  108. table.cell(statsTable, 0, 5, "Last DI Crossover", text_color = color.white)
  109. table.cell(statsTable, 1, 5, str.tostring(ta.barssince(DIPlus > DIMinus), "#") + " bars ago", text_color = color.gray)
  110.  
Tags: MVRV
Advertisement
Comments
Add Comment
Please, Sign In to add comment