Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- // By using this or any TheBTCBeast indicator
- // The user assumes all risks and responsibilities
- indicator("VWAP & Moving Averages - The BTC Beast", overlay = true)
- // ==========================================
- // VWAP
- // ==========================================
- vwap_show = input.bool(true, "Show VWAP", group="VWAP")
- vwap_anchor = input.string("Daily", "VWAP Anchor", options=["Daily", "Weekly", "Timestamp"], group="VWAP",
- 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.")
- vwap_ts = input.time(timestamp("1 Oct 2026 00:00 +0000"), "Anchor Timestamp (used when anchor = Timestamp)", group="VWAP")
- vwap_color = input.color(#00e5ff, "VWAP Color", group="VWAP")
- vwap_width = input.int(2, "VWAP Line Width", minval=1, maxval=5, group="VWAP")
- // ==========================================
- // MOVING AVERAGES (6 slots: toggle, type, length, optional higher timeframe)
- // Types: SMA, EMA, WMA, HMA (Hull), RMA (Wilder/SMMA), VWMA, DEMA, TEMA, ZLEMA (zero-lag EMA), LinReg (least squares)
- // ==========================================
- mtf_confirmed = input.bool(true, "MTF: Use Confirmed (Non-Repainting) Values", group="MTF Settings",
- 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.")
- ma1_show = input.bool(true, "Show MA 1", group="MA 1")
- ma1_type = input.string("EMA", "MA 1 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 1")
- ma1_len = input.int(20, "MA 1 Length", minval=1, group="MA 1")
- ma1_mtf = input.bool(false, "MA 1 Use Higher Timeframe (MTF)", group="MA 1")
- 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.")
- ma1_color = input.color(#ffeb3b, "MA 1 Color", group="MA 1")
- ma1_width = input.int(2, "MA 1 Line Width", minval=1, maxval=5, group="MA 1")
- ma2_show = input.bool(true, "Show MA 2", group="MA 2")
- ma2_type = input.string("EMA", "MA 2 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 2")
- ma2_len = input.int(50, "MA 2 Length", minval=1, group="MA 2")
- ma2_mtf = input.bool(false, "MA 2 Use Higher Timeframe (MTF)", group="MA 2")
- 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.")
- ma2_color = input.color(#ff9800, "MA 2 Color", group="MA 2")
- ma2_width = input.int(2, "MA 2 Line Width", minval=1, maxval=5, group="MA 2")
- ma3_show = input.bool(true, "Show MA 3", group="MA 3")
- ma3_type = input.string("SMA", "MA 3 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 3")
- ma3_len = input.int(200, "MA 3 Length", minval=1, group="MA 3")
- ma3_mtf = input.bool(false, "MA 3 Use Higher Timeframe (MTF)", group="MA 3")
- 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.")
- ma3_color = input.color(#ffffff, "MA 3 Color", group="MA 3")
- ma3_width = input.int(3, "MA 3 Line Width", minval=1, maxval=5, group="MA 3")
- ma4_show = input.bool(false, "Show MA 4", group="MA 4")
- ma4_type = input.string("EMA", "MA 4 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 4")
- ma4_len = input.int(9, "MA 4 Length", minval=1, group="MA 4")
- ma4_mtf = input.bool(false, "MA 4 Use Higher Timeframe (MTF)", group="MA 4")
- 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.")
- ma4_color = input.color(#00e676, "MA 4 Color", group="MA 4")
- ma4_width = input.int(2, "MA 4 Line Width", minval=1, maxval=5, group="MA 4")
- ma5_show = input.bool(false, "Show MA 5", group="MA 5")
- ma5_type = input.string("WMA", "MA 5 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 5")
- ma5_len = input.int(100, "MA 5 Length", minval=1, group="MA 5")
- ma5_mtf = input.bool(false, "MA 5 Use Higher Timeframe (MTF)", group="MA 5")
- 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.")
- ma5_color = input.color(#e040fb, "MA 5 Color", group="MA 5")
- ma5_width = input.int(2, "MA 5 Line Width", minval=1, maxval=5, group="MA 5")
- ma6_show = input.bool(false, "Show MA 6", group="MA 6")
- ma6_type = input.string("HMA", "MA 6 Type", options=["SMA", "EMA", "WMA", "HMA", "RMA", "VWMA", "DEMA", "TEMA", "ZLEMA", "LinReg"], group="MA 6")
- ma6_len = input.int(21, "MA 6 Length", minval=1, group="MA 6")
- ma6_mtf = input.bool(false, "MA 6 Use Higher Timeframe (MTF)", group="MA 6")
- 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.")
- ma6_color = input.color(#ff4081, "MA 6 Color", group="MA 6")
- ma6_width = input.int(2, "MA 6 Line Width", minval=1, maxval=5, group="MA 6")
- // ==========================================
- // CALCULATIONS
- // ==========================================
- // VWAP anchor: a bar where the running calculation restarts
- bool anchor_bar = switch vwap_anchor
- "Weekly" => timeframe.change("W")
- "Timestamp" => time >= vwap_ts and (na(time[1]) or time[1] < vwap_ts)
- => timeframe.change("D")
- float vwap_val = ta.vwap(hlc3, anchor_bar)
- // In Timestamp mode nothing is drawn before the anchor
- bool vwap_visible = vwap_show and (vwap_anchor != "Timestamp" or time >= vwap_ts)
- f_ma(string maType, int length) =>
- switch maType
- "SMA" => ta.sma(close, length)
- "EMA" => ta.ema(close, length)
- "WMA" => ta.wma(close, length)
- "HMA" => ta.hma(close, length)
- "RMA" => ta.rma(close, length)
- "VWMA" => ta.vwma(close, length)
- "DEMA" => 2 * ta.ema(close, length) - ta.ema(ta.ema(close, length), length)
- "TEMA" => 3 * (ta.ema(close, length) - ta.ema(ta.ema(close, length), length)) + ta.ema(ta.ema(ta.ema(close, length), length), length)
- "ZLEMA" => ta.ema(close + (close - close[math.round((length - 1) / 2)]), length)
- "LinReg" => ta.linreg(close, length, 0)
- => ta.sma(close, length)
- // Each average: chart-timeframe value, or the higher-timeframe value when its MTF toggle is on.
- // The higher-timeframe request only runs for averages that actually have MTF switched on.
- float ma1_c = f_ma(ma1_type, ma1_len)
- bool ma1_use = ma1_mtf and timeframe.in_seconds(ma1_tf) >= timeframe.in_seconds()
- float ma1_rt = ma1_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma1_tf, ma1_c, gaps=barmerge.gaps_off) : na
- 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
- float ma1 = ma1_use ? (mtf_confirmed ? ma1_np : ma1_rt) : ma1_c
- float ma2_c = f_ma(ma2_type, ma2_len)
- bool ma2_use = ma2_mtf and timeframe.in_seconds(ma2_tf) >= timeframe.in_seconds()
- float ma2_rt = ma2_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma2_tf, ma2_c, gaps=barmerge.gaps_off) : na
- 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
- float ma2 = ma2_use ? (mtf_confirmed ? ma2_np : ma2_rt) : ma2_c
- float ma3_c = f_ma(ma3_type, ma3_len)
- bool ma3_use = ma3_mtf and timeframe.in_seconds(ma3_tf) >= timeframe.in_seconds()
- float ma3_rt = ma3_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma3_tf, ma3_c, gaps=barmerge.gaps_off) : na
- 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
- float ma3 = ma3_use ? (mtf_confirmed ? ma3_np : ma3_rt) : ma3_c
- float ma4_c = f_ma(ma4_type, ma4_len)
- bool ma4_use = ma4_mtf and timeframe.in_seconds(ma4_tf) >= timeframe.in_seconds()
- float ma4_rt = ma4_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma4_tf, ma4_c, gaps=barmerge.gaps_off) : na
- 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
- float ma4 = ma4_use ? (mtf_confirmed ? ma4_np : ma4_rt) : ma4_c
- float ma5_c = f_ma(ma5_type, ma5_len)
- bool ma5_use = ma5_mtf and timeframe.in_seconds(ma5_tf) >= timeframe.in_seconds()
- float ma5_rt = ma5_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma5_tf, ma5_c, gaps=barmerge.gaps_off) : na
- 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
- float ma5 = ma5_use ? (mtf_confirmed ? ma5_np : ma5_rt) : ma5_c
- float ma6_c = f_ma(ma6_type, ma6_len)
- bool ma6_use = ma6_mtf and timeframe.in_seconds(ma6_tf) >= timeframe.in_seconds()
- float ma6_rt = ma6_use and not mtf_confirmed ? request.security(syminfo.tickerid, ma6_tf, ma6_c, gaps=barmerge.gaps_off) : na
- 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
- float ma6 = ma6_use ? (mtf_confirmed ? ma6_np : ma6_rt) : ma6_c
- // ==========================================
- // PLOTS
- // ==========================================
- plot(vwap_visible ? vwap_val : na, "VWAP", color=vwap_color, linewidth=vwap_width)
- plot(ma1_show ? ma1 : na, "MA 1", color=ma1_color, linewidth=ma1_width)
- plot(ma2_show ? ma2 : na, "MA 2", color=ma2_color, linewidth=ma2_width)
- plot(ma3_show ? ma3 : na, "MA 3", color=ma3_color, linewidth=ma3_width)
- plot(ma4_show ? ma4 : na, "MA 4", color=ma4_color, linewidth=ma4_width)
- plot(ma5_show ? ma5 : na, "MA 5", color=ma5_color, linewidth=ma5_width)
- plot(ma6_show ? ma6 : na, "MA 6", color=ma6_color, linewidth=ma6_width)
Add Comment
Please, Sign In to add comment