MA Ribbon Comparison: 6 MA Types on 4 Shared Lengths

cryptosquanch · study · 460 行 · 点赞 2 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cryptosquanch
 
//@version=6
indicator(
     "MA Ribbon Comparison: 6 MA Types on 4 Shared Lengths",
     shorttitle = "MA Ribbon Comparison",
     overlay = true,
     max_labels_count = 500,
     max_lines_count = 500
)
 
//══════════════════════════════════════════════════════════════════════════════
// 1) Indicator Guide
//══════════════════════════════════════════════════════════════════════════════
guideGroup = "📘 Indicator Guide"
 
guideIntro = input.text_area(
     "MA RIBBON COMPARISON INDICATOR\n\n" +
     "STEP 1: Click the 3 dots on the settings of this indicator and adjust the pinned-to-scale settings if needed.\n" +
     "STEP 2: Use the MA Slot Visuals section to customize slot visibility, colors, widths, and styles.\n" +
     "STEP 3: Use the Show / Hide MA Sets section to control which moving-average families are visible.\n\n" +
     "This indicator lays all six moving-average types on top of the same four MA slots so you can compare how each one behaves under the same conditions.\n\n" +
     "HOW IT WORKS\n" +
     "• MA #1, MA #2, MA #3, and MA #4 each have one shared length, one shared source, and one shared color.\n" +
     "• For each of those four MA slots, the script plots six MA types: SMA, EMA, SMMA (RMA), WMA, VWMA, and HMA.\n" +
     "• That means the chart can display 24 lines total: 4 slots × 6 MA types.\n" +
     "• The whole point is comparison. You are seeing how different moving-average methods react when they are given the same source and same length.\n\n" +
     "When the lines bunch up, the herd agrees. When they spread apart, each critter shows its own temperament.\n",
     "Read Me First",
     group = guideGroup,
     active = false,
     tooltip = "Overview of what the indicator does and how the MA comparison works."
)
 
guideMaMath = input.text_area(
     "MA TYPE GUIDE\n\n" +
     "SMA — SIMPLE MOVING AVERAGE\n" +
     "• Equal weight to every bar in the lookback.\n" +
     "• Formula idea: add the last N prices, divide by N.\n" +
     "• Tends to be smooth and straightforward, but slower to react.\n" +
     "• Think of SMA as the steady ranch hand who treats every hoofprint the same.\n\n" +
     "EMA — EXPONENTIAL MOVING AVERAGE\n" +
     "• More weight on recent prices.\n" +
     "• Formula idea: new EMA = price × factor + previous EMA × remaining factor.\n" +
     "• Tends to react faster to new moves than SMA.\n" +
     "• Think of EMA as the quick-draw cowboy who cares most about the freshest dust on the trail.\n\n" +
     "SMMA (RMA) — SMOOTHED MOVING AVERAGE\n" +
     "• More heavily smoothed than EMA.\n" +
     "• Formula idea: previous average carries strongly into the next value.\n" +
     "• Tends to move slower and filter more noise.\n" +
     "• Think of SMMA as the old trail boss who takes his sweet time and smooths out the commotion.\n\n" +
     "WMA — WEIGHTED MOVING AVERAGE\n" +
     "• More recent bars get bigger linear weights.\n" +
     "• Formula idea: newest bars count more using fixed increasing weights.\n" +
     "• Tends to react faster than SMA.\n" +
     "• Think of WMA as the eager ranch dog that leans hard toward the newest move.\n\n" +
     "VWMA — VOLUME WEIGHTED MOVING AVERAGE\n" +
     "• Prices from higher-volume bars matter more.\n" +
     "• Formula idea: sum(price × volume) divided by sum(volume).\n" +
     "• Useful when you want volume to influence the average.\n" +
     "• Think of VWMA as the saloon owner who only listens when the whole crowd gets loud with volume.\n\n" +
     "HMA — HULL MOVING AVERAGE\n" +
     "• Designed to reduce lag while staying smooth.\n" +
     "• Formula idea: combines weighted averages and smooths the result using the square root of the length.\n" +
     "• Tends to turn quickly while still looking cleaner than many fast averages.\n" +
     "• Think of HMA as the sharp-eyed scout that spots a turn in the trail before the rest of the posse.\n\n" +
     "HOW TO READ THE COMPARISON\n" +
     "• Faster methods usually turn first. Slower methods usually confirm later.\n" +
     "• If the herd is stampeding, EMA, WMA, and HMA often lead.\n" +
     "• If the trail is choppy, SMMA may stay calmer.\n" +
     "• VWMA can behave differently when the crowd gets noisy and volume swells.\n",
     "How The MA Types Differ",
     group = guideGroup,
     active = false,
     tooltip = "Brief explanation of how each moving average is calculated and how it behaves."
)
 
guideStyle = input.text_area(
     "VISUAL STYLE GUIDE\n\n" +
     "• You can control each MA slot's visibility and color from the MA Slot Visuals section.\n" +
     "• You can also control each MA type's width and line style from the same section.\n" +
     "• Available built-in line styles are Solid, Dashed, and Dotted.\n" +
     "• Each MA method keeps one shared visual style across all four MA slots so comparisons stay easy to read.\n\n" +
     "Think of it like four cattle brands, with six different riders all trying to round up the same herd.\n",
     "How To Read The Styling",
     group = guideGroup,
     active = false,
     tooltip = "Explains how the visual styling works."
)
 
//══════════════════════════════════════════════════════════════════════════════
// 2) Timeframe
//══════════════════════════════════════════════════════════════════════════════
tfGroup = "🕰 Timeframe"
 
tfInput = input.string(
     "Chart",
     "Calculation timeframe",
     options = ["Chart", "1s", "1m", "5m", "15m", "30m", "1h", "2h", "3h", "4h", "6h", "8h", "12h", "D", "W", "M"],
     group = tfGroup,
     tooltip = "Choose the timeframe used to calculate all moving averages. 'Chart' uses the chart timeframe."
)
 
tfResolved = switch tfInput
    "Chart" => timeframe.period
    "1s"    => "1S"
    "1m"    => "1"
    "5m"    => "5"
    "15m"   => "15"
    "30m"   => "30"
    "1h"    => "60"
    "2h"    => "120"
    "3h"    => "180"
    "4h"    => "240"
    "6h"    => "360"
    "8h"    => "480"
    "12h"   => "720"
    "D"     => "D"
    "W"     => "W"
    "M"     => "M"
    => timeframe.period
 
//══════════════════════════════════════════════════════════════════════════════
// 3) Visibility Toggles
//══════════════════════════════════════════════════════════════════════════════
toggleGroup = "👀 Show / Hide MA Sets"
 
showSmaSet = input.bool(true, "Show SMA set", group = toggleGroup, tooltip = "Shows all enabled SMA slot lines.")
showEmaSet = input.bool(true, "Show EMA set", group = toggleGroup, tooltip = "Shows all enabled EMA slot lines.")
showSmmaSet = input.bool(true, "Show SMMA (RMA) set", group = toggleGroup, tooltip = "Shows all enabled SMMA / RMA slot lines.")
showWmaSet = input.bool(false, "Show WMA set", group = toggleGroup, tooltip = "Shows all enabled WMA slot lines.")
showVwmaSet = input.bool(false, "Show VWMA set", group = toggleGroup, tooltip = "Shows all enabled VWMA slot lines.")
showHmaSet = input.bool(false, "Show HMA set", group = toggleGroup, tooltip = "Shows all enabled HMA slot lines.")
 
showQuickRef = input.bool(true, "Show top-right quick reference panel", group = toggleGroup, tooltip = "Shows a compact legend and settings summary in the top-right corner.")
 
//══════════════════════════════════════════════════════════════════════════════
// 4) MA Slot Visuals
//══════════════════════════════════════════════════════════════════════════════
visualGroup = "🎨 MA Slot Visuals"
 
// Slot visibility controls
showMa1Slot = input.bool(true, "Show MA #1", group = visualGroup, inline = "slot1", tooltip = "Turns MA #1 on or off across all MA types.")
ma1Color = input.color(color.new(#00e5ff, 0), "MA #1 color", group = visualGroup, inline = "slot1", tooltip = "Shared color for all MA #1 lines.")
 
showMa2Slot = input.bool(true, "Show MA #2", group = visualGroup, inline = "slot2", tooltip = "Turns MA #2 on or off across all MA types.")
ma2Color = input.color(color.new(#00ff66, 0), "MA #2 color", group = visualGroup, inline = "slot2", tooltip = "Shared color for all MA #2 lines.")
 
showMa3Slot = input.bool(true, "Show MA #3", group = visualGroup, inline = "slot3", tooltip = "Turns MA #3 on or off across all MA types.")
ma3Color = input.color(color.new(#ff6a00, 0), "MA #3 color", group = visualGroup, inline = "slot3", tooltip = "Shared color for all MA #3 lines.")
 
showMa4Slot = input.bool(false, "Show MA #4", group = visualGroup, inline = "slot4", tooltip = "Turns MA #4 on or off across all MA types.")
ma4Color = input.color(color.new(#ffe600, 0), "MA #4 color", group = visualGroup, inline = "slot4", tooltip = "Shared color for all MA #4 lines.")
 
// Per-MA-type visual controls
smaWidth = input.int(1, "SMA width", minval = 1, maxval = 5, group = visualGroup, inline = "smaVis", tooltip = "Default line width for all SMA plots.")
smaStyleInput = input.string("Solid", "SMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "smaVis", tooltip = "Default line style for all SMA plots.")
 
emaWidth = input.int(2, "EMA width", minval = 1, maxval = 5, group = visualGroup, inline = "emaVis", tooltip = "Default line width for all EMA plots.")
emaStyleInput = input.string("Solid", "EMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "emaVis", tooltip = "Default line style for all EMA plots.")
 
smmaWidth = input.int(2, "SMMA width", minval = 1, maxval = 5, group = visualGroup, inline = "smmaVis", tooltip = "Default line width for all SMMA plots.")
smmaStyleInput = input.string("Dotted", "SMMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "smmaVis", tooltip = "Default line style for all SMMA plots.")
 
wmaWidth = input.int(1, "WMA width", minval = 1, maxval = 5, group = visualGroup, inline = "wmaVis", tooltip = "Default line width for all WMA plots.")
wmaStyleInput = input.string("Dashed", "WMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "wmaVis", tooltip = "Default line style for all WMA plots.")
 
vwmaWidth = input.int(2, "VWMA width", minval = 1, maxval = 5, group = visualGroup, inline = "vwmaVis", tooltip = "Default line width for all VWMA plots.")
vwmaStyleInput = input.string("Dashed", "VWMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "vwmaVis", tooltip = "Default line style for all VWMA plots.")
 
hmaWidth = input.int(1, "HMA width", minval = 1, maxval = 5, group = visualGroup, inline = "hmaVis", tooltip = "Default line width for all HMA plots.")
hmaStyleInput = input.string("Dotted", "HMA style", options = ["Solid", "Dashed", "Dotted"], group = visualGroup, inline = "hmaVis", tooltip = "Default line style for all HMA plots.")
 
//══════════════════════════════════════════════════════════════════════════════
// 5) MA Slot Sources
//══════════════════════════════════════════════════════════════════════════════
sourceGroup = "🔎 MA Slot Sources"
 
ma1SourceInput = input.string("Close", "MA #1 source", options = ["Open", "High", "Low", "Close", "HL2", "HLC3", "OHLC4", "HLCC4"], group = sourceGroup, tooltip = "Source used by all MA #1 lines across all MA methods.")
ma2SourceInput = input.string("Close", "MA #2 source", options = ["Open", "High", "Low", "Close", "HL2", "HLC3", "OHLC4", "HLCC4"], group = sourceGroup, tooltip = "Source used by all MA #2 lines across all MA methods.")
ma3SourceInput = input.string("Close", "MA #3 source", options = ["Open", "High", "Low", "Close", "HL2", "HLC3", "OHLC4", "HLCC4"], group = sourceGroup, tooltip = "Source used by all MA #3 lines across all MA methods.")
ma4SourceInput = input.string("Close", "MA #4 source", options = ["Open", "High", "Low", "Close", "HL2", "HLC3", "OHLC4", "HLCC4"], group = sourceGroup, tooltip = "Source used by all MA #4 lines across all MA methods.")
 
//══════════════════════════════════════════════════════════════════════════════
// 6) MA Slot Lengths
//══════════════════════════════════════════════════════════════════════════════
lengthGroup = "📏 MA Slot Lengths"
 
ma1Len = input.int(5, "MA #1 length", minval = 1, group = lengthGroup, tooltip = "Shared length for all MA #1 lines.")
ma2Len = input.int(25, "MA #2 length", minval = 1, group = lengthGroup, tooltip = "Shared length for all MA #2 lines.")
ma3Len = input.int(200, "MA #3 length", minval = 1, group = lengthGroup, tooltip = "Shared length for all MA #3 lines.")
ma4Len = input.int(400, "MA #4 length", minval = 1, group = lengthGroup, tooltip = "Shared length for all MA #4 lines.")
 
//══════════════════════════════════════════════════════════════════════════════
// Utilities
//══════════════════════════════════════════════════════════════════════════════
srcFromName(_name) =>
    switch _name
        "Open"  => open
        "High"  => high
        "Low"   => low
        "Close" => close
        "HL2"   => hl2
        "HLC3"  => hlc3
        "OHLC4" => ohlc4
        "HLCC4" => hlcc4
        => close
 
plotStyleFromName(_style) =>
    switch _style
        "Solid"  => plot.linestyle_solid
        "Dashed" => plot.linestyle_dashed
        "Dotted" => plot.linestyle_dotted
        => plot.linestyle_solid
 
smaStyle  = plotStyleFromName(smaStyleInput)
emaStyle  = plotStyleFromName(emaStyleInput)
smmaStyle = plotStyleFromName(smmaStyleInput)
wmaStyle  = plotStyleFromName(wmaStyleInput)
vwmaStyle = plotStyleFromName(vwmaStyleInput)
hmaStyle  = plotStyleFromName(hmaStyleInput)
 
ma1Source = srcFromName(ma1SourceInput)
ma2Source = srcFromName(ma2SourceInput)
ma3Source = srcFromName(ma3SourceInput)
ma4Source = srcFromName(ma4SourceInput)
 
maCalc(_source, _length, _type) =>
    switch _type
        "SMA"        => ta.sma(_source, _length)
        "EMA"        => ta.ema(_source, _length)
        "SMMA (RMA)" => ta.rma(_source, _length)
        "WMA"        => ta.wma(_source, _length)
        "VWMA"       => ta.vwma(_source, _length)
        "HMA"        => ta.hma(_source, _length)
        => na
 
maFromTf(_source, _length, _type, _tf) =>
    request.security(syminfo.tickerid, _tf, maCalc(_source, _length, _type), gaps = barmerge.gaps_on)
 
//══════════════════════════════════════════════════════════════════════════════
// MA Calculations
//══════════════════════════════════════════════════════════════════════════════
sma1 = maFromTf(ma1Source, ma1Len, "SMA", tfResolved)
sma2 = maFromTf(ma2Source, ma2Len, "SMA", tfResolved)
sma3 = maFromTf(ma3Source, ma3Len, "SMA", tfResolved)
sma4 = maFromTf(ma4Source, ma4Len, "SMA", tfResolved)
 
ema1 = maFromTf(ma1Source, ma1Len, "EMA", tfResolved)
ema2 = maFromTf(ma2Source, ma2Len, "EMA", tfResolved)
ema3 = maFromTf(ma3Source, ma3Len, "EMA", tfResolved)
ema4 = maFromTf(ma4Source, ma4Len, "EMA", tfResolved)
 
smma1 = maFromTf(ma1Source, ma1Len, "SMMA (RMA)", tfResolved)
smma2 = maFromTf(ma2Source, ma2Len, "SMMA (RMA)", tfResolved)
smma3 = maFromTf(ma3Source, ma3Len, "SMMA (RMA)", tfResolved)
smma4 = maFromTf(ma4Source, ma4Len, "SMMA (RMA)", tfResolved)
 
wma1 = maFromTf(ma1Source, ma1Len, "WMA", tfResolved)
wma2 = maFromTf(ma2Source, ma2Len, "WMA", tfResolved)
wma3 = maFromTf(ma3Source, ma3Len, "WMA", tfResolved)
wma4 = maFromTf(ma4Source, ma4Len, "WMA", tfResolved)
 
vwma1 = maFromTf(ma1Source, ma1Len, "VWMA", tfResolved)
vwma2 = maFromTf(ma2Source, ma2Len, "VWMA", tfResolved)
vwma3 = maFromTf(ma3Source, ma3Len, "VWMA", tfResolved)
vwma4 = maFromTf(ma4Source, ma4Len, "VWMA", tfResolved)
 
hma1 = maFromTf(ma1Source, ma1Len, "HMA", tfResolved)
hma2 = maFromTf(ma2Source, ma2Len, "HMA", tfResolved)
hma3 = maFromTf(ma3Source, ma3Len, "HMA", tfResolved)
hma4 = maFromTf(ma4Source, ma4Len, "HMA", tfResolved)
 
//══════════════════════════════════════════════════════════════════════════════
// Method Disagreement Analysis
//══════════════════════════════════════════════════════════════════════════════
envGroup = "📐 Method Disagreement"
 
showEnvelope = input.bool(true, "Show per-slot disagreement envelope", group = envGroup, tooltip = "Shades the band between the highest and the lowest of the six MA methods for each visible slot. A wide band means the averaging methods disagree. A thin band means they agree.")
envAtrLen = input.int(14, "ATR length for spread normalization", minval = 1, group = envGroup, tooltip = "The distance between the highest and lowest method is divided by ATR so the spread can be compared across symbols and timeframes.")
envTransp = input.int(88, "Envelope transparency", minval = 0, maxval = 100, group = envGroup, tooltip = "Transparency of the envelope fill. 100 = invisible.")
 
atrNorm = ta.atr(envAtrLen)
 
slotHi(_a, _b, _c, _d, _e, _f) =>
    math.max(_a, _b, _c, _d, _e, _f)
 
slotLo(_a, _b, _c, _d, _e, _f) =>
    math.min(_a, _b, _c, _d, _e, _f)
 
methodAt(_v, _sma, _ema, _smma, _wma, _vwma, _hma) =>
    na(_v) ? "n/a" : _v == _sma ? "SMA" : _v == _ema ? "EMA" : _v == _smma ? "SMMA" : _v == _wma ? "WMA" : _v == _vwma ? "VWMA" : "HMA"
 
spreadAtr(_hi, _lo) =>
    atrNorm > 0 and not na(_hi) and not na(_lo) ? (_hi - _lo) / atrNorm : na
 
hi1 = slotHi(sma1, ema1, smma1, wma1, vwma1, hma1)
lo1 = slotLo(sma1, ema1, smma1, wma1, vwma1, hma1)
hi2 = slotHi(sma2, ema2, smma2, wma2, vwma2, hma2)
lo2 = slotLo(sma2, ema2, smma2, wma2, vwma2, hma2)
hi3 = slotHi(sma3, ema3, smma3, wma3, vwma3, hma3)
lo3 = slotLo(sma3, ema3, smma3, wma3, vwma3, hma3)
hi4 = slotHi(sma4, ema4, smma4, wma4, vwma4, hma4)
lo4 = slotLo(sma4, ema4, smma4, wma4, vwma4, hma4)
 
pHi1 = plot(showEnvelope and showMa1Slot ? hi1 : na, title = "Envelope high MA #1", color = na, editable = false)
pLo1 = plot(showEnvelope and showMa1Slot ? lo1 : na, title = "Envelope low MA #1", color = na, editable = false)
pHi2 = plot(showEnvelope and showMa2Slot ? hi2 : na, title = "Envelope high MA #2", color = na, editable = false)
pLo2 = plot(showEnvelope and showMa2Slot ? lo2 : na, title = "Envelope low MA #2", color = na, editable = false)
pHi3 = plot(showEnvelope and showMa3Slot ? hi3 : na, title = "Envelope high MA #3", color = na, editable = false)
pLo3 = plot(showEnvelope and showMa3Slot ? lo3 : na, title = "Envelope low MA #3", color = na, editable = false)
pHi4 = plot(showEnvelope and showMa4Slot ? hi4 : na, title = "Envelope high MA #4", color = na, editable = false)
pLo4 = plot(showEnvelope and showMa4Slot ? lo4 : na, title = "Envelope low MA #4", color = na, editable = false)
 
fill(pHi1, pLo1, color = color.new(ma1Color, envTransp), title = "Envelope fill MA #1")
fill(pHi2, pLo2, color = color.new(ma2Color, envTransp), title = "Envelope fill MA #2")
fill(pHi3, pLo3, color = color.new(ma3Color, envTransp), title = "Envelope fill MA #3")
fill(pHi4, pLo4, color = color.new(ma4Color, envTransp), title = "Envelope fill MA #4")
 
//══════════════════════════════════════════════════════════════════════════════
// Plots
//══════════════════════════════════════════════════════════════════════════════
plot(showSmaSet and showMa1Slot ? sma1 : na, title = "SMA MA #1", color = ma1Color, linewidth = smaWidth, linestyle = smaStyle)
plot(showSmaSet and showMa2Slot ? sma2 : na, title = "SMA MA #2", color = ma2Color, linewidth = smaWidth, linestyle = smaStyle)
plot(showSmaSet and showMa3Slot ? sma3 : na, title = "SMA MA #3", color = ma3Color, linewidth = smaWidth, linestyle = smaStyle)
plot(showSmaSet and showMa4Slot ? sma4 : na, title = "SMA MA #4", color = ma4Color, linewidth = smaWidth, linestyle = smaStyle)
 
plot(showEmaSet and showMa1Slot ? ema1 : na, title = "EMA MA #1", color = ma1Color, linewidth = emaWidth, linestyle = emaStyle)
plot(showEmaSet and showMa2Slot ? ema2 : na, title = "EMA MA #2", color = ma2Color, linewidth = emaWidth, linestyle = emaStyle)
plot(showEmaSet and showMa3Slot ? ema3 : na, title = "EMA MA #3", color = ma3Color, linewidth = emaWidth, linestyle = emaStyle)
plot(showEmaSet and showMa4Slot ? ema4 : na, title = "EMA MA #4", color = ma4Color, linewidth = emaWidth, linestyle = emaStyle)
 
plot(showSmmaSet and showMa1Slot ? smma1 : na, title = "SMMA MA #1", color = ma1Color, linewidth = smmaWidth, linestyle = smmaStyle)
plot(showSmmaSet and showMa2Slot ? smma2 : na, title = "SMMA MA #2", color = ma2Color, linewidth = smmaWidth, linestyle = smmaStyle)
plot(showSmmaSet and showMa3Slot ? smma3 : na, title = "SMMA MA #3", color = ma3Color, linewidth = smmaWidth, linestyle = smmaStyle)
plot(showSmmaSet and showMa4Slot ? smma4 : na, title = "SMMA MA #4", color = ma4Color, linewidth = smmaWidth, linestyle = smmaStyle)
 
plot(showWmaSet and showMa1Slot ? wma1 : na, title = "WMA MA #1", color = ma1Color, linewidth = wmaWidth, linestyle = wmaStyle)
plot(showWmaSet and showMa2Slot ? wma2 : na, title = "WMA MA #2", color = ma2Color, linewidth = wmaWidth, linestyle = wmaStyle)
plot(showWmaSet and showMa3Slot ? wma3 : na, title = "WMA MA #3", color = ma3Color, linewidth = wmaWidth, linestyle = wmaStyle)
plot(showWmaSet and showMa4Slot ? wma4 : na, title = "WMA MA #4", color = ma4Color, linewidth = wmaWidth, linestyle = wmaStyle)
 
plot(showVwmaSet and showMa1Slot ? vwma1 : na, title = "VWMA MA #1", color = ma1Color, linewidth = vwmaWidth, linestyle = vwmaStyle)
plot(showVwmaSet and showMa2Slot ? vwma2 : na, title = "VWMA MA #2", color = ma2Color, linewidth = vwmaWidth, linestyle = vwmaStyle)
plot(showVwmaSet and showMa3Slot ? vwma3 : na, title = "VWMA MA #3", color = ma3Color, linewidth = vwmaWidth, linestyle = vwmaStyle)
plot(showVwmaSet and showMa4Slot ? vwma4 : na, title = "VWMA MA #4", color = ma4Color, linewidth = vwmaWidth, linestyle = vwmaStyle)
 
plot(showHmaSet and showMa1Slot ? hma1 : na, title = "HMA MA #1", color = ma1Color, linewidth = hmaWidth, linestyle = hmaStyle)
plot(showHmaSet and showMa2Slot ? hma2 : na, title = "HMA MA #2", color = ma2Color, linewidth = hmaWidth, linestyle = hmaStyle)
plot(showHmaSet and showMa3Slot ? hma3 : na, title = "HMA MA #3", color = ma3Color, linewidth = hmaWidth, linestyle = hmaStyle)
plot(showHmaSet and showMa4Slot ? hma4 : na, title = "HMA MA #4", color = ma4Color, linewidth = hmaWidth, linestyle = hmaStyle)
 
//══════════════════════════════════════════════════════════════════════════════
// Quick Reference Panel
//══════════════════════════════════════════════════════════════════════════════
var table refTbl = na
 
panelHeader  = color.rgb(15, 15, 15)
panelSubhead = color.rgb(25, 25, 25)
panelBody    = color.rgb(5, 5, 5)
panelText    = color.white
 
if barstate.islast
    if showQuickRef
        if na(refTbl)
            refTbl := table.new(position.top_right, 4, 17, border_width = 1, border_color = color.rgb(40, 40, 40))
 
        // Top section
        table.cell(refTbl, 0, 0, "Slot",   text_color = panelText, bgcolor = panelHeader)
        table.cell(refTbl, 1, 0, "Value",  text_color = panelText, bgcolor = panelHeader)
        table.cell(refTbl, 2, 0, "Source", text_color = panelText, bgcolor = panelHeader)
        table.cell(refTbl, 3, 0, "Toggle", text_color = panelText, bgcolor = panelHeader)
 
        table.cell(refTbl, 0, 1, "MA #1", text_color = ma1Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 1, str.tostring(ma1Len), text_color = ma1Color, bgcolor = panelBody)
        table.cell(refTbl, 2, 1, ma1SourceInput, text_color = ma1Color, bgcolor = panelBody)
        table.cell(refTbl, 3, 1, showMa1Slot ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 2, "MA #2", text_color = ma2Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 2, str.tostring(ma2Len), text_color = ma2Color, bgcolor = panelBody)
        table.cell(refTbl, 2, 2, ma2SourceInput, text_color = ma2Color, bgcolor = panelBody)
        table.cell(refTbl, 3, 2, showMa2Slot ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 3, "MA #3", text_color = ma3Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 3, str.tostring(ma3Len), text_color = ma3Color, bgcolor = panelBody)
        table.cell(refTbl, 2, 3, ma3SourceInput, text_color = ma3Color, bgcolor = panelBody)
        table.cell(refTbl, 3, 3, showMa3Slot ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 4, "MA #4", text_color = ma4Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 4, str.tostring(ma4Len), text_color = ma4Color, bgcolor = panelBody)
        table.cell(refTbl, 2, 4, ma4SourceInput, text_color = ma4Color, bgcolor = panelBody)
        table.cell(refTbl, 3, 4, showMa4Slot ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        // Bottom section
        table.cell(refTbl, 0, 5, "Type",   text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 1, 5, "Width",  text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 2, 5, "Style",  text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 3, 5, "Toggle", text_color = panelText, bgcolor = panelSubhead)
 
        table.cell(refTbl, 0, 6, "SMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 6, str.tostring(smaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 6, smaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 6, showSmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 7, "EMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 7, str.tostring(emaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 7, emaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 7, showEmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 8, "SMMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 8, str.tostring(smmaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 8, smmaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 8, showSmmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 9, "WMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 9, str.tostring(wmaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 9, wmaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 9, showWmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 10, "VWMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 10, str.tostring(vwmaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 10, vwmaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 10, showVwmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 11, "HMA", text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 1, 11, str.tostring(hmaWidth), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 11, hmaStyleInput, text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 11, showHmaSet ? "ON" : "OFF", text_color = panelText, bgcolor = panelBody)
 
        // Disagreement section
        table.cell(refTbl, 0, 12, "Slot", text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 1, 12, "Spread (ATR)", text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 2, 12, "Top method", text_color = panelText, bgcolor = panelSubhead)
        table.cell(refTbl, 3, 12, "Bottom method", text_color = panelText, bgcolor = panelSubhead)
 
        table.cell(refTbl, 0, 13, "MA #1", text_color = ma1Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 13, str.tostring(spreadAtr(hi1, lo1), "#.##"), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 13, methodAt(hi1, sma1, ema1, smma1, wma1, vwma1, hma1), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 13, methodAt(lo1, sma1, ema1, smma1, wma1, vwma1, hma1), text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 14, "MA #2", text_color = ma2Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 14, str.tostring(spreadAtr(hi2, lo2), "#.##"), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 14, methodAt(hi2, sma2, ema2, smma2, wma2, vwma2, hma2), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 14, methodAt(lo2, sma2, ema2, smma2, wma2, vwma2, hma2), text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 15, "MA #3", text_color = ma3Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 15, str.tostring(spreadAtr(hi3, lo3), "#.##"), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 15, methodAt(hi3, sma3, ema3, smma3, wma3, vwma3, hma3), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 15, methodAt(lo3, sma3, ema3, smma3, wma3, vwma3, hma3), text_color = panelText, bgcolor = panelBody)
 
        table.cell(refTbl, 0, 16, "MA #4", text_color = ma4Color, bgcolor = panelBody)
        table.cell(refTbl, 1, 16, str.tostring(spreadAtr(hi4, lo4), "#.##"), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 2, 16, methodAt(hi4, sma4, ema4, smma4, wma4, vwma4, hma4), text_color = panelText, bgcolor = panelBody)
        table.cell(refTbl, 3, 16, methodAt(lo4, sma4, ema4, smma4, wma4, vwma4, hma4), text_color = panelText, bgcolor = panelBody)
 
    else
        if not na(refTbl)
            table.delete(refTbl)
            refTbl := na

← 返回列表