The_Bitcoin_Beast

MTF Moving Averages with VWAP The BTC Beast

Oct 29th, 2026
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | Cryptocurrency | 0 0
  1. //@version=6
  2. // By using this or any TheBTCBeast indicator
  3. // The user assumes all risks and responsibilities
  4. indicator("VWAP & Moving Averages - The BTC Beast", overlay = true)
  5.  
  6. // ==========================================
  7. // VWAP
  8. // ==========================================
  9. vwap_show = input.bool(true, "Show VWAP", group="VWAP")
  10. vwap_anchor = input.string("Daily", "VWAP Anchor", options=["Daily", "Weekly", "Timestamp"], group="VWAP",
  11. tooltip="Daily = resets each day. Weekly = resets each week. Timestamp = starts at the date and time below and runs forward. Use an intraday chart for Daily.")
  12. vwap_ts = input.time(timestamp("1 Oct 2026 00:00 +0000"), "Anchor Timestamp (used when anchor = Timestamp)", group="VWAP")
  13. vwap_color = input.color(#00e5ff, "VWAP Color", group="VWAP")
  14. vwap_width = input.int(2, "VWAP Line Width", minval=1, maxval=5, group="VWAP")
  15.  
  16. // ==========================================
  17. // MOVING AVERAGES (6 slots: toggle, type, length, optional higher timeframe)
  18. // Types: SMA, EMA, WMA, HMA (Hull), RMA (Wilder/SMMA), VWMA, DEMA, TEMA, ZLEMA (zero-lag EMA), LinReg (least squares)
  19. // ==========================================
  20. mtf_confirmed = input.bool(true, "MTF: Use Confirmed (Non-Repainting) Values", group="MTF Settings",
  21. tooltip="ON: higher-timeframe averages use the last CLOSED higher-timeframe bar, so they never change after the fact (they update one higher-timeframe bar later). OFF: uses the still-forming higher-timeframe bar, which moves live and can repaint.")
  22.  
  23. ma1_show = input.bool(true, "Show MA 1", group="MA 1")
  24. ma1_type = input.string("EMA", "MA 1 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 1")
  25. ma1_len = input.int(20, "MA 1 Length", minval=1, group="MA 1")
  26. ma1_mtf = input.bool(false, "MA 1 Use Higher Timeframe (MTF)", group="MA 1")
  27. ma1_tf = input.timeframe("60", "MA 1 Timeframe", group="MA 1", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  28. ma1_color = input.color(#ffeb3b, "MA 1 Color", group="MA 1")
  29. ma1_width = input.int(2, "MA 1 Line Width", minval=1, maxval=5, group="MA 1")
  30.  
  31. ma2_show = input.bool(true, "Show MA 2", group="MA 2")
  32. ma2_type = input.string("EMA", "MA 2 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 2")
  33. ma2_len = input.int(50, "MA 2 Length", minval=1, group="MA 2")
  34. ma2_mtf = input.bool(false, "MA 2 Use Higher Timeframe (MTF)", group="MA 2")
  35. ma2_tf = input.timeframe("240", "MA 2 Timeframe", group="MA 2", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  36. ma2_color = input.color(#ff9800, "MA 2 Color", group="MA 2")
  37. ma2_width = input.int(2, "MA 2 Line Width", minval=1, maxval=5, group="MA 2")
  38.  
  39. ma3_show = input.bool(true, "Show MA 3", group="MA 3")
  40. ma3_type = input.string("SMA", "MA 3 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 3")
  41. ma3_len = input.int(200, "MA 3 Length", minval=1, group="MA 3")
  42. ma3_mtf = input.bool(false, "MA 3 Use Higher Timeframe (MTF)", group="MA 3")
  43. ma3_tf = input.timeframe("D", "MA 3 Timeframe", group="MA 3", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  44. ma3_color = input.color(#ffffff, "MA 3 Color", group="MA 3")
  45. ma3_width = input.int(3, "MA 3 Line Width", minval=1, maxval=5, group="MA 3")
  46.  
  47. ma4_show = input.bool(false, "Show MA 4", group="MA 4")
  48. ma4_type = input.string("EMA", "MA 4 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 4")
  49. ma4_len = input.int(9, "MA 4 Length", minval=1, group="MA 4")
  50. ma4_mtf = input.bool(false, "MA 4 Use Higher Timeframe (MTF)", group="MA 4")
  51. ma4_tf = input.timeframe("60", "MA 4 Timeframe", group="MA 4", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  52. ma4_color = input.color(#00e676, "MA 4 Color", group="MA 4")
  53. ma4_width = input.int(2, "MA 4 Line Width", minval=1, maxval=5, group="MA 4")
  54.  
  55. ma5_show = input.bool(false, "Show MA 5", group="MA 5")
  56. ma5_type = input.string("WMA", "MA 5 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 5")
  57. ma5_len = input.int(100, "MA 5 Length", minval=1, group="MA 5")
  58. ma5_mtf = input.bool(false, "MA 5 Use Higher Timeframe (MTF)", group="MA 5")
  59. ma5_tf = input.timeframe("240", "MA 5 Timeframe", group="MA 5", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  60. ma5_color = input.color(#e040fb, "MA 5 Color", group="MA 5")
  61. ma5_width = input.int(2, "MA 5 Line Width", minval=1, maxval=5, group="MA 5")
  62.  
  63. ma6_show = input.bool(false, "Show MA 6", group="MA 6")
  64. ma6_type = input.string("HMA", "MA 6 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 6")
  65. ma6_len = input.int(21, "MA 6 Length", minval=1, group="MA 6")
  66. ma6_mtf = input.bool(false, "MA 6 Use Higher Timeframe (MTF)", group="MA 6")
  67. ma6_tf = input.timeframe("D", "MA 6 Timeframe", group="MA 6", tooltip="Only used when MTF is on. Must be equal to or higher than the chart timeframe, otherwise the chart-timeframe average is shown.")
  68. ma6_color = input.color(#ff4081, "MA 6 Color", group="MA 6")
  69. ma6_width = input.int(2, "MA 6 Line Width", minval=1, maxval=5, group="MA 6")
  70.  
  71. // ==========================================
  72. // CALCULATIONS
  73. // ==========================================
  74. // VWAP anchor: a bar where the running calculation restarts
  75. bool anchor_bar = switch vwap_anchor
  76. "Weekly" => timeframe.change("W")
  77. "Timestamp" => time >= vwap_ts and (na(time[1]) or time[1] < vwap_ts)
  78. => timeframe.change("D")
  79.  
  80. float vwap_val = ta.vwap(hlc3, anchor_bar)
  81. // In Timestamp mode nothing is drawn before the anchor
  82. bool vwap_visible = vwap_show and (vwap_anchor != "Timestamp" or time >= vwap_ts)
  83.  
  84. f_ma(string maType, int length) =>
  85. switch maType
  86. "SMA" => ta.sma(close, length)
  87. "EMA" => ta.ema(close, length)
  88. "WMA" => ta.wma(close, length)
  89. "HMA" => ta.hma(close, length)
  90. "RMA" => ta.rma(close, length)
  91. "VWMA" => ta.vwma(close, length)
  92. "DEMA" => 2 * ta.ema(close, length) - ta.ema(ta.ema(close, length), length)
  93. "TEMA" => 3 * (ta.ema(close, length) - ta.ema(ta.ema(close, length), length)) + ta.ema(ta.ema(ta.ema(close, length), length), length)
  94. "ZLEMA" => ta.ema(close + (close - close[math.round((length - 1) / 2)]), length)
  95. "LinReg" => ta.linreg(close, length, 0)
  96. => ta.sma(close, length)
  97.  
  98. // Each average: chart-timeframe value, or the higher-timeframe value when its MTF toggle is on.
  99. // The higher-timeframe request only runs for averages that actually have MTF switched on.
  100. float ma1_c = f_ma(ma1_type, ma1_len)
  101. bool ma1_use = ma1_mtf and timeframe.in_seconds(ma1_tf) >= timeframe.in_seconds()
  102. float ma1_rt = ma1_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma1_tf, ma1_c, gaps=barmerge.gaps_off) : na
  103. float ma1_np = ma1_use and mtf_confirmed ? request.security(syminfo.tickerid, ma1_tf, ma1_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  104. float ma1 = ma1_use ? (mtf_confirmed ? ma1_np : ma1_rt) : ma1_c
  105.  
  106. float ma2_c = f_ma(ma2_type, ma2_len)
  107. bool ma2_use = ma2_mtf and timeframe.in_seconds(ma2_tf) >= timeframe.in_seconds()
  108. float ma2_rt = ma2_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma2_tf, ma2_c, gaps=barmerge.gaps_off) : na
  109. float ma2_np = ma2_use and mtf_confirmed ? request.security(syminfo.tickerid, ma2_tf, ma2_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  110. float ma2 = ma2_use ? (mtf_confirmed ? ma2_np : ma2_rt) : ma2_c
  111.  
  112. float ma3_c = f_ma(ma3_type, ma3_len)
  113. bool ma3_use = ma3_mtf and timeframe.in_seconds(ma3_tf) >= timeframe.in_seconds()
  114. float ma3_rt = ma3_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma3_tf, ma3_c, gaps=barmerge.gaps_off) : na
  115. float ma3_np = ma3_use and mtf_confirmed ? request.security(syminfo.tickerid, ma3_tf, ma3_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  116. float ma3 = ma3_use ? (mtf_confirmed ? ma3_np : ma3_rt) : ma3_c
  117.  
  118. float ma4_c = f_ma(ma4_type, ma4_len)
  119. bool ma4_use = ma4_mtf and timeframe.in_seconds(ma4_tf) >= timeframe.in_seconds()
  120. float ma4_rt = ma4_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma4_tf, ma4_c, gaps=barmerge.gaps_off) : na
  121. float ma4_np = ma4_use and mtf_confirmed ? request.security(syminfo.tickerid, ma4_tf, ma4_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  122. float ma4 = ma4_use ? (mtf_confirmed ? ma4_np : ma4_rt) : ma4_c
  123.  
  124. float ma5_c = f_ma(ma5_type, ma5_len)
  125. bool ma5_use = ma5_mtf and timeframe.in_seconds(ma5_tf) >= timeframe.in_seconds()
  126. float ma5_rt = ma5_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma5_tf, ma5_c, gaps=barmerge.gaps_off) : na
  127. float ma5_np = ma5_use and mtf_confirmed ? request.security(syminfo.tickerid, ma5_tf, ma5_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  128. float ma5 = ma5_use ? (mtf_confirmed ? ma5_np : ma5_rt) : ma5_c
  129.  
  130. float ma6_c = f_ma(ma6_type, ma6_len)
  131. bool ma6_use = ma6_mtf and timeframe.in_seconds(ma6_tf) >= timeframe.in_seconds()
  132. float ma6_rt = ma6_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma6_tf, ma6_c, gaps=barmerge.gaps_off) : na
  133. float ma6_np = ma6_use and mtf_confirmed ? request.security(syminfo.tickerid, ma6_tf, ma6_c[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : na
  134. float ma6 = ma6_use ? (mtf_confirmed ? ma6_np : ma6_rt) : ma6_c
  135.  
  136. // ==========================================
  137. // PLOTS
  138. // ==========================================
  139. plot(vwap_visible ? vwap_val : na, "VWAP", color=vwap_color, linewidth=vwap_width)
  140. plot(ma1_show ? ma1 : na, "MA 1", color=ma1_color, linewidth=ma1_width)
  141. plot(ma2_show ? ma2 : na, "MA 2", color=ma2_color, linewidth=ma2_width)
  142. plot(ma3_show ? ma3 : na, "MA 3", color=ma3_color, linewidth=ma3_width)
  143. plot(ma4_show ? ma4 : na, "MA 4", color=ma4_color, linewidth=ma4_width)
  144. plot(ma5_show ? ma5 : na, "MA 5", color=ma5_color, linewidth=ma5_width)
  145. plot(ma6_show ? ma6 : na, "MA 6", color=ma6_color, linewidth=ma6_width)
  146.  
Add Comment
Please, Sign In to add comment