MrApeX Trend Clouds - MTF EMA Clouds and Relative Volume

Mr4peX · study · 1324 行 · 点赞 13 · 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/
// © MrApeX
// Built on the EMA Cloud system of Ripster47 ("Ripster EMA Clouds", MPL 2.0, © ripster47). Thank you, Ripster!
//@version=6
indicator(title="MrApeX Trend Clouds - MTF EMA Clouds and Relative Volume", shorttitle="MrApeX Trend Clouds+RelVol", overlay=true, max_bars_back=500, max_labels_count=100)
 
color def_C1_Bull_Color = color.green
color def_C1_Bear_Color = color.red
 
color def_C2_Bull_Color = color.blue
color def_C2_Bear_Color = color.orange
 
color def_C3_Bull_Color = color.blue
color def_C3_Bear_Color = color.orange
 
color def_C4_Bull_Color = color.green
color def_C4_Bear_Color = color.red
 
color def_C5_Bull_Color = color.blue
color def_C5_Bear_Color = color.orange
 
color def_C6_Bull_Color = color.green
color def_C6_Bear_Color = color.red
 
color def_C7_Bull_Color = color.blue
color def_C7_Bear_Color = color.orange
color def_C72_Bull_Color = #009688
color def_C72_Bear_Color = #f06292
color def_C180_Bull_Color = #05bed5
color def_C180_Bear_Color = #e65100
color def_C8_Bull_Color = color.green
color def_C8_Bear_Color = color.red
 
var cloudLabels = array.new_label()
 
grpCurrentTF = "CURRENT TIMEFRAME CLOUDS"
inline1 = "C1_Settings"
inline2 = "C2_Settings"
inline3 = "C3_Settings"
inline72 = "C72_Settings"
inline180 = "C180_Settings"
showCloud1 = input.bool(true, title="Cloud 1 / Label:", group=grpCurrentTF, inline=inline1)
len1_S = input.int(8, title="", minval=1, group=grpCurrentTF, inline=inline1)
len1_L = input.int(9, title="", minval=1, group=grpCurrentTF, inline=inline1)
showLabel1 = input.bool(false, title="", group=grpCurrentTF, inline=inline1, tooltip="The 8-9 cloud: Ripster's pullback levels (optional in his system). Green = short-term trend up, red = down. Short and Long set how fast the two edges react. Label = show its two EMA lengths (e.g. 8/9) just right of the last candle.")
 
showCloud2 = input.bool(true, title="Cloud 2 / Label:", group=grpCurrentTF, inline=inline2)
len2_S = input.int(5, title="", minval=1, group=grpCurrentTF, inline=inline2)
len2_L = input.int(12, title="", minval=1, group=grpCurrentTF, inline=inline2)
showLabel2 = input.bool(false, title="", group=grpCurrentTF, inline=inline2, tooltip="The 5-12 cloud: Ripster's fluid trendline. In a trend, price rides this cloud; candles closing back through it = the move is weakening. Label = show its two EMA lengths (e.g. 8/9) just right of the last candle.")
 
showCloud3 = input.bool(true, title="Cloud 3 / Label:", group=grpCurrentTF, inline=inline3)
len3_S = input.int(34, title="", minval=1, group=grpCurrentTF, inline=inline3)
len3_L = input.int(50, title="", minval=1, group=grpCurrentTF, inline=inline3)
showLabel3 = input.bool(false, title="", group=grpCurrentTF, inline=inline3, tooltip="The 34-50 cloud: Ripster's bias and risk level, on any timeframe. Above it = bullish bias, below it = bearish bias. Label = show its two EMA lengths (e.g. 8/9) just right of the last candle.")
 
showCloud72 = input.bool(false, title="Cloud 4 / Label:", group=grpCurrentTF, inline=inline72)
len72_S = input.int(72, title="", minval=1, group=grpCurrentTF, inline=inline72)
len72_L = input.int(89, title="", minval=1, group=grpCurrentTF, inline=inline72)
showLabel72 = input.bool(false, title="", group=grpCurrentTF, inline=inline72, tooltip="The 72-89 cloud from Ripster's EMA Clouds (off by default, as in his script). A slower trend cloud on your chart timeframe. Label = show its two EMA lengths (e.g. 8/9) just right of the last candle.")
 
showCloud180 = input.bool(false, title="Cloud 5 / Label:", group=grpCurrentTF, inline=inline180)
len180_S = input.int(180, title="", minval=1, group=grpCurrentTF, inline=inline180)
len180_L = input.int(200, title="", minval=1, group=grpCurrentTF, inline=inline180)
showLabel180 = input.bool(false, title="", group=grpCurrentTF, inline=inline180, tooltip="The 180-200 cloud from Ripster's EMA Clouds (off by default, as in his script). The slowest trend cloud on your chart timeframe. Label = show its two EMA lengths (e.g. 8/9) just right of the last candle.")
 
currentTFSource = input.source(hl2, title="Current TF Source:", group=grpCurrentTF, tooltip="CHOOSE CURRENT TIMEFRAME DATA SOURCE:\n\n CLOSE: Final bar price - Best for:\n• Trend following strategies (captures momentum)\n• Entry/exit timing (actual execution prices)\n• Breakout signals (immediate reaction)\n• When you trade at bar close\n• Most common for current TF analysis\n\n HL2 ((High+Low)/2): Bar midpoint - Best for:\n• Scalping strategies (intraday range focus)\n• Support/Resistance trading\n• Range-bound markets (reduces noise)\n• Volatile coins/assets (smooths extremes)\n\n HLC3 ((High+Low+Close)/3): Balanced approach\n• Combines range awareness with close sentiment\n• Good for swing trading strategies\n\n OHLC4 ((Open+High+Low+Close)/4): Maximum smoothing\n• Extremely volatile assets (crypto, small caps)\n• When you need very stable signals\n\n DEFAULT: HL2, as in Ripster's EMA Clouds. CLOSE reacts faster to the bar close.")
 
grpMTF = "MULTI TIME FRAME CLOUDS"
inline4 = "C4_Settings"
inline5 = "C5_Settings"
inline6 = "C6_Settings"
inline7 = "C7_Settings"
inline8 = "C8_Settings"
showCloud4 = input.bool(true, title="MTF1:", group=grpMTF, inline=inline4)
len4_S = input.int(34, title="", minval=1, group=grpMTF, inline=inline4)
len4_L = input.int(50, title="", minval=1, group=grpMTF, inline=inline4)
tf4 = input.timeframe("60", title="", group=grpMTF, inline=inline4, tooltip="A trend cloud from the higher timeframe you pick, drawn on this chart, so you see the bigger trend while trading a lower timeframe. While a higher-timeframe candle is still open, the MTF clouds, their alerts and the table follow that forming candle and can change until it closes.")
 
showCloud5 = input.bool(false, title="MTF2:", group=grpMTF, inline=inline5)
len5_S = input.int(34, title="", minval=1, group=grpMTF, inline=inline5)
len5_L = input.int(50, title="", minval=1, group=grpMTF, inline=inline5)
tf5 = input.timeframe("240", title="", group=grpMTF, inline=inline5, tooltip="Optional (off by default): Ripster's 34/50 bias cloud on the 4-hour chart (his MTF Clouds script: \"Default is 4 hrs\"). It sits between the 1-hour and the daily clouds: on a 10-15 min chart, price above it = the bigger trend is up, below = down, and it often acts as support or resistance.")
 
showCloud6 = input.bool(true, title="MTF3:", group=grpMTF, inline=inline6)
len6_S = input.int(20, title="", minval=1, group=grpMTF, inline=inline6)
len6_L = input.int(21, title="", minval=1, group=grpMTF, inline=inline6)
tf6 = input.timeframe("1D", title="", group=grpMTF, inline=inline6, tooltip="A trend cloud from a larger timeframe (default: daily).")
 
showCloud7 = input.bool(true, title="MTF4:", group=grpMTF, inline=inline7)
len7_S = input.int(50, title="", minval=1, group=grpMTF, inline=inline7)
len7_L = input.int(55, title="", minval=1, group=grpMTF, inline=inline7)
tf7 = input.timeframe("1D", title="", group=grpMTF, inline=inline7, tooltip="A second, slower trend cloud from the larger timeframe.")
 
showCloud8 = input.bool(false, title="MTF5:", group=grpMTF, inline=inline8)
len8_S = input.int(180, title="", minval=1, group=grpMTF, inline=inline8)
len8_L = input.int(200, title="", minval=1, group=grpMTF, inline=inline8)
tf8 = input.timeframe("240", title="", group=grpMTF, inline=inline8, tooltip="Optional (off by default): the 4-hour 180/200 cloud, i.e. the 4-hour 200 EMA, the higher-timeframe level traders cite most for support and resistance. Usually far from price; it matters when price comes near it.")
 
mtfSource = input.source(hl2, title="MTF Source / Labels:", group=grpMTF, inline="mtfsrc", tooltip="CHOOSE MTF DATA SOURCE:\n\n CLOSE: Final bar price - Best for:\n• Strong trending markets (captures momentum)\n• Breakout strategies (immediate reaction)\n• News-driven markets (final sentiment)\n• When you want reactive signals\n\n HL2 ((High+Low)/2): Bar midpoint - Best for:\n• Choppy/sideways markets (reduces noise)\n• Support/Resistance strategies\n• High volatility periods (smooths extremes)\n• When you want smoother MTF signals\n\n HLC3 ((High+Low+Close)/3): Balanced approach\n• General-purpose (combines range + sentiment)\n• Moderate smoothing with trend awareness\n\n OHLC4 ((Open+High+Low+Close)/4): Maximum smoothing\n• Very noisy markets (ultimate smoothing)\n• When you need stable higher TF signals\n\n RECOMMENDATION: HL2 for cleaner MTF clouds, especially on 1D+ timeframes")
showMtfLabels = input.bool(false, "", group=grpMTF, inline="mtfsrc", tooltip="Show or hide the name labels of all MTF clouds (MTF1 to MTF5) just right of the last candle.")
 
grpTbl = "CLOUDS & MTF STATUS Table Settings"
inlineTbl_mode_pos_size = "tbl_mode_pos_size"
showTable = input.bool(false, "Show Cloud & MTF Status Table", group=grpTbl, tooltip="A small table with the direction of Clouds 1 to 3 on nine timeframes, from 1 minute to weekly.")
tablePosition = input.string("Bottom Right", title="Position", options=["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group=grpTbl, inline=inlineTbl_mode_pos_size)
tableSize = input.string("Medium", title="", options=["Tiny", "Small", "Medium", "Large"], group=grpTbl, inline=inlineTbl_mode_pos_size, tooltip="Where the status table sits on the chart, and its text size.")
showCurrentClouds = true
show1hClouds = false
show1dClouds = false
compactMode = true
tbl_bg_color = color.new(color.rgb(40, 40, 40), 0)
tbl_header_text_color = color.new(color.white, 0)
tbl_bull_text_color = color.new(color.green, 0)
tbl_bear_text_color = color.new(#F23645, 0)
 
grpVol = "VOLUME ENGINE"
inlineVol_main = "vol_main"
inlineVol_settings = "vol_settings"
showVolumeTable = input.bool(false, "Show Volume Analysis Table", group=grpVol, inline=inlineVol_main)
 
volumeTablePosition = input.string("Top Right", "", group=grpVol, inline=inlineVol_main, options=["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"])
 
volumeTableSize = input.string("Normal", "", group=grpVol, inline=inlineVol_main, options=["Small", "Normal", "Large"], tooltip="VOLUME TABLE:\nFirst the two Ripster47 volume reads:\n• RIPSTER RVOL - the day volume vs the 20-day average; on weekly / monthly charts the week / month volume vs the 20-week / 20-month average (red at 20 % or less)\n• CANDLE RVOL - this candle and the last one vs the last 50 candles (orange from 100 %, red from 200 %)\nThen our volume read as a story:\n• NOW - this bar vs the SAME time of day\n• PACE - is today running hot or cold, with a full-day projection\n• STATE - QUIET / NORMAL / BUILDING / SPIKE / COILED\n• BIAS - share of the volume on up-candles over the last 20 candles\nplus one row per market (New York, London, Tokyo): its current part of the day and the volume traded in it so far vs the same hours on a typical day (High from 150 %, Normal from 100 %, Low from 50 %, Very Low below; Closed at the weekend), and the cloud + volume read block.\n\nThe chart tells the same story visually: state dots, optional spike tinting and the next busy-time marker.\n\nPOSITION (first box): where the volume table sits on the chart.\nSIZE (second box): Small / Normal / Large text.")
 
rvolLookback = 10
veBaselineDays = 20
inlineVE1 = "ve1"
veSpikeTh = input.float(200.0, "Spike % / Quiet %", group=grpVol, inline=inlineVE1, minval=120, step=5)
veQuietTh = input.float(70.0, "", group=grpVol, inline=inlineVE1, minval=10, maxval=100, step=5, tooltip="SPIKE %: Volume vs the same time of day at/above this % = SPIKE state.\n\nQUIET %: Volume vs the same time of day at/below this % = QUIET; a long quiet run plus a tight price range = COILED.\n\nOn daily and higher charts both compare with the recent average volume instead of the same time of day.")
marketType = input.string("Crypto (24/7)", "Market Type / MTF Clouds in Consensus", options=["Crypto (24/7)", "Stocks / Futures"], group=grpVol, inline="vemkt")
bool veMarketCrypto = marketType == "Crypto (24/7)"
veWeekendSplit = true
consensusIncludeMtf = input.bool(true, "", group=grpVol, inline="vemkt", tooltip="MARKET TYPE: Sets the market rhythm the Volume Engine expects.\n- Crypto (24/7): continuous trading; weekend volume gets its own baseline, because weekends are usually quieter.\n- Stocks / Futures: no weekend split (weekday and weekend volume share one baseline). On every market, the volume day and PACE follow the exchange session of the symbol.\n\nMTF CLOUDS IN CONSENSUS: When on, every MTF cloud that is switched on and can draw on this chart (by default MTF1 1-hour, MTF3 and MTF4 daily) also votes in the Clouds / Trend / Combined Read / Setup Quality rows, next to Clouds 1-3. Turn off to score Clouds 1-3 alone. Clouds 4 and 5 never vote.")
inlineVE2 = "ve2"
veDotSpike = false
veDotBuild = true
veDotCoil = true
veDotQuiet = false
veShowStateDots = input.bool(false, "State Dots / Volume Layer / Busy-Time Marker / Tint Spike Bars", group=grpVol, inline=inlineVE2)
veShowPulse = input.bool(false, "", group=grpVol, inline=inlineVE2)
veShowNextEnergy = input.bool(true, "", group=grpVol, inline=inlineVE2)
veTintSpikes = input.bool(false, "", group=grpVol, inline=inlineVE2, tooltip="STATE DOTS: Chart visual (off by default): a small dot at the bottom of the chart, below the candle, when the volume state is BUILDING (orange) or COILED (purple). Prefer a shape-free chart? Use the Volume Layer instead - it paints the volume state color into Cloud 2's shape, keeping the signal lanes free for other indicators.\n\nVOLUME LAYER: Chart visual (off by default): the volume STATE painted in Cloud 2's exact shape (the 5/12 gap), drawn over every cloud except Cloud 1 (the 8/9 cloud stays on top) - red SPIKE, orange BUILDING, purple COILED, faint gray QUIET. NO paint = normal volume. The shape follows momentum (the 5/12 gap); the color is the volume verdict vs the same time of day. Works even when Cloud 2 itself is hidden. No marker shapes - the signal lanes stay free for other indicators.\n\nBUSY-TIME MARKER: Chart visual, intraday charts only: a dotted vertical line AHEAD of the last bar marking the next time slot that is typically high-volume for this symbol (at least 1.8x its usual slot, learned from its own history, e.g. a session open), with its usual intensity. Crypto: always shown, pointing at the next busy time (looking up to 3 days ahead, weekday and weekend habits kept apart). Stocks and other markets: shown only while the market is open (regular hours), looking about 8 hours ahead on charts up to 1 hour. The line can sit to the right of the visible chart.\n\nTINT SPIKE BARS: Chart visual: color the bars whose volume vs the same time of day is at/above the Spike threshold.")
inlineVE3 = "ve3"
veColSpike = input.color(color.red, "Spike / Building / Coiled / Quiet", group=grpVol, inline=inlineVE3)
veColBuild = input.color(color.orange, "", group=grpVol, inline=inlineVE3)
veColCoil = input.color(color.purple, "", group=grpVol, inline=inlineVE3)
veColQuiet = input.color(color.gray, "", group=grpVol, inline=inlineVE3, tooltip="State colors used everywhere: the dots, the spike bar tint, the Volume Layer and the STATE table row.")
veCoilBars = 6
veCoilComp = 0.6
veEnergyMult = 1.8
veShowBreaks = input.bool(false, "Break Dots / Cloud Alignment Strategy", group=grpVol, inline=inlineVol_settings)
veBreakRef = "MTF 1"
veBreakVolTh = 130.0
 
cloudAlignmentStrategy = input.string("Aggressive", "", group=grpVol, inline=inlineVol_settings, options=["Aggressive", "Neutral", "Passive"], tooltip="BREAK DOTS: A dot at the bottom of the chart when a candle CLOSES across the MTF1 cloud (1-hour by default) WITH real participation (volume at least 130 % of the same time of day). Only on charts below the MTF1 timeframe. Aqua = upside break, magenta = downside. Breaks without volume stay unmarked - treat them as suspect. Note: the MTF1 cloud is still forming when your chart bar closes, so a break flagged early in that higher-timeframe bar can look different once it completes - give fresh hourly/daily opens extra patience.\n\nCLOUD ALIGNMENT STRATEGY: How Clouds 1, 2 and 3 are weighted when scoring trend alignment.\n- Aggressive: favors the fastest cloud - quicker to react, more signals.\n- Neutral: equal weight across the three clouds.\n- Passive: favors the slowest cloud - steadier, fewer flips.")
 
showRipDayRvol = true
showRipCandleRvol = true
showVeNow = true
showVePace = true
showVeState = true
showVeBias = true
 
showTimeInterval = true
 
showLondonTime = true
 
showTokyoTime = true
 
showCloudAlignment = true
showTrendDisplay = true
 
showVolumeConviction = true
showTradingSignal = true
 
showRiskLevel = true
 
showLabels = true
labelSize = "Normal"
labelTextColor = color.white
labelPositioning = "Chart Edge"
labelOffsetPercent = 3.0
 
var string[] TABLE_TIMEFRAMES_STR = array.from("1", "5", "15", "30", "60", "240", "720", "D", "W")
var string[] TABLE_TIMEFRAMES_LBL = array.from("1m", "5m", "15m", "30m", "1h", "4h", "12h", "D", "W")
 
getTablePosition(posString) =>
    var string _pos = position.top_right
    if posString == "Top Left"
        _pos := position.top_left
    else if posString == "Top Center"
        _pos := position.top_center
    else if posString == "Top Right"
        _pos := position.top_right
    else if posString == "Middle Left"
        _pos := position.middle_left
    else if posString == "Middle Center"
        _pos := position.middle_center
    else if posString == "Middle Right"
        _pos := position.middle_right
    else if posString == "Bottom Left"
        _pos := position.bottom_left
    else if posString == "Bottom Center"
        _pos := position.bottom_center
    else if posString == "Bottom Right"
        _pos := position.bottom_right
    _pos
 
getMTFEMAPlot(sourceSeries, timeframeString, length) =>
    request.security(syminfo.tickerid, timeframeString == "" ? timeframe.period : timeframeString, ta.ema(sourceSeries, length))
 
getTableTextSize(sizeString) =>
    sizeString == "Tiny" ? size.tiny :
     sizeString == "Small" ? size.small :
     sizeString == "Medium" ? size.normal :
     sizeString == "Large" ? size.large :
     size.small
 
get_ema_status(src, len_s, len_l) =>
    ta.ema(src, len_s) >= ta.ema(src, len_l)
 
formatTimeframe(tf) =>
    switch tf
        "1" => "1m"
        "3" => "3m"
        "5" => "5m"
        "15" => "15m"
        "30" => "30m"
        "45" => "45m"
        "60" => "1H"
        "120" => "2H"
        "240" => "4H"
        "360" => "6H"
        "720" => "12H"
        "1D" => "1D"
        "1W" => "1W"
        "1M" => "1M"
        => str.contains(tf, "S") or str.contains(tf, "D") or str.contains(tf, "W") or str.contains(tf, "M") ? tf : tf + "m"
 
len1_S_validated = math.min(len1_S, len1_L)
len1_L_validated = math.max(len1_S, len1_L)
len2_S_validated = math.min(len2_S, len2_L)
len2_L_validated = math.max(len2_S, len2_L)
len3_S_validated = math.min(len3_S, len3_L)
len3_L_validated = math.max(len3_S, len3_L)
 
len4_S_validated = math.min(len4_S, len4_L)
len4_L_validated = math.max(len4_S, len4_L)
len5_S_validated = math.min(len5_S, len5_L)
len5_L_validated = math.max(len5_S, len5_L)
len6_S_validated = math.min(len6_S, len6_L)
len6_L_validated = math.max(len6_S, len6_L)
len7_S_validated = math.min(len7_S, len7_L)
len7_L_validated = math.max(len7_S, len7_L)
len8_S_validated = math.min(len8_S, len8_L)
len8_L_validated = math.max(len8_S, len8_L)
len72_S_validated = math.min(len72_S, len72_L)
len72_L_validated = math.max(len72_S, len72_L)
len180_S_validated = math.min(len180_S, len180_L)
len180_L_validated = math.max(len180_S, len180_L)
 
var string[] TABLE_CLOUD_LABELS = array.from(str.tostring(len1_S_validated) + "/" + str.tostring(len1_L_validated), str.tostring(len2_S_validated) + "/" + str.tostring(len2_L_validated), str.tostring(len3_S_validated) + "/" + str.tostring(len3_L_validated), str.tostring(len4_S_validated) + "/" + str.tostring(len4_L_validated), str.tostring(len5_S_validated) + "/" + str.tostring(len5_L_validated), str.tostring(len6_S_validated) + "/" + str.tostring(len6_L_validated), str.tostring(len7_S_validated) + "/" + str.tostring(len7_L_validated))
var int[] TABLE_TIMEFRAMES_SEC = array.from(timeframe.in_seconds("1"), timeframe.in_seconds("5"), timeframe.in_seconds("15"), timeframe.in_seconds("30"), timeframe.in_seconds("60"), timeframe.in_seconds("240"), timeframe.in_seconds("720"), timeframe.in_seconds("D"), timeframe.in_seconds("W"))
var int[] TABLE_CLOUD_TFSEC = array.from(-1, -1, -1, timeframe.in_seconds(tf4), timeframe.in_seconds(tf5), timeframe.in_seconds(tf6), timeframe.in_seconds(tf7))
 
ema_8_9_status_series = get_ema_status(currentTFSource, len1_S_validated, len1_L_validated)
ema_5_12_status_series = get_ema_status(currentTFSource, len2_S_validated, len2_L_validated)
ema_34_50_status_series = get_ema_status(currentTFSource, len3_S_validated, len3_L_validated)
 
ema4_status_mtf = request.security(syminfo.tickerid, tf4, get_ema_status(mtfSource, len4_S_validated, len4_L_validated), lookahead=barmerge.lookahead_off)
ema5_status_mtf = request.security(syminfo.tickerid, tf5, get_ema_status(mtfSource, len5_S_validated, len5_L_validated), lookahead=barmerge.lookahead_off)
ema6_status_mtf = request.security(syminfo.tickerid, tf6, get_ema_status(mtfSource, len6_S_validated, len6_L_validated), lookahead=barmerge.lookahead_off)
ema7_status_mtf = request.security(syminfo.tickerid, tf7, get_ema_status(mtfSource, len7_S_validated, len7_L_validated), lookahead=barmerge.lookahead_off)
 
var bool mtfCloud4CanPlot = timeframe.in_seconds(tf4) > timeframe.in_seconds(timeframe.period)
var bool mtfCloud5CanPlot = timeframe.in_seconds(tf5) > timeframe.in_seconds(timeframe.period)
var bool mtfCloud6CanPlot = timeframe.in_seconds(tf6) > timeframe.in_seconds(timeframe.period)
var bool mtfCloud7CanPlot = timeframe.in_seconds(tf7) > timeframe.in_seconds(timeframe.period)
var bool mtfCloud8CanPlot = timeframe.in_seconds(tf8) > timeframe.in_seconds(timeframe.period)
 
calcEMACloudData(src, len_s, len_l) =>
    ema_s = ta.ema(src, len_s)
    ema_l = ta.ema(src, len_l)
    is_bull = ema_s >= ema_l
    [ema_s, ema_l, is_bull]
 
calcMTFEMACloudData(src, tf, len_s, len_l) =>
    ema_s_htf = getMTFEMAPlot(src, tf, len_s)
    ema_l_htf = getMTFEMAPlot(src, tf, len_l)
    is_bull = ema_s_htf >= ema_l_htf
    [ema_s_htf, ema_l_htf, is_bull]
 
calcMTFEMACloudDataConditional(canShow, src, tf, len_s, len_l) =>
    if canShow
        calcMTFEMACloudData(src, tf, len_s, len_l)
    else
        [float(na), float(na), false]
 
[ema1_S, ema1_L, isBull1] = calcEMACloudData(currentTFSource, len1_S_validated, len1_L_validated)
 
[ema2_S, ema2_L, isBull2] = calcEMACloudData(currentTFSource, len2_S_validated, len2_L_validated)
 
[ema3_S, ema3_L, isBull3] = calcEMACloudData(currentTFSource, len3_S_validated, len3_L_validated)
 
[ema4_S_htf_plot, ema4_L_htf_plot, isBull4] = calcMTFEMACloudDataConditional(mtfCloud4CanPlot, mtfSource, tf4, len4_S_validated, len4_L_validated)
 
[ema5_S_htf_plot, ema5_L_htf_plot, isBull5] = calcMTFEMACloudDataConditional(showCloud5 and mtfCloud5CanPlot, mtfSource, tf5, len5_S_validated, len5_L_validated)
 
[ema6_S_htf_plot, ema6_L_htf_plot, isBull6] = calcMTFEMACloudDataConditional(mtfCloud6CanPlot, mtfSource, tf6, len6_S_validated, len6_L_validated)
 
[ema7_S_htf_plot, ema7_L_htf_plot, isBull7] = calcMTFEMACloudDataConditional(mtfCloud7CanPlot, mtfSource, tf7, len7_S_validated, len7_L_validated)
 
[ema8_S_htf_plot, ema8_L_htf_plot, isBull8] = calcMTFEMACloudDataConditional(showCloud8 and mtfCloud8CanPlot, mtfSource, tf8, len8_S_validated, len8_L_validated)
 
[ema72_S, ema72_L, isBull72] = calcEMACloudData(currentTFSource, len72_S_validated, len72_L_validated)
 
[ema180_S, ema180_L, isBull180] = calcEMACloudData(currentTFSource, len180_S_validated, len180_L_validated)
 
avgVolume = ta.sma(volume, rvolLookback)
 
ripRvolTf = timeframe.isweekly ? "W" : timeframe.ismonthly ? "M" : "D"
float ripDayVol = request.security(syminfo.tickerid, ripRvolTf, volume)
float ripDayAvg = request.security(syminfo.tickerid, ripRvolTf, ta.sma(volume[1], 20))
float ripDayRvol = not na(ripDayVol) and not na(ripDayAvg) and ripDayAvg > 0 ? math.round(ripDayVol / ripDayAvg * 100) : na
float ripCandleAvg = ta.sma(volume, 50)
float ripCandleRvol = not na(volume) and not na(ripCandleAvg) and ripCandleAvg > 0 ? volume / ripCandleAvg * 100 : na
float ripLastRvol = ripCandleRvol[1]
ripFmtVol(float v) =>
    na(v) ? "N/A" : v >= 1000000 ? str.tostring(math.round(v / 1000000, 2)) + "M" : str.tostring(math.round(v / 1000, 2)) + "k"
ripCandleColor(float p) =>
    na(p) ? color.gray : p >= 200 ? color.red : p >= 100 ? color.orange : color.yellow
 
candleVolumeDisplay = na(volume) ? "N/A" : volume >= 1000000 ? str.tostring(math.round(volume / 1000000, 2)) + "M" : str.tostring(math.round(volume / 1000, 2)) + "k"
 
int veTfSec = timeframe.in_seconds(timeframe.period)
bool veSlotMode = timeframe.isintraday and veTfSec >= 60 and 86400 % veTfSec == 0
int veSlots = veSlotMode ? 86400 / veTfSec : 1
var float[] veSlotAvg = array.new<float>(veSlots * 2, na)
int veDow = dayofweek(time, "UTC")
bool veIsWknd = veWeekendSplit and veMarketCrypto and (veDow == dayofweek.saturday or veDow == dayofweek.sunday)
int veDayStartMs = time("D")
int veIntradaySec = na(veDayStartMs) or veDayStartMs <= 0 ? int((time % 86400000) / 1000) : int((time - veDayStartMs) / 1000)
int veSlotIx = veSlotMode ? math.min(veSlots - 1, math.max(0, int(veIntradaySec / veTfSec))) : 0
int veIdx = veSlotIx + (veIsWknd ? veSlots : 0)
float veAlpha = 2.0 / (veBaselineDays + 1)
float veBase0 = array.get(veSlotAvg, veIdx)
float veWkdayPeer = veIsWknd ? array.get(veSlotAvg, veSlotIx) : na
float veBaseEff = not na(veBase0) ? veBase0 : (veIsWknd and not na(veWkdayPeer) ? veWkdayPeer * 0.6 : avgVolume)
float veElapsedFrac = barstate.isrealtime and not barstate.isconfirmed ? math.min(1.0, math.max(0.05, (timenow - time) / math.max(1, time_close - time))) : 1.0
float slotRVol = not na(volume) and not na(veBaseEff) and veBaseEff > 0 ? volume / (veBaseEff * veElapsedFrac) * 100 : na
if barstate.isconfirmed and not na(volume)
    array.set(veSlotAvg, veIdx, na(veBase0) ? volume : veBase0 + veAlpha * (volume - veBase0))
 
var float veCumToday = 0.0
var int veDayBars = 0
var int veMaxDayBars = 0
if ta.change(time("D")) != 0
    veCumToday := 0.0
    veMaxDayBars := math.max(veMaxDayBars, veDayBars)
    veDayBars := 0
if barstate.isconfirmed
    veDayBars += 1
int veDaySlots = veMaxDayBars > 0 ? math.min(veMaxDayBars, veSlots) : veSlots
float veCumNow = veCumToday + (na(volume) ? 0 : volume)
if barstate.isconfirmed and not na(volume)
    veCumToday += volume
vePhaseId(string tz, int b1, int b2, int b3, int b4, int b5, int b6) =>
    int d = dayofweek(time, tz)
    int hm = hour(time, tz) * 100 + minute(time, tz)
    d == dayofweek.sunday or d == dayofweek.saturday ? 0 : hm < b1 or hm >= b6 ? 6 : hm < b2 ? 1 : hm < b3 ? 2 : hm < b4 ? 3 : hm < b5 ? 4 : 5
vePhasePct(int ph) =>
    var float act = 0.0
    var float typ = 0.0
    if ph != nz(ph[1], -1)
        act := 0.0
        typ := 0.0
    if barstate.isconfirmed and not na(volume) and not na(veBaseEff)
        act += volume
        typ += veBaseEff
    float a = act + (barstate.isconfirmed or na(volume) ? 0.0 : volume)
    float t = typ + (barstate.isconfirmed or na(veBaseEff) ? 0.0 : veBaseEff * veElapsedFrac)
    na(volume) or t <= 0 ? na : a / t * 100
float veNyPct = vePhasePct(vePhaseId("America/New_York", 400, 930, 1200, 1500, 1600, 2000))
float veLonPct = vePhasePct(vePhaseId("Europe/London", 600, 800, 1200, 1630, 1700, 2000))
float veTyoPct = vePhasePct(vePhaseId("Asia/Tokyo", 800, 900, 1130, 1230, 1500, 1530))
veSessText(float p) =>
    not veSlotMode ? "intraday only" : na(p) ? "N/A" : p >= 150 ? "↑ High" : p >= 100 ? "↗ Normal" : p >= 50 ? "↘ Low" : "↓ Very Low"
veSessColor(float p) =>
    not veSlotMode or na(p) ? color.gray : p >= 150 ? color.blue : p >= 100 ? color.green : p >= 50 ? color.orange : color.red
veTypical() =>
    int veOff = veIsWknd ? veSlots : 0
    int veCur = veIdx - veOff
    float cum = 0.0
    float tot = 0.0
    int filled = 0
    for i = 0 to veSlots - 1
        float v = array.get(veSlotAvg, veOff + i)
        if not na(v)
            tot += v
            filled += 1
            if i < veCur
                cum += v
            else if i == veCur
                cum += v * veElapsedFrac
    [cum, tot, filled]
 
bool veSpike = not na(slotRVol) and slotRVol >= veSpikeTh
bool veQuietBar = not na(slotRVol) and slotRVol <= veQuietTh
var int veQuietRun = 0
veQuietRun := veQuietBar ? veQuietRun + 1 : 0
float veRngK = ta.highest(high, 12) - ta.lowest(low, 12)
float veRngAvg = ta.sma(veRngK, 48)
bool veCoiled = veQuietRun >= veCoilBars and not na(veRngAvg) and veRngK < veRngAvg * veCoilComp
bool veBuilding = not veSpike and not na(slotRVol) and slotRVol >= 120 and slotRVol > nz(slotRVol[1]) and nz(slotRVol[1]) > nz(slotRVol[2])
bool veNoVol = na(slotRVol)
string veState = veNoVol ? "N/A" : veSpike ? "SPIKE" : veCoiled ? "COILED" : veBuilding ? "BUILDING" : veQuietBar ? "QUIET" : "NORMAL"
color veStateColor = veNoVol ? color.gray : veSpike ? veColSpike : veCoiled ? veColCoil : veBuilding ? veColBuild : veQuietBar ? veColQuiet : color.white
 
float volpct = math.round(nz(slotRVol, 0), 2)
 
float veUpVol = math.sum(close > open and not na(volume) ? volume : 0.0, 20)
float veDnVol = math.sum(close < open and not na(volume) ? volume : 0.0, 20)
float veBiasPct = veUpVol + veDnVol > 0 ? veUpVol / (veUpVol + veDnVol) * 100 : na
 
cloud1Weight = switch cloudAlignmentStrategy
    "Aggressive" => 45.0
    "Neutral" => 33.3
    "Passive" => 20.0
    => 20.0
 
cloud2Weight = switch cloudAlignmentStrategy
    "Aggressive" => 35.0
    "Neutral" => 33.3
    "Passive" => 35.0
    => 35.0
 
cloud3Weight = switch cloudAlignmentStrategy
    "Aggressive" => 20.0
    "Neutral" => 33.3
    "Passive" => 45.0
    => 45.0
 
totalWeight = 0.0
bullishWeight = 0.0
bearishWeight = 0.0
activeClouds = 0
 
if showCloud1
    totalWeight += cloud1Weight
    if isBull1
        bullishWeight += cloud1Weight
    else
        bearishWeight += cloud1Weight
    activeClouds += 1
 
if showCloud2
    totalWeight += cloud2Weight
    if isBull2
        bullishWeight += cloud2Weight
    else
        bearishWeight += cloud2Weight
    activeClouds += 1
 
if showCloud3
    totalWeight += cloud3Weight
    if isBull3
        bullishWeight += cloud3Weight
    else
        bearishWeight += cloud3Weight
    activeClouds += 1
 
float mtfConsensusWeight = 25.0
if consensusIncludeMtf and showCloud4 and mtfCloud4CanPlot
    totalWeight += mtfConsensusWeight
    bullishWeight += isBull4 ? mtfConsensusWeight : 0.0
    bearishWeight += isBull4 ? 0.0 : mtfConsensusWeight
    activeClouds += 1
if consensusIncludeMtf and showCloud5 and mtfCloud5CanPlot
    totalWeight += mtfConsensusWeight
    bullishWeight += isBull5 ? mtfConsensusWeight : 0.0
    bearishWeight += isBull5 ? 0.0 : mtfConsensusWeight
    activeClouds += 1
if consensusIncludeMtf and showCloud6 and mtfCloud6CanPlot
    totalWeight += mtfConsensusWeight
    bullishWeight += isBull6 ? mtfConsensusWeight : 0.0
    bearishWeight += isBull6 ? 0.0 : mtfConsensusWeight
    activeClouds += 1
if consensusIncludeMtf and showCloud7 and mtfCloud7CanPlot
    totalWeight += mtfConsensusWeight
    bullishWeight += isBull7 ? mtfConsensusWeight : 0.0
    bearishWeight += isBull7 ? 0.0 : mtfConsensusWeight
    activeClouds += 1
if consensusIncludeMtf and showCloud8 and mtfCloud8CanPlot
    totalWeight += mtfConsensusWeight
    bullishWeight += isBull8 ? mtfConsensusWeight : 0.0
    bearishWeight += isBull8 ? 0.0 : mtfConsensusWeight
    activeClouds += 1
 
bullishCloudPercent = totalWeight > 0 ? math.round((bullishWeight / totalWeight) * 100, 1) : 0
bearishCloudPercent = totalWeight > 0 ? math.round((bearishWeight / totalWeight) * 100, 1) : 0
 
bullishClouds = (showCloud1 and isBull1 ? 1 : 0) + (showCloud2 and isBull2 ? 1 : 0) + (showCloud3 and isBull3 ? 1 : 0) + (consensusIncludeMtf and showCloud4 and mtfCloud4CanPlot and isBull4 ? 1 : 0) + (consensusIncludeMtf and showCloud5 and mtfCloud5CanPlot and isBull5 ? 1 : 0) + (consensusIncludeMtf and showCloud6 and mtfCloud6CanPlot and isBull6 ? 1 : 0) + (consensusIncludeMtf and showCloud7 and mtfCloud7CanPlot and isBull7 ? 1 : 0) + (consensusIncludeMtf and showCloud8 and mtfCloud8CanPlot and isBull8 ? 1 : 0)
bearishClouds = activeClouds - bullishClouds
 
overallTrend = switch
    bullishCloudPercent >= 75 => "STRONG BULL"
    bullishCloudPercent >= 60 => "BULL"
    bearishCloudPercent >= 75 => "STRONG BEAR"
    bearishCloudPercent >= 60 => "BEAR"
    bullishCloudPercent >= 40 => "MIXED"
    => "NEUTRAL"
 
volumeConviction = switch
    veNoVol => "N/A"
    volpct >= 200 => "EXTREME"
    volpct >= 150 => "HIGH"
    volpct >= 100 => "NORMAL"
    volpct >= 50 => "LOW"
    => "VERY LOW"
 
signal = switch
    veNoVol => "NO VOLUME DATA"
    volpct >= 150 and bullishCloudPercent >= 75 => "STRONG UP"
    volpct >= 150 and bearishCloudPercent >= 75 => "STRONG DOWN"
    volpct >= 100 and bullishCloudPercent >= 60 => "UP"
    volpct >= 100 and bearishCloudPercent >= 60 => "DOWN"
    volpct >= 150 and overallTrend == "MIXED" => "HIGH VOLUME, MIXED"
    volpct < 50 => "LOW ACTIVITY"
    => "WAIT"
 
riskLevel = switch
    veNoVol => "N/A"
    volpct >= 150 and (bullishCloudPercent >= 75 or bearishCloudPercent >= 75) => "CLEAR SETUP"
    volpct >= 100 and (bullishCloudPercent >= 60 or bearishCloudPercent >= 60) => "MIXED SETUP"
    volpct >= 150 and overallTrend == "MIXED" => "UNCLEAR SETUP"
    volpct < 50 => "NO SETUP"
    => "WEAK SETUP"
 
cloud8_color = isBull8 ? def_C8_Bull_Color : def_C8_Bear_Color
cloud8_line1 = plot(showCloud8 ? ema8_S_htf_plot : na, title="MTF5 Line 1", color=color.gray, display=display.none)
cloud8_line2 = plot(showCloud8 ? ema8_L_htf_plot : na, title="MTF5 Line 2", color=color.gray, display=display.none)
fill(cloud8_line1, cloud8_line2, title="MTF5", color=showCloud8 ? color.new(cloud8_color, 50) : na)
 
cloud7_color = isBull7 ? def_C7_Bull_Color : def_C7_Bear_Color
cloud7_line1 = plot(showCloud7 ? ema7_S_htf_plot : na, title="MTF4 Line 1", color=color.gray, display=display.none)
cloud7_line2 = plot(showCloud7 ? ema7_L_htf_plot : na, title="MTF4 Line 2", color=color.gray, display=display.none)
fill(cloud7_line1, cloud7_line2, title="MTF4", color=showCloud7 ? color.new(cloud7_color, 50) : na)
 
cloud6_color = isBull6 ? def_C6_Bull_Color : def_C6_Bear_Color
cloud6_line1 = plot(showCloud6 ? ema6_S_htf_plot : na, title="MTF3 Line 1", color=color.gray, display=display.none)
cloud6_line2 = plot(showCloud6 ? ema6_L_htf_plot : na, title="MTF3 Line 2", color=color.gray, display=display.none)
fill(cloud6_line1, cloud6_line2, title="MTF3", color=showCloud6 ? color.new(cloud6_color, 50) : na)
 
cloud5_color = isBull5 ? def_C5_Bull_Color : def_C5_Bear_Color
cloud5_line1 = plot(showCloud5 ? ema5_S_htf_plot : na, title="MTF2 Line 1", color=color.gray, display=display.none)
cloud5_line2 = plot(showCloud5 ? ema5_L_htf_plot : na, title="MTF2 Line 2", color=color.gray, display=display.none)
fill(cloud5_line1, cloud5_line2, title="MTF2", color=showCloud5 ? color.new(cloud5_color, 50) : na)
 
cloud4_color = isBull4 ? def_C4_Bull_Color : def_C4_Bear_Color
cloud4_line1 = plot(showCloud4 ? ema4_S_htf_plot : na, title="MTF1 Line 1", color=color.gray, display=display.none)
cloud4_line2 = plot(showCloud4 ? ema4_L_htf_plot : na, title="MTF1 Line 2", color=color.gray, display=display.none)
fill(cloud4_line1, cloud4_line2, title="MTF1", color=showCloud4 ? color.new(cloud4_color, 50) : na)
 
cloud180_color = isBull180 ? def_C180_Bull_Color : def_C180_Bear_Color
cloud180_line1 = plot(showCloud180 ? ema180_S : na, title="Cloud 5 Line 1", color=color.gray, display=display.none)
cloud180_line2 = plot(showCloud180 ? ema180_L : na, title="Cloud 5 Line 2", color=color.gray, display=display.none)
fill(cloud180_line1, cloud180_line2, title="Cloud 5", color=showCloud180 ? color.new(cloud180_color, 65) : na)
 
cloud72_color = isBull72 ? def_C72_Bull_Color : def_C72_Bear_Color
cloud72_line1 = plot(showCloud72 ? ema72_S : na, title="Cloud 4 Line 1", color=color.gray, display=display.none)
cloud72_line2 = plot(showCloud72 ? ema72_L : na, title="Cloud 4 Line 2", color=color.gray, display=display.none)
fill(cloud72_line1, cloud72_line2, title="Cloud 4", color=showCloud72 ? color.new(cloud72_color, 65) : na)
 
cloud3_color = isBull3 ? def_C3_Bull_Color : def_C3_Bear_Color
cloud3_line1 = plot(showCloud3 ? ema3_S : na, title="Cloud 3 Line 1", color=color.gray, display=display.none)
cloud3_line2 = plot(showCloud3 ? ema3_L : na, title="Cloud 3 Line 2", color=color.gray, display=display.none)
fill(cloud3_line1, cloud3_line2, title="Cloud 3", color=showCloud3 ? color.new(cloud3_color, 50) : na)
 
cloud2_color = isBull2 ? def_C2_Bull_Color : def_C2_Bear_Color
cloud2_line1 = plot(ema2_S, title="Cloud 2 Line 1", color=color.gray, display=display.none)
cloud2_line2 = plot(ema2_L, title="Cloud 2 Line 2", color=color.gray, display=display.none)
color veVolLayerColor = veShowPulse ? (veSpike ? color.new(veColSpike, 12) : veCoiled ? color.new(veColCoil, 18) : veBuilding ? color.new(veColBuild, 16) : veQuietBar ? color.new(veColQuiet, 78) : na) : na
fill(cloud2_line1, cloud2_line2, title="Cloud 2 / Volume Layer", color=not na(veVolLayerColor) ? veVolLayerColor : showCloud2 ? color.new(cloud2_color, 0) : na)
 
cloud1_color = isBull1 ? def_C1_Bull_Color : def_C1_Bear_Color
cloud1_line1 = plot(showCloud1 ? ema1_S : na, title="Cloud 1 Line 1", color=color.gray, display=display.none)
cloud1_line2 = plot(showCloud1 ? ema1_L : na, title="Cloud 1 Line 2", color=color.gray, display=display.none)
fill(cloud1_line1, cloud1_line2, title="Cloud 1", color=showCloud1 ? color.new(cloud1_color, 0) : na)
 
getLabelSize(sizeString) =>
    sizeString == "Tiny" ? size.tiny :
     sizeString == "Small" ? size.small :
     sizeString == "Normal" ? size.normal :
     sizeString == "Large" ? size.large :
     sizeString == "Huge" ? size.huge :
     size.normal
 
var int leftVisibleBarIdx = na
if na(leftVisibleBarIdx) and time >= chart.left_visible_bar_time
    leftVisibleBarIdx := bar_index
var int rightVisibleBarIdx = na
if time <= chart.right_visible_bar_time
    rightVisibleBarIdx := bar_index
 
getLabelPosition() =>
    int label_offset_x = 10
    int label_x_position = bar_index + 10
 
    if labelPositioning == "Chart Edge"
        label_offset_x := 7
        label_x_position := bar_index + label_offset_x
    else if labelPositioning == "Percentage Based"
        estimated_visible_bars = math.max(10, nz(rightVisibleBarIdx - leftVisibleBarIdx, 100))
        label_offset_x := math.max(2, math.min(500, int(estimated_visible_bars * labelOffsetPercent / 100.0)))
        label_x_position := bar_index + label_offset_x
    else
        label_offset_x := 10
        label_x_position := bar_index + label_offset_x
 
    label_x_position
 
var float visHigh = na
var float visLow = na
if time >= chart.left_visible_bar_time and time <= chart.right_visible_bar_time
    visHigh := na(visHigh) ? high : math.max(visHigh, high)
    visLow := na(visLow) ? low : math.min(visLow, low)
 
tfLabelName(string tf) =>
    string out = tf
    if not str.contains(tf, "D") and not str.contains(tf, "W") and not str.contains(tf, "M") and not str.contains(tf, "S")
        float m = str.tonumber(tf)
        if not na(m)
            out := m >= 60 and m % 60 == 0 ? str.tostring(int(m / 60)) + "H" : str.tostring(int(m)) + "m"
    out
 
if showLabels and barstate.islast
    cloudLabelsSize = array.size(cloudLabels)
    if cloudLabelsSize > 0
        for i = 0 to cloudLabelsSize - 1
            label.delete(array.get(cloudLabels, i))
        array.clear(cloudLabels)
 
    labelPos = getLabelPosition()
    lblSize = getLabelSize(labelSize)
    float[] lblYs = array.new_float()
    string[] lblTs = array.new_string()
    color[] lblCs = array.new_color()
 
    if showCloud1 and showLabel1
        label1Text = str.tostring(len1_S_validated) + "/" + str.tostring(len1_L_validated)
        label1Color = isBull1 ? def_C1_Bull_Color : def_C1_Bear_Color
        label1Y = (ema1_S + ema1_L) / 2
        array.push(lblYs, label1Y)
        array.push(lblTs, label1Text)
        array.push(lblCs, color.new(label1Color, 0))
 
    if showCloud2 and showLabel2
        label2Text = str.tostring(len2_S_validated) + "/" + str.tostring(len2_L_validated)
        label2Color = isBull2 ? def_C2_Bull_Color : def_C2_Bear_Color
        label2Y = (ema2_S + ema2_L) / 2
        array.push(lblYs, label2Y)
        array.push(lblTs, label2Text)
        array.push(lblCs, color.new(label2Color, 0))
 
    if showCloud3 and showLabel3
        label3Text = str.tostring(len3_S_validated) + "/" + str.tostring(len3_L_validated)
        label3Color = isBull3 ? def_C3_Bull_Color : def_C3_Bear_Color
        label3Y = (ema3_S + ema3_L) / 2
        array.push(lblYs, label3Y)
        array.push(lblTs, label3Text)
        array.push(lblCs, color.new(label3Color, 50))
 
    if showCloud72 and showLabel72
        label72Text = str.tostring(len72_S_validated) + "/" + str.tostring(len72_L_validated)
        label72Color = isBull72 ? def_C72_Bull_Color : def_C72_Bear_Color
        label72Y = (ema72_S + ema72_L) / 2
        array.push(lblYs, label72Y)
        array.push(lblTs, label72Text)
        array.push(lblCs, color.new(label72Color, 50))
 
    if showCloud180 and showLabel180
        label180Text = str.tostring(len180_S_validated) + "/" + str.tostring(len180_L_validated)
        label180Color = isBull180 ? def_C180_Bull_Color : def_C180_Bear_Color
        label180Y = (ema180_S + ema180_L) / 2
        array.push(lblYs, label180Y)
        array.push(lblTs, label180Text)
        array.push(lblCs, color.new(label180Color, 50))
 
    if showMtfLabels and showCloud4 and mtfCloud4CanPlot
        label4Text = str.tostring(len4_S_validated) + "/" + str.tostring(len4_L_validated) + " " + tfLabelName(tf4)
        label4Color = isBull4 ? def_C4_Bull_Color : def_C4_Bear_Color
        label4Y = (ema4_S_htf_plot[1] + ema4_L_htf_plot[1]) / 2
        if not na(label4Y)
            array.push(lblYs, label4Y)
            array.push(lblTs, label4Text)
            array.push(lblCs, color.new(label4Color, 50))
 
    if showMtfLabels and showCloud5 and mtfCloud5CanPlot
        label5Text = str.tostring(len5_S_validated) + "/" + str.tostring(len5_L_validated) + " " + tfLabelName(tf5)
        label5Color = isBull5 ? def_C5_Bull_Color : def_C5_Bear_Color
        label5Y = (ema5_S_htf_plot[1] + ema5_L_htf_plot[1]) / 2
        if not na(label5Y)
            array.push(lblYs, label5Y)
            array.push(lblTs, label5Text)
            array.push(lblCs, color.new(label5Color, 50))
 
    if showMtfLabels and showCloud6 and mtfCloud6CanPlot
        label6Text = str.tostring(len6_S_validated) + "/" + str.tostring(len6_L_validated) + " " + tfLabelName(tf6)
        label6Color = isBull6 ? def_C6_Bull_Color : def_C6_Bear_Color
        label6Y = (ema6_S_htf_plot[1] + ema6_L_htf_plot[1]) / 2
        if not na(label6Y)
            array.push(lblYs, label6Y)
            array.push(lblTs, label6Text)
            array.push(lblCs, color.new(label6Color, 50))
 
    if showMtfLabels and showCloud7 and mtfCloud7CanPlot
        label7Text = str.tostring(len7_S_validated) + "/" + str.tostring(len7_L_validated) + " " + tfLabelName(tf7)
        label7Color = isBull7 ? def_C7_Bull_Color : def_C7_Bear_Color
        label7Y = (ema7_S_htf_plot[1] + ema7_L_htf_plot[1]) / 2
        if not na(label7Y)
            array.push(lblYs, label7Y)
            array.push(lblTs, label7Text)
            array.push(lblCs, color.new(label7Color, 50))
 
    if showMtfLabels and showCloud8 and mtfCloud8CanPlot
        label8Text = str.tostring(len8_S_validated) + "/" + str.tostring(len8_L_validated) + " " + tfLabelName(tf8)
        label8Color = isBull8 ? def_C8_Bull_Color : def_C8_Bear_Color
        label8Y = (ema8_S_htf_plot[1] + ema8_L_htf_plot[1]) / 2
        if not na(label8Y)
            array.push(lblYs, label8Y)
            array.push(lblTs, label8Text)
            array.push(lblCs, color.new(label8Color, 50))
 
    int nLbl = array.size(lblYs)
    if nLbl > 0
        float lblGap = (nz(visHigh) - nz(visLow)) / 28.0
        int[] lblOrder = array.sort_indices(lblYs, order.ascending)
        float prevY = na
        for k = 0 to nLbl - 1
            int j = array.get(lblOrder, k)
            float y = array.get(lblYs, j)
            if not na(prevY) and lblGap > 0 and y < prevY + lblGap
                y := prevY + lblGap
            prevY := y
            array.push(cloudLabels, label.new(labelPos, y, array.get(lblTs, j), color=array.get(lblCs, j), textcolor=labelTextColor, size=lblSize, style=label.style_label_left))
 
if (showTable and barstate.islast)
    tbl_pos = getTablePosition(tablePosition)
    textSize = getTableTextSize(tableSize)
    lookaheadValue = barmerge.lookahead_off
 
    var matrix<bool> currentTFStatuses = matrix.new<bool>(3, 9, false)
 
    for tfIdx = 0 to 8
        tf = array.get(TABLE_TIMEFRAMES_STR, tfIdx)
        [cloud1_status, cloud2_status, cloud3_status] = request.security(syminfo.tickerid, tf, [ema_8_9_status_series, ema_5_12_status_series, ema_34_50_status_series], lookahead=lookaheadValue)
 
        matrix.set(currentTFStatuses, 0, tfIdx, cloud1_status)
        matrix.set(currentTFStatuses, 1, tfIdx, cloud2_status)
        matrix.set(currentTFStatuses, 2, tfIdx, cloud3_status)
 
    int[] visibleClouds = array.new<int>()
    if showCurrentClouds
        array.push(visibleClouds, 0)
        array.push(visibleClouds, 1)
        array.push(visibleClouds, 2)
    if show1hClouds
        array.push(visibleClouds, 3)
        array.push(visibleClouds, 4)
    if show1dClouds
        array.push(visibleClouds, 5)
        array.push(visibleClouds, 6)
 
    numClouds = array.size(visibleClouds)
    int[] visibleTimeframes = array.new<int>()
 
    for tfIdx = 0 to array.size(TABLE_TIMEFRAMES_STR) - 1
        showColumn = true
 
        if compactMode and (show1hClouds or show1dClouds)
            hasData = false
            for cloudIdx = 0 to numClouds - 1
                actualCloudIdx = array.get(visibleClouds, cloudIdx)
                if actualCloudIdx >= 3
                    if array.get(TABLE_TIMEFRAMES_SEC, tfIdx) >= array.get(TABLE_CLOUD_TFSEC, actualCloudIdx)
                        hasData := true
                else
                    hasData := true
 
            showColumn := hasData
 
        if showColumn
            array.push(visibleTimeframes, tfIdx)
 
    numVisibleTimeframes = array.size(visibleTimeframes)
 
    totalColumns = numVisibleTimeframes + 1
    statusTable = table.new(tbl_pos, totalColumns, numClouds + 1, border_width = 1)
 
    table.cell(statusTable, 0, 0, "Cloud", bgcolor = tbl_bg_color, text_color = tbl_header_text_color, text_halign = text.align_center, text_size = textSize)
    for i = 0 to numVisibleTimeframes - 1
        tfIdx = array.get(visibleTimeframes, i)
        table.cell(statusTable, i + 1, 0, array.get(TABLE_TIMEFRAMES_LBL, tfIdx), bgcolor = tbl_bg_color, text_color = tbl_header_text_color, text_halign = text.align_center, text_size = textSize)
 
    for rowIdx = 0 to numClouds - 1
        cloudIdx = array.get(visibleClouds, rowIdx)
        cloudLabel = array.get(TABLE_CLOUD_LABELS, cloudIdx)
 
        table.cell(statusTable, 0, rowIdx + 1, cloudLabel, bgcolor = tbl_bg_color, text_color = tbl_header_text_color, text_halign = text.align_left, text_size = textSize)
 
        for colIdx = 0 to numVisibleTimeframes - 1
            if colIdx >= array.size(visibleTimeframes)
                continue
 
            tfIdx = array.get(visibleTimeframes, colIdx)
 
            tableColIdx = colIdx + 1
 
            if tableColIdx >= totalColumns or tableColIdx >= numVisibleTimeframes + 1
                continue
 
            if tableColIdx < 0 or tableColIdx > 10
                continue
 
            canShow = true
            if cloudIdx >= 3
                canShow := array.get(TABLE_TIMEFRAMES_SEC, tfIdx) >= array.get(TABLE_CLOUD_TFSEC, cloudIdx)
 
            if canShow
                isBullStatus = false
                if cloudIdx <= 2
                    isBullStatus := matrix.get(currentTFStatuses, cloudIdx, tfIdx)
                else if cloudIdx == 3
                    isBullStatus := ema4_status_mtf
                else if cloudIdx == 4
                    isBullStatus := ema5_status_mtf
                else if cloudIdx == 5
                    isBullStatus := ema6_status_mtf
                else if cloudIdx == 6
                    isBullStatus := ema7_status_mtf
 
                int status_temp = isBullStatus ? 1 : -1
                int status = nz(status_temp, 0)
                cell_text = status == 1 ? "↗" : status == -1 ? "↘" : "N/A"
                cell_txtcolor = status == 1 ? tbl_bull_text_color : status == -1 ? tbl_bear_text_color : tbl_header_text_color
                table.cell(statusTable, tableColIdx, rowIdx + 1, cell_text, bgcolor = tbl_bg_color, text_color = cell_txtcolor, text_halign = text.align_center, text_size = textSize)
            else
                table.cell(statusTable, tableColIdx, rowIdx + 1, "--", bgcolor = tbl_bg_color, text_color = tbl_header_text_color, text_halign = text.align_center, text_size = textSize)
 
float veBrkA = veBreakRef == "Cloud 3" ? ema3_S : veBreakRef == "MTF 1" ? ema4_S_htf_plot : ema5_S_htf_plot
float veBrkB = veBreakRef == "Cloud 3" ? ema3_L : veBreakRef == "MTF 1" ? ema4_L_htf_plot : ema5_L_htf_plot
float veBrkUpper = math.max(veBrkA, veBrkB)
float veBrkLower = math.min(veBrkA, veBrkB)
bool veBrkUpX = ta.crossover(close, veBrkUpper)
bool veBrkDnX = ta.crossunder(close, veBrkLower)
bool veBreakUp = veShowBreaks and barstate.isconfirmed and not na(veBrkUpper) and veBrkUpX and volpct >= veBreakVolTh
bool veBreakDown = veShowBreaks and barstate.isconfirmed and not na(veBrkLower) and veBrkDnX and volpct >= veBreakVolTh
 
color veDotColor = veState == "SPIKE" and veDotSpike ? color.new(veColSpike, 0) : veState == "BUILDING" and veDotBuild ? color.new(veColBuild, 20) : veState == "COILED" and veDotCoil ? color.new(veColCoil, 0) : veState == "QUIET" and veDotQuiet ? color.new(veColQuiet, 70) : na
plotshape(veShowStateDots and not na(veDotColor), title="Volume State Dot", location=location.bottom, style=shape.circle, size=size.tiny, color=veDotColor)
color veBreakDotColor = veBreakUp ? color.new(color.aqua, 0) : veBreakDown ? color.new(#e64ac1, 0) : na
plotshape(not na(veBreakDotColor), title="Confirmed Break Dot", location=location.bottom, style=shape.circle, size=size.tiny, color=veBreakDotColor)
barcolor(veTintSpikes and veSpike ? veColSpike : na, title="Spike Bar Tint")
 
bool veIsCrypto = syminfo.type == "crypto"
var line veNextLine = na
var label veNextLbl = na
if barstate.islast
    line.delete(veNextLine)
    label.delete(veNextLbl)
    if veShowNextEnergy and veSlotMode and (veIsCrypto or (barstate.isrealtime and session.ismarket))
        int veOff2 = veIsWknd ? veSlots : 0
        int veOffAlt = veIsWknd ? 0 : veSlots
        float[] veTmp = array.new<float>()
        float[] veTmpAlt = array.new<float>()
        for i = 0 to veSlots - 1
            float v2 = array.get(veSlotAvg, veOff2 + i)
            if not na(v2)
                array.push(veTmp, v2)
            float v3 = array.get(veSlotAvg, veOffAlt + i)
            if not na(v3)
                array.push(veTmpAlt, v3)
        if array.size(veTmp) >= veDaySlots / 2
            float veMed = array.median(veTmp)
            float veMedAlt = array.size(veTmpAlt) >= veDaySlots / 2 ? array.median(veTmpAlt) : na
            int veCur2 = veIdx - veOff2
            int veAhead = -1
            float veHot = na
            float veHotMed = na
            int veHorizon = veIsCrypto ? 3 * veSlots - 1 : math.min(veSlots - 1, math.max(8, veSlots / 3))
            for j = 1 to veHorizon
                int k = (veCur2 + j) % veSlots
                int veDowJ = dayofweek(time + j * veTfSec * 1000, "UTC")
                bool veWkndJ = veWeekendSplit and veMarketCrypto and (veDowJ == dayofweek.saturday or veDowJ == dayofweek.sunday)
                float vk = array.get(veSlotAvg, (veWkndJ ? veSlots : 0) + k)
                float veMedJ = veWkndJ == veIsWknd ? veMed : veMedAlt
                if not na(vk) and not na(veMedJ) and veMedJ > 0 and vk >= veMedJ * veEnergyMult
                    veAhead := j
                    veHot := vk
                    veHotMed := veMedJ
                    break
            if veAhead > 0
                int veT = time + veAhead * veTfSec * 1000
                veNextLine := line.new(veT, low, veT, high, xloc=xloc.bar_time, extend=extend.both, style=line.style_dotted, width=1, color=color.new(color.aqua, 45))
                veNextLbl := label.new(veT, high, " x" + str.tostring(math.round(veHot / veHotMed, 1)) + " typical", style=label.style_label_down, xloc=xloc.bar_time, color=color.new(color.aqua, 80), textcolor=color.aqua, size=size.small)
 
if (showVolumeTable and barstate.islast)
    baseRows = 1
    volumeRows = 0
    enhancedRows = 0
    volumeSignalsRows = 1
    if showCloudAlignment
        volumeSignalsRows += 1
    if showTrendDisplay
        volumeSignalsRows += 1
    if showVolumeConviction
        volumeSignalsRows += 1
    if showTradingSignal
        volumeSignalsRows += 1
    if showRiskLevel
        volumeSignalsRows += 1
 
    if showRipDayRvol
        volumeRows += 1
    if showRipCandleRvol
        volumeRows += 2
    if showVeNow
        volumeRows += 1
    if showVePace
        volumeRows += 1
    if showVeState
        volumeRows += 1
    if showVeBias
        volumeRows += 1
 
    if showTimeInterval
        enhancedRows += 1
    if showLondonTime
        enhancedRows += 1
    if showTokyoTime
        enhancedRows += 1
 
    totalVolumeRows = baseRows + volumeRows + enhancedRows + volumeSignalsRows
 
    vol_tbl_pos = getTablePosition(volumeTablePosition)
 
    volumeTableHeaderSize = switch volumeTableSize
        "Small" => size.tiny
        "Normal" => size.small
        "Large" => size.normal
        => size.small
 
    volumeTableTextSize = switch volumeTableSize
        "Small" => size.tiny
        "Normal" => size.small
        "Large" => size.normal
        => size.small
 
    volumeTable = table.new(vol_tbl_pos, 2, totalVolumeRows, bgcolor=tbl_bg_color, border_width=1, border_color=color.gray)
 
    table.cell(volumeTable, 0, 0, "VOLUME ANALYSIS", text_color=tbl_header_text_color, text_size=volumeTableHeaderSize, bgcolor=tbl_bg_color, text_halign=text.align_center)
    table.merge_cells(volumeTable, 0, 0, 1, 0)
 
    currentRow = 1
 
    if showRipDayRvol
        ripDayTxt = na(ripDayRvol) ? "--" : "Vol " + ripFmtVol(ripDayVol) + " · Avg " + ripFmtVol(ripDayAvg) + " · " + str.tostring(ripDayRvol) + "%"
        ripDayColor = na(ripDayRvol) ? color.gray : ripDayRvol <= 20 ? color.red : color.green
        table.cell(volumeTable, 0, currentRow, "RIPSTER RVOL (20" + ripRvolTf + "):", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, ripDayTxt, text_color=ripDayColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showRipCandleRvol
        ripCandleTxt = ripFmtVol(volume) + " · " + (na(ripCandleRvol) ? "--" : str.tostring(math.round(ripCandleRvol, 2)) + "%")
        table.cell(volumeTable, 0, currentRow, "CANDLE RVOL (50):", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, ripCandleTxt, text_color=ripCandleColor(ripCandleRvol), text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
        ripLastTxt = na(ripLastRvol) ? "--" : str.tostring(math.round(ripLastRvol, 2)) + "%"
        table.cell(volumeTable, 0, currentRow, "LAST CANDLE RVOL:", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, ripLastTxt, text_color=ripCandleColor(ripLastRvol), text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showVeNow
        veNowArrow = not na(slotRVol) ? (slotRVol >= 200 ? "↑" : slotRVol >= 150 ? "↗" : slotRVol >= 100 ? "→" : slotRVol >= 50 ? "↘" : "↓") : "→"
        veNowColor = not na(slotRVol) ? (slotRVol >= 200 ? color.blue : slotRVol >= 150 ? color.green : slotRVol >= 100 ? color.gray : slotRVol >= 50 ? color.orange : color.red) : color.gray
        veNowTxt = candleVolumeDisplay + "  " + veNowArrow + " " + (not na(slotRVol) ? str.tostring(math.round(slotRVol)) + "%" : "--")
        veNowLbl = veSlotMode and not na(veBase0) ? "NOW (vs same time-of-day):" : "NOW (vs recent average):"
        table.cell(volumeTable, 0, currentRow, veNowLbl, text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, veNowTxt, text_color=veNowColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showVePace
        [veTypCum, veTypTot, veFilled] = veTypical()
        bool veReady = veSlotMode and veFilled >= veDaySlots / 2 and veTypCum > 0
        float vePace = veReady ? veCumNow / veTypCum * 100 : na
        vePaceTxt = not veSlotMode ? "intraday only" : veNoVol ? "N/A" : not veReady ? "learning..." : str.tostring(math.round(vePace)) + "%  → " + str.tostring(math.round(veCumNow / veTypCum, 1)) + "x day"
        vePaceColor = na(vePace) ? color.gray : vePace >= 200 ? color.blue : vePace >= 140 ? color.green : vePace >= 80 ? color.white : vePace >= 50 ? color.orange : color.red
        table.cell(volumeTable, 0, currentRow, "PACE (today vs typical):", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, vePaceTxt, text_color=vePaceColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showVeState
        table.cell(volumeTable, 0, currentRow, "STATE:", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, veState, text_color=veStateColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showVeBias
        veBiasTxt = na(veBiasPct) ? "--" : str.tostring(math.round(veBiasPct)) + "% up-volume " + (veBiasPct >= 55 ? "↑" : veBiasPct <= 45 ? "↓" : "→")
        veBiasColor = na(veBiasPct) ? color.gray : veBiasPct >= 60 ? color.green : veBiasPct >= 55 ? color.new(color.green, 30) : veBiasPct <= 40 ? color.red : veBiasPct <= 45 ? color.new(color.red, 30) : color.white
        table.cell(volumeTable, 0, currentRow, "BIAS (20-bar volume):", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, veBiasTxt, text_color=veBiasColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showTimeInterval
        nyHours = hour(time, "America/New_York")
        nyMinutes = minute(time, "America/New_York")
        nyTime = nyHours * 100 + nyMinutes
        nyDayOfWeek = dayofweek(time, "America/New_York")
 
        isWeekend = nyDayOfWeek == 1 or nyDayOfWeek == 7
 
        sessionName = ""
        timeRange = ""
 
        if isWeekend
            sessionName := "NY WkndClose"
            timeRange := ""
        else if nyTime >= 400 and nyTime < 930
            sessionName := "NY PreMarket"
            timeRange := "04:00-09:30"
        else if nyTime >= 930 and nyTime < 1200
            sessionName := "NY Morning"
            timeRange := "09:30-12:00"
        else if nyTime >= 1200 and nyTime < 1500
            sessionName := "NY Afternoon"
            timeRange := "12:00-15:00"
        else if nyTime >= 1500 and nyTime < 1600
            sessionName := "NY Close"
            timeRange := "15:00-16:00"
        else if nyTime >= 1600 and nyTime < 2000
            sessionName := "NY PostMarket"
            timeRange := "16:00-20:00"
        else
            sessionName := "NY Overnight"
            timeRange := "20:00-04:00"
        displayValue = isWeekend ? "Closed" : veSessText(veNyPct)
        cellText = isWeekend ? sessionName : sessionName + " " + timeRange + ":"
 
        table.cell(volumeTable, 0, currentRow, cellText, text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
 
        sessionColor = isWeekend ? color.gray : veSessColor(veNyPct)
 
        table.cell(volumeTable, 1, currentRow, displayValue, text_color=sessionColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showLondonTime
        lonHours = hour(time, "Europe/London")
        lonMinutes = minute(time, "Europe/London")
        lonTime = lonHours * 100 + lonMinutes
        lonDayOfWeek = dayofweek(time, "Europe/London")
 
        isWeekend = lonDayOfWeek == 1 or lonDayOfWeek == 7
 
        sessionName = ""
        timeRange = ""
 
        if isWeekend
            sessionName := "LON WkndClose"
            timeRange := ""
        else if lonTime >= 600 and lonTime < 800
            sessionName := "LON PreMarket"
            timeRange := "06:00-08:00"
        else if lonTime >= 800 and lonTime < 1200
            sessionName := "LON Morning"
            timeRange := "08:00-12:00"
        else if lonTime >= 1200 and lonTime < 1630
            sessionName := "LON Afternoon"
            timeRange := "12:00-16:30"
        else if lonTime >= 1630 and lonTime < 1700
            sessionName := "LON Close"
            timeRange := "16:30-17:00"
        else if lonTime >= 1700 and lonTime < 2000
            sessionName := "LON PostMarket"
            timeRange := "17:00-20:00"
        else
            sessionName := "LON Overnight"
            timeRange := "20:00-06:00"
        displayValue = isWeekend ? "Closed" : veSessText(veLonPct)
        cellText = isWeekend ? sessionName : sessionName + " " + timeRange + ":"
 
        table.cell(volumeTable, 0, currentRow, cellText, text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
 
        sessionColor = isWeekend ? color.gray : veSessColor(veLonPct)
 
        table.cell(volumeTable, 1, currentRow, displayValue, text_color=sessionColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showTokyoTime
        tyoHours = hour(time, "Asia/Tokyo")
        tyoMinutes = minute(time, "Asia/Tokyo")
        tyoTime = tyoHours * 100 + tyoMinutes
        tyoDayOfWeek = dayofweek(time, "Asia/Tokyo")
 
        isWeekend = tyoDayOfWeek == 1 or tyoDayOfWeek == 7
 
        sessionName = ""
        timeRange = ""
 
        if isWeekend
            sessionName := "TYO WkndClose"
            timeRange := ""
        else if tyoTime >= 800 and tyoTime < 900
            sessionName := "TYO PreMarket"
            timeRange := "08:00-09:00"
        else if tyoTime >= 900 and tyoTime < 1130
            sessionName := "TYO Morning"
            timeRange := "09:00-11:30"
        else if tyoTime >= 1130 and tyoTime < 1230
            sessionName := "TYO Lunch"
            timeRange := "11:30-12:30"
        else if tyoTime >= 1230 and tyoTime < 1500
            sessionName := "TYO Afternoon"
            timeRange := "12:30-15:00"
        else if tyoTime >= 1500 and tyoTime < 1530
            sessionName := "TYO Close"
            timeRange := "15:00-15:30"
        else
            sessionName := "TYO Overnight"
            timeRange := "15:30-08:00"
        displayValue = isWeekend ? "Closed" : veSessText(veTyoPct)
        cellText = isWeekend ? sessionName : sessionName + " " + timeRange + ":"
 
        table.cell(volumeTable, 0, currentRow, cellText, text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
 
        sessionColor = isWeekend ? color.gray : veSessColor(veTyoPct)
 
        table.cell(volumeTable, 1, currentRow, displayValue, text_color=sessionColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    table.cell(volumeTable, 0, currentRow, "CLOUD + VOLUME READ", text_color=tbl_header_text_color, text_size=volumeTableHeaderSize, bgcolor=tbl_bg_color, text_halign=text.align_center)
    table.merge_cells(volumeTable, 0, currentRow, 1, currentRow)
    currentRow += 1
 
    if showCloudAlignment
        dominantPercent = bullishCloudPercent >= bearishCloudPercent ? bullishCloudPercent : bearishCloudPercent
        isDominantBullish = bullishCloudPercent >= bearishCloudPercent
 
        alignmentSuffix = ""
        if dominantPercent == 100.0 and activeClouds > 1
            alignmentSuffix := " 100%"
        else
            alignmentSuffix := " (" + str.tostring(dominantPercent) + "%)"
 
        cloudAlignmentText = str.tostring(bullishClouds) + "B/" + str.tostring(bearishClouds) + "Be" + alignmentSuffix
        cloudAlignmentColor = switch overallTrend
            "STRONG BULL" => color.lime
            "BULL" => color.green
            "STRONG BEAR" => dominantPercent == 100.0 ? color.red : #FF6B6B
            "BEAR" => color.red
            "MIXED" => color.yellow
            "NEUTRAL" => color.yellow
            => color.gray
 
        table.cell(volumeTable, 0, currentRow, formatTimeframe(timeframe.period) + " Clouds [" + cloudAlignmentStrategy + "]:", text_color=tbl_header_text_color, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        table.cell(volumeTable, 1, currentRow, cloudAlignmentText, text_color=cloudAlignmentColor, text_size=volumeTableTextSize, bgcolor=tbl_bg_color)
        currentRow += 1
 
    if showTrendDisplay
        trendDisplayName = switch overallTrend
            "STRONG BULL" => "↑ STRONG BULL"
            "BULL" => "↗ BULL"
            "MIXED" => "⤨ MIXED"
            "NEUTRAL" => " NEUTRAL"
            "BEAR" => "↘ BEAR"
            "STRONG BEAR" => "↓ STRONG BEAR"
            => " NEUTRAL"
 
        cloudAlignmentColor = switch overallTrend
            "STRONG BULL" => color.lime
            "BULL" => color.green
            "MIXED" => color.yellow
            "NEUTRAL" => color.yellow
            "BEAR" => color.red
            "STRONG BEAR" => #FF6B6B
            => color.gray
 
        table.cell(volumeTable, 0, currentRow, formatTimeframe(timeframe.period) + " Trend [" + cloudAlignmentStrategy + "]:", text_color=color.white, text_size=volumeTableTextSize)
        table.cell(volumeTable, 1, currentRow, trendDisplayName, text_color=cloudAlignmentColor, text_size=volumeTableTextSize)
        currentRow += 1
 
    if showVolumeConviction
        volumeConvictionArrow = switch volumeConviction
            "EXTREME" => "↑"
            "HIGH" => "↗"
            "NORMAL" => "→"
            "LOW" => "↘"
            "VERY LOW" => "↓"
            "N/A" => "-"
            => "→"
 
        volumeConvictionColor = switch volumeConviction
            "EXTREME" => color.blue
            "HIGH" => color.green
            "NORMAL" => color.gray
            "LOW" => color.orange
            "VERY LOW" => color.red
            "N/A" => color.gray
            => color.white
 
        table.cell(volumeTable, 0, currentRow, formatTimeframe(timeframe.period) + (veSlotMode and not na(veBase0) ? " Volume Level [time of day]:" : " Volume Level [recent average]:"), text_color=color.white, text_size=volumeTableTextSize)
        table.cell(volumeTable, 1, currentRow, volumeConvictionArrow + " " + volumeConviction, text_color=volumeConvictionColor, text_size=volumeTableTextSize)
        currentRow += 1
 
    if showTradingSignal
        signalColor = switch signal
            "STRONG UP" => color.lime
            "UP" => color.green
            "STRONG DOWN" => color.red
            "DOWN" => #FF6B6B
            "HIGH VOLUME, MIXED" => color.orange
            "LOW ACTIVITY" => color.gray
            "WAIT" => color.yellow
            "NO VOLUME DATA" => color.gray
            => color.white
 
        table.cell(volumeTable, 0, currentRow, formatTimeframe(timeframe.period) + " Combined Read [" + cloudAlignmentStrategy + "]:", text_color=color.white, text_size=volumeTableTextSize)
        table.cell(volumeTable, 1, currentRow, signal, text_color=signalColor, text_size=volumeTableTextSize)
        currentRow += 1
 
    if showRiskLevel
        riskColor = switch riskLevel
            "CLEAR SETUP" => color.green
            "MIXED SETUP" => color.yellow
            "WEAK SETUP" => color.yellow
            "UNCLEAR SETUP" => color.red
            "NO SETUP" => color.gray
            "N/A" => color.gray
            => color.white
 
        table.cell(volumeTable, 0, currentRow, formatTimeframe(timeframe.period) + " Setup Quality [" + cloudAlignmentStrategy + "]:", text_color=color.white, text_size=volumeTableTextSize)
        table.cell(volumeTable, 1, currentRow, riskLevel, text_color=riskColor, text_size=volumeTableTextSize)
 
var bool prev_isBull1 = false
var bool prev_isBull2 = false
var bool prev_isBull3 = false
var bool prev_ema4_status_mtf = false
var bool prev_ema5_status_mtf = false
var bool prev_ema6_status_mtf = false
var bool prev_ema7_status_mtf = false
var string prev_signal = ""
 
curr_isBull1 = ema1_S >= ema1_L
curr_isBull2 = ema2_S >= ema2_L
curr_isBull3 = ema3_S >= ema3_L
curr_ema4_status_mtf = ema4_status_mtf
curr_ema5_status_mtf = ema5_status_mtf
curr_ema6_status_mtf = ema6_status_mtf
curr_ema7_status_mtf = ema7_status_mtf
 
bool alertBarConfirmed = barstate.isconfirmed
 
cloud1_bullish_change = not prev_isBull1 and curr_isBull1
cloud1_bearish_change = prev_isBull1 and not curr_isBull1
alertcondition(alertBarConfirmed and cloud1_bullish_change, title="Cloud 1 ↗ Bullish", message="{{close}} - Up ↗ Cloud 1")
alertcondition(alertBarConfirmed and cloud1_bearish_change, title="Cloud 1 ↘ Bearish", message="{{close}} - Down ↘ Cloud 1")
 
cloud2_bullish_change = not prev_isBull2 and curr_isBull2
cloud2_bearish_change = prev_isBull2 and not curr_isBull2
alertcondition(alertBarConfirmed and cloud2_bullish_change, title="Cloud 2 ↗ Bullish", message="{{close}} - Up ↗ Cloud 2")
alertcondition(alertBarConfirmed and cloud2_bearish_change, title="Cloud 2 ↘ Bearish", message="{{close}} - Down ↘ Cloud 2")
 
cloud3_bullish_change = not prev_isBull3 and curr_isBull3
cloud3_bearish_change = prev_isBull3 and not curr_isBull3
alertcondition(alertBarConfirmed and cloud3_bullish_change, title="Cloud 3 ↗ Bullish", message="{{close}} - Up ↗ Cloud 3")
alertcondition(alertBarConfirmed and cloud3_bearish_change, title="Cloud 3 ↘ Bearish", message="{{close}} - Down ↘ Cloud 3")
 
mtf1_bullish_change = not prev_ema4_status_mtf and curr_ema4_status_mtf
mtf1_bearish_change = prev_ema4_status_mtf and not curr_ema4_status_mtf
alertcondition(alertBarConfirmed and mtfCloud4CanPlot and mtf1_bullish_change, title="MTF 1 ↗ Bullish", message="{{close}} - Up ↗ MTF 1")
alertcondition(alertBarConfirmed and mtfCloud4CanPlot and mtf1_bearish_change, title="MTF 1 ↘ Bearish", message="{{close}} - Down ↘ MTF 1")
 
mtf2_bullish_change = not prev_ema5_status_mtf and curr_ema5_status_mtf
mtf2_bearish_change = prev_ema5_status_mtf and not curr_ema5_status_mtf
alertcondition(alertBarConfirmed and mtfCloud5CanPlot and mtf2_bullish_change, title="MTF 2 ↗ Bullish", message="{{close}} - Up ↗ MTF 2")
alertcondition(alertBarConfirmed and mtfCloud5CanPlot and mtf2_bearish_change, title="MTF 2 ↘ Bearish", message="{{close}} - Down ↘ MTF 2")
 
mtf3_bullish_change = not prev_ema6_status_mtf and curr_ema6_status_mtf
mtf3_bearish_change = prev_ema6_status_mtf and not curr_ema6_status_mtf
alertcondition(alertBarConfirmed and mtfCloud6CanPlot and mtf3_bullish_change, title="MTF 3 ↗ Bullish", message="{{close}} - Up ↗ MTF 3")
alertcondition(alertBarConfirmed and mtfCloud6CanPlot and mtf3_bearish_change, title="MTF 3 ↘ Bearish", message="{{close}} - Down ↘ MTF 3")
 
mtf4_bullish_change = not prev_ema7_status_mtf and curr_ema7_status_mtf
mtf4_bearish_change = prev_ema7_status_mtf and not curr_ema7_status_mtf
alertcondition(alertBarConfirmed and mtfCloud7CanPlot and mtf4_bullish_change, title="MTF 4 ↗ Bullish", message="{{close}} - Up ↗ MTF 4")
alertcondition(alertBarConfirmed and mtfCloud7CanPlot and mtf4_bearish_change, title="MTF 4 ↘ Bearish", message="{{close}} - Down ↘ MTF 4")
 
signal_strong_buy = prev_signal != "STRONG UP" and signal == "STRONG UP"
signal_buy = prev_signal != "UP" and signal == "UP"
signal_strong_sell = prev_signal != "STRONG DOWN" and signal == "STRONG DOWN"
signal_sell = prev_signal != "DOWN" and signal == "DOWN"
signal_high_vol_mixed = prev_signal != "HIGH VOLUME, MIXED" and signal == "HIGH VOLUME, MIXED"
 
alertcondition(alertBarConfirmed and signal_strong_buy, title="Strong Up Read", message="STRONG UP - High volume with strong bullish cloud alignment")
alertcondition(alertBarConfirmed and signal_buy, title="Up Read", message="UP - Good volume with bullish cloud alignment")
alertcondition(alertBarConfirmed and signal_strong_sell, title="Strong Down Read", message="STRONG DOWN - High volume with strong bearish cloud alignment")
alertcondition(alertBarConfirmed and signal_sell, title="Down Read", message="DOWN - Good volume with bearish cloud alignment")
alertcondition(alertBarConfirmed and signal_high_vol_mixed, title="High Volume Mixed", message="HIGH VOLUME, MIXED - High volume with conflicting cloud signals")
 
state_spike_start = veState == "SPIKE" and veState[1] != "SPIKE"
state_coiled_start = veState == "COILED" and veState[1] != "COILED"
alertcondition(alertBarConfirmed and state_spike_start, title="Volume Spike", message="Trend Clouds: volume SPIKE vs same time of day")
alertcondition(alertBarConfirmed and state_coiled_start, title="Volume Coiled", message="Trend Clouds: volume COILED - quiet volume, tight range")
alertcondition(alertBarConfirmed and (veBreakUp or veBreakDown), title="Confirmed Cloud Break", message="Trend Clouds: close across the reference cloud with volume")
 
if barstate.isconfirmed
    prev_isBull1 := curr_isBull1
    prev_isBull2 := curr_isBull2
    prev_isBull3 := curr_isBull3
    prev_ema4_status_mtf := curr_ema4_status_mtf
    prev_ema5_status_mtf := curr_ema5_status_mtf
    prev_ema6_status_mtf := curr_ema6_status_mtf
    prev_ema7_status_mtf := curr_ema7_status_mtf
    prev_signal := signal

← 返回列表