本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Overlay HUD: MM, ATR%/extension, %MaxATRx, volume, STS, VCPT, optional MA stops
// Credits: Minervini Trend Template by yogy.frestarahmawan (Mozilla Public License 2.0)
indicator("GreenStar Heads-Up Display", shorttitle="GS2 HUD", overlay=true)
import TradingView/ta/7
// ==================== INPUTS ====================
// Layout & Position
layout_mode = input.string('Wide', title='Layout Mode', options=['Wide', 'Stacked'], group='Layout & Position', tooltip='Wide=horizontal rows, Stacked=vertical single column')
posTable = input.string(defval='Top Right', title='Main HUD Position', options=['Top Left', 'Top Right', 'Bottom Left', 'Bottom Right'], group='Layout & Position')
posTable_SI = input.string(defval='Top Right', title='RS Block Position', options=['Top Left', 'Top Right', 'Bottom Left', 'Bottom Right'], group='Layout & Position', tooltip='Sector & Industry table. Same corner as Main HUD joins into one wide table; different corner separates it. STS/VCPT stay on the main grid with MM.')
tbl_size = input.string('Normal', title='Text Size', options=['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group='Layout & Position')
show_ma_section = input.bool(false, title='Show MA Distance Section', group='Layout & Position', tooltip='Display MA percentage distance and ATR multiples (rows 3-4)')
show_volume_section = input.bool(true, title='Show Volume Section', group='Layout & Position', tooltip='Display RelVol Day, RelVol Proj, Vol Buzz, and Proj/Avg. OBV stays visible under VCPT either way.')
add_empty_row_above = input.int(3, title='Main HUD: Rows Above', minval=0, maxval=10, step=1, group='Layout & Position')
add_empty_row_below = input.int(2, title='Main HUD: Rows Below', minval=0, maxval=10, step=1, group='Layout & Position')
add_empty_row_above_si = input.int(3, title='RS Block: Rows Above', minval=0, maxval=10, step=1, group='Layout & Position')
add_empty_row_below_si = input.int(0, title='RS Block: Rows Below', minval=0, maxval=10, step=1, group='Layout & Position')
// Minervini Method (MM)
show_mm_warning_details = input.bool(true, title='Show Details on Warning (6-7/8)', group='Minervini Method', tooltip='Display which MM criteria failed when score is 6 or 7')
show_mm_failure_details = input.bool(false, title='Show Details on Failure (≤5/8)', group='Minervini Method', tooltip='Display which MM criteria failed when score is 5 or below')
// ATR & Extension
ma_period = input.int(50, title='Reference MA Period', minval=1, group='ATR & Extension', tooltip='MA period used for extension calculation (xFrom)')
atr_min = input.float(5.0, title='ATR% Minimum', minval=0, step=0.1, group='ATR & Extension', tooltip='Minimum ATR% for green/pass status')
atr_max = input.float(9.0, title='ATR% Maximum', minval=0, step=0.1, group='ATR & Extension', tooltip='Maximum ATR% for green/pass status')
atr_warn_buffer = input.float(2.5, title='ATR% Warning Buffer', minval=0, step=0.1, group='ATR & Extension', tooltip='Yellow zone extends this far outside green band (default 2.5 = yellow 2.5-11.5 when green is 5-9)')
ext_min = input.float(0.0, title='Extension Minimum', step=0.1, group='ATR & Extension', tooltip='Minimum ATR multiples from MA for green status')
ext_max = input.float(3.5, title='Extension Green Max', minval=0, step=0.1, group='ATR & Extension', tooltip='Maximum ATR multiples from MA for green status (default 3.5)')
ext_yellow_max = input.float(6.0, title='Extension Yellow Max', minval=0, step=0.1, group='ATR & Extension', tooltip='Maximum ATR multiples for yellow; above = red (default 6)')
show_atr_details = input.bool(true, title='Show Out-of-Range Details', group='ATR & Extension', tooltip='Display actual values when ATR or Extension are outside pass range')
show_atr_dollars = input.bool(false, title='Show ATR Dollar Amounts', group='ATR & Extension', tooltip='Append ($) to 14dATR and 10/21/50d ATR rows')
lod_green_max = input.float(0.5, title='xFromLoD Green Max (ATR×)', minval=0, step=0.05, group='ATR & Extension', tooltip='Below this = green (default 0.5 = 50% of ATR from session low)')
lod_yellow_max = input.float(0.7, title='xFromLoD Yellow Max (ATR×)', minval=0, step=0.05, group='ATR & Extension', tooltip='Below this = yellow; at/above = red (default 0.7 = 70% of ATR)')
xfrom_max_lookback = input.int(120, title='%MaxATRx Lookback', minval=5, maxval=500, group='ATR & Extension', tooltip='Bars for highest xFromMA when computing %MaxATRx (screener default 120 daily ≈ 2 quarters)')
// Moving Averages
ma1_period = input.int(10, title='MA 1 Period', minval=1, group='Moving Averages')
ma1_type = input.string('SMA', title='MA 1 Type', options=['SMA', 'EMA'], group='Moving Averages')
ma2_period = input.int(21, title='MA 2 Period', minval=1, group='Moving Averages')
ma2_type = input.string('EMA', title='MA 2 Type', options=['SMA', 'EMA'], group='Moving Averages')
ma3_period = input.int(50, title='MA 3 Period', minval=1, group='Moving Averages')
ma3_type = input.string('SMA', title='MA 3 Type', options=['SMA', 'EMA'], group='Moving Averages')
show_ma_lines = input.bool(true, title='Plot MA Lines on Chart', group='Moving Averages')
ma1_line_color = input.color(#00bcd4, title='MA 1 Line Color', group='Moving Averages')
ma2_line_color = input.color(#66bb6a, title='MA 2 Line Color', group='Moving Averages')
ma3_line_color = input.color(#056656, title='MA 3 Line Color', group='Moving Averages')
ma_line_width = input.int(2, title='MA Line Width', minval=1, maxval=4, group='Moving Averages')
// MA line-color marker (▌) — own column, forced narrow (% of pane)
ma_swatch_glyph = "▌"
ma_swatch_cell_width = 1
// Ideal Stop Percentage Distance (for MA percentage distance coloring)
stop_pct_min = input.float(0.0, title='Ideal Stop % Min', minval=0, step=0.1, group='Ideal Stop % Distance', tooltip='Minimum percentage distance for green (ideal tight stop zone)')
stop_pct_max = input.float(3.0, title='Ideal Stop % Max', minval=0, step=0.1, group='Ideal Stop % Distance', tooltip='Maximum percentage distance for green (ideal tight stop zone)')
stop_pct_warn_max = input.float(6.0, title='Stop % Warning Max', minval=0, step=0.1, group='Ideal Stop % Distance', tooltip='Maximum percentage distance for yellow (acceptable stop zone)')
// Ideal ATR Multiple Distance (for ATR multiple distance coloring)
atr_dist_min = input.float(0.0, title='Ideal ATR Multiple Min', minval=0, step=0.1, group='ATR Multiple Distance', tooltip='Minimum ATR multiples for green (test entry zone)')
atr_dist_max = input.float(1.5, title='Ideal ATR Multiple Max', minval=0, step=0.1, group='ATR Multiple Distance', tooltip='Maximum ATR multiples for green (test entry zone)')
atr_dist_warn_max = input.float(3.5, title='ATR Multiple Warning Max', minval=0, step=0.1, group='ATR Multiple Distance', tooltip='Maximum ATR multiples for yellow (acceptable entry zone)')
atr_dist_fail_max = input.float(5.0, title='ATR Multiple Fail Max', minval=0, step=0.1, group='ATR Multiple Distance', tooltip='Above this = red (stop too wide); between warn max and this = default')
// Bollinger Bands (defaults: BB1 off, BB2 on for 21 EMA, BB3 off)
show_bb1 = input.bool(false, title='Show BB for MA 1', group='Bollinger Bands')
show_bb2 = input.bool(true, title='Show BB for MA 2', group='Bollinger Bands', tooltip='Default ON — pairs with MA 2 (21 EMA)')
show_bb3 = input.bool(false, title='Show BB for MA 3', group='Bollinger Bands')
bb_source = input.source(close, title='BB Source', group='Bollinger Bands')
bb_stddev = input.float(2.0, title='BB Standard Deviation', minval=0.001, maxval=50, step=0.1, group='Bollinger Bands')
bb_offset = input.int(0, title='BB Offset', minval=-500, maxval=500, group='Bollinger Bands')
bb_upper_color = input.color(color.new(#0000ff, 76), title='BB Upper Line Color', group='Bollinger Bands')
bb_lower_color = input.color(color.new(#0000ff, 76), title='BB Lower Line Color', group='Bollinger Bands')
bb_fill_color = input.color(color.new(#000000, 80), title='BB Fill Color', group='Bollinger Bands')
bb_line_width = input.int(1, title='BB Line Width', minval=1, maxval=4, group='Bollinger Bands')
// Volume & OBV (Jeff Sun Swing Data formulas)
vol_ma_len = input.int(50, title='Volume MA Length', minval=5, maxval=100, group='Volume & OBV', tooltip='SMA length for Avg Vol, Rel Vol, and Vol Buzz (Jeff default 50)')
relvol_time_len = input.int(10, title='RelVol Day Lookback', minval=1, maxval=50, group='Volume & OBV', tooltip='Sessions for same-clock cumulative volume average (TV screener default 10)')
obv_lookback = input.int(10, title='OBV Lookback Period', minval=1, group='Volume & OBV', tooltip='Bars to look back for OBV direction comparison')
vol_buzz_green_min = input.float(30.0, title='Vol Buzz Green Min (%)', step=1.0, group='Volume & OBV', tooltip='At or above = green (real bar spike)')
vol_buzz_red_below = input.float(-15.0, title='Vol Buzz Red Below (%)', maxval=0, step=1.0, group='Volume & OBV', tooltip='Below this = red (dead bar); between here and green min = yellow')
// Sector & Industry
sector_rs_len = input.int(20, title='RS Rank Period', group='Sector & Industry', tooltip='Time period for sector/industry relative strength ranking')
// STS & VCP (Jeff Sun momentum/consolidation metrics)
sts_lookback = input.int(25, title='STS Lookback Period', minval=10, maxval=100, group='STS & VCP', tooltip='Bars for STS percentile ranking vs SPY (Jeff Sun default 25)')
sts_green_min = input.float(90.0, title='STS Green Min (%)', minval=0, maxval=100, step=5, group='STS & VCP', tooltip='STS percentile at or above = green (default 90)')
sts_yellow_min = input.float(65.0, title='STS Yellow Min (%)', minval=0, maxval=100, step=5, group='STS & VCP', tooltip='STS percentile from yellow min up to green = yellow (default 65–89); below = red')
vcp_tightness_len = input.int(5, title='VCP Lookback (Bars)', minval=2, maxval=20, group='STS & VCP', tooltip='Bars to measure closing spread (default 5)')
vcp_adr_len = input.int(20, title='VCP ADR Lookback', minval=10, maxval=50, group='STS & VCP', tooltip='Bars to calculate Average Daily Range % for VCP normalization (default 20)')
vcp_baseline = input.int(50, title='VCP Historical Baseline', minval=10, maxval=200, group='STS & VCP', tooltip='Window to normalize VCP 0-100 score (default 50)')
vcp_tight_max = input.float(10.0, title='VCP Super Tight Max', minval=0, maxval=50, step=1, group='STS & VCP', tooltip='≤ this = Success color (source default 10)')
vcp_yellow_max = input.float(25.0, title='VCP Tight/Yellow Max', minval=0, maxval=100, step=1, group='STS & VCP', tooltip='≤ this = Warning color (source default 25); above = Failure color (same as Vol Buzz)')
// Appearance
bg_col = input(color.new(#000000, 0), title='Background Color', group='Appearance', tooltip='Used for all HUD cells')
color_success = input(color.green, title='Success Color (Pass)', group='Appearance')
color_warning = input(color.yellow, title='Warning Color (Caution)', group='Appearance')
color_failure = input(#ff5100, title='Failure Color (Fail)', group='Appearance')
color_default = input(color.new(#ffffff, 45), title='Default/Neutral Color', group='Appearance')
blank_bg_col = color.new(color.black, 100) // Transparent background for spacer/empty rows
tablePos = switch posTable
'Top Left' => position.top_left
'Top Right' => position.top_right
'Bottom Left' => position.bottom_left
'Bottom Right' => position.bottom_right
tablePos_SI = switch posTable_SI
'Top Left' => position.top_left
'Top Right' => position.top_right
'Bottom Left' => position.bottom_left
'Bottom Right' => position.bottom_right
size_tbl = switch tbl_size
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
// ==================== SECTOR/INDUSTRY CALCULATION ====================
get_sector_etf(sec) =>
switch sec
"Technology Services" => "XLK"
"Electronic Technology" => "XLK"
"Finance" => "XLF"
"Health Technology" => "XLV"
"Health Services" => "XLV"
"Retail Trade" => "XLP"
"Consumer Non-Durables" => "XLP"
"Energy Minerals" => "XLE"
"Producer Manufacturing" => "XLI"
"Consumer Services" => "XLY"
"Consumer Durables" => "XLY"
"Commercial Services" => "XLI"
"Industrial Services" => "XLI"
"Utilities" => "XLU"
"Transportation" => "XLI"
"Non-Energy Minerals" => "XLB"
"Process Industries" => "XLB"
"Communications" => "XLC"
"Distribution Services" => "XLI"
"Miscellaneous" => "SPY"
=> "SPY"
get_industry_etf(ind) =>
switch ind
"Pharmaceuticals: Major" => "IHE"
"Packaged Software" => "IGV"
"Biotechnology" => "XBI"
"Regional Banks" => "KRE"
"Medical Specialties" => "IHI"
"Financial Conglomerates" => "XLF"
"Real Estate Investment Trusts" => "VNQ"
"Miscellaneous Commercial Services" => "XLF"
"Investment Managers" => "KCE"
"Semiconductors" => "SOXX"
"Information Technology Services" => "VGT"
"Internet Software/Services" => "FDN"
"Major Banks" => "KBE"
"Finance/Rental/Leasing" => "XLF"
"Industrial Machinery" => "XLI"
"Specialty Stores" => "XRT"
"Aerospace & Defense" => "ITA"
"Precious Metals" => "GDX"
"Electrical Products" => "XLI"
"Electric Utilities" => "XLU"
"Chemicals: Specialty" => "XLB"
"Engineering & Construction" => "PKB"
"Medical/Nursing Services" => "XLV"
"Integrated Oil" => "XLE"
"Wholesale Distributors" => "XLY"
"Other Metals/Minerals" => "XME"
"Real Estate Development" => "VNQ"
"Restaurants" => "EATZ"
"Other Consumer Services" => "XLY"
"Marine Shipping" => "SEA"
"Savings Banks" => "KRE"
"Investment Banks/Brokers" => "IAI"
"Movies/Entertainment" => "PEJ"
"Food: Specialty/Candy" => "PBJ"
"Internet Retail" => "IBUY"
"Electronic Equipment/Instruments" => "BOTZ"
"Motor Vehicles" => "CARZ"
"Property/Casualty Insurance" => "KIE"
"Auto Parts: OEM" => "CARZ"
"Multi-Line Insurance" => "KIE"
"Advertising/Marketing Services" => "XLC"
"Telecommunications Equipment" => "IYZ"
"Oil & Gas Production" => "XOP"
"Apparel/Footwear" => "XRT"
"Trucks/Construction/Farm Machinery" => "XLI"
"Apparel/Footwear Retail" => "XRT"
"Agricultural Commodities/Milling" => "VEGI"
"Oilfield Services/Equipment" => "OIH"
"Pharmaceuticals: Other" => "IHE"
"Homebuilding" => "XHB"
"Electronic Production Equipment" => "SMH"
"Air Freight/Couriers" => "IYT"
"Recreational Products" => "PEJ"
"Steel" => "SLX"
"Building Products" => "XHB"
"Personnel Services" => "XLI"
"Airlines" => "JETS"
"Household/Personal Care" => "XLP"
"Electronics/Appliances" => "VGT"
"Wireless Telecommunications" => "IYZ"
"Computer Peripherals" => "VGT"
"Electronic Components" => "SOXX"
"Containers/Packaging" => "XLB"
"Oil & Gas Pipelines" => "AMLP"
"Insurance Brokers/Services" => "KIE"
"Gas Distributors" => "XOP"
"Trucking" => "XTN"
"Broadcasting" => "XLC"
"Metal Fabrication" => "XLI"
"Chemicals: Agricultural" => "PSCE"
"Home Furnishings" => "PLG"
"Other Transportation" => "XTN"
"Industrial Specialties" => "VAW"
"Environmental Services" => "PBD"
"Casinos/Gaming" => "BJK"
"Hospital/Nursing Management" => "XLV"
"Major Telecommunications" => "XLC"
"Beverages: Non-Alcoholic" => "PBJ"
"Miscellaneous Manufacturing" => "VAW"
"Beverages: Alcoholic" => "PBJ"
"Construction Materials" => "XLB"
"Water Utilities" => "PHO"
"Computer Communications" => "XSD"
"Contract Drilling" => "XLE"
"Specialty Telecommunications" => "XTL"
"Alternative Power Generation" => "ICLN"
"Computer Processing Hardware" => "XLK"
"Oil Refining/Marketing" => "XOP"
"Food Retail" => "XLP"
"Chemicals: Major Diversified" => "VAW"
"Specialty Insurance" => "KIE"
"Coal" => "XLE"
"Medical Distributors" => "IHI"
"Life/Health Insurance" => "KIE"
"Food: Major Diversified" => "XLP"
"Food Distributors" => "XLP"
"Managed Health Care" => "IXJ"
"Electronics Distributors" => "IXP"
"Commercial Printing/Forms" => "XLI"
"Food: Meat/Fish/Dairy" => "XLP"
"Miscellaneous" => "SPY"
"Department Stores" => "XRT"
"Publishing: Newspapers" => "XLC"
"Forest Products" => "WOOD"
"Railroads" => "IYT"
"Industrial Conglomerates" => "XLI"
"Publishing: Books/Magazines" => "XLC"
"Other Consumer Specialties" => "XLY"
"Home Improvement Chains" => "XLY"
"Tobacco" => "XLY"
"Cable/Satellite TV" => "XLC"
"Pulp & Paper" => "XLB"
"Automotive Aftermarket" => "XLY"
"Office Equipment/Supplies" => "IGV"
"Financial Publishing/Services" => "XLF"
"Drugstore Chains" => "XLP"
"Tools & Hardware" => "XLI"
"Services to the Health Industry" => "XLV"
"Aluminum" => "XME"
"Textiles" => "XLY"
"Discount Stores" => "XLP"
"Media Conglomerates" => "XLC"
"Consumer Sundries" => "XLP"
"Electronics/Appliance Stores" => "XRT"
"Pharmaceuticals: Generic" => "IHE"
"Catalog/Specialty Distribution" => "IBUY"
"Hotels/Resorts/Cruise lines" => "PEJ"
=> "SPY"
var string[] sector_etf_list = array.from("XLY", "XLP", "XLE", "XLF", "XLV", "XLI", "XLB", "XLRE", "XLK", "XLC", "XLU", "SPY")
// Calculate SPY reference at global scope for proper series context
indexClose = request.security("SPY", timeframe.period, close)
RS_function(symbolclose) =>
RSclose = symbolclose / indexClose
rank = 0.0
for i = 1 to 20
rank += (RSclose > RSclose[i] ? 1 : 0)
rank / 20.00 * 100
sector = na(syminfo.sector) ? "N/A" : syminfo.sector
industry = na(syminfo.industry) ? "N/A" : syminfo.industry
sector_etf = get_sector_etf(sector)
industry_etf = get_industry_etf(industry)
var float[] etf_returns = array.new_float()
var int rankrs = na
var int spy_rankrs = na
var int total_etfs = array.size(sector_etf_list)
getReturn() =>
[curClose, prevClose] = request.security(syminfo.tickerid, "D", [close, close[sector_rs_len]])
(curClose / prevClose - 1) * 100
if barstate.islast
array.clear(etf_returns)
for i = 0 to total_etfs - 1
etf = array.get(sector_etf_list, i)
etf_return = request.security(etf, "D", getReturn())
array.push(etf_returns, etf_return)
current_index = array.indexof(sector_etf_list, sector_etf)
spy_index = array.indexof(sector_etf_list, "SPY")
if not na(current_index) and not na(spy_index)
current_return = array.get(etf_returns, current_index)
spy_return = array.get(etf_returns, spy_index)
int better_count = 0
for j = 0 to total_etfs - 1
compare_return = array.get(etf_returns, j)
if not na(compare_return) and compare_return > current_return
better_count += 1
rankrs := better_count + 1
int spy_better_count = 0
for j = 0 to total_etfs - 1
compare_return = array.get(etf_returns, j)
if not na(compare_return) and compare_return > spy_return
spy_better_count += 1
spy_rankrs := spy_better_count + 1
industry_close = request.security(industry_etf, timeframe.period, close)
industry_rs = RS_function(industry_close)
sector_close = request.security(sector_etf, timeframe.period, close)
sector_rs = RS_function(sector_close)
// Industry & Sector: RS≥60=pass, RS 40-59=warn, RS<40=fail (rank x/12 stays text-only)
industry_color = (industry_rs == 0 or na(industry_rs)) ? color_default : (industry_rs >= 60 ? color_success : (industry_rs >= 40 ? color_warning : color_failure))
sector_color = (sector_rs == 0 or na(sector_rs)) ? color_default : (sector_rs >= 60 ? color_success : (sector_rs >= 40 ? color_warning : color_failure))
sector_rank_text = not na(rankrs) ? str.tostring(rankrs) + "/12" : "N/A"
sector_text = sector_etf + " RS: " + str.tostring(sector_rs, "#") + " (" + sector_rank_text + ")"
industry_text = industry + " RS: " + str.tostring(industry_rs, "#")
// ==================== MINERVINI CRITERIA ====================
sma_custom = ta.sma(close, ma_period)
sma50 = ta.sma(close, 50)
sma150 = ta.sma(close, 150)
sma200 = ta.sma(close, 200)
sma200_22 = sma200[22]
highest_price = ta.highest(high, 260)
lowest_price = ta.lowest(low, 260)
// Daily quarter lookbacks (yogy weekly 13/26/39/52 -> 63/126/189/252 on daily bars)
three_month_rs = 0.4*(close/close[63])
six_month_rs = 0.2*(close/(close[126]*2))
nine_month_rs = 0.2*(close/(close[189]*3))
twelve_month_rs = 0.2*(close/(close[252]*4))
rs_rating = (three_month_rs + six_month_rs + nine_month_rs + twelve_month_rs) * 100
c_1 = (close > sma150) and (close > sma200) ? 1 : 0
c_2 = sma150 > sma200 ? 1 : 0
c_3 = sma200 > sma200_22 ? 1 : 0
c_4 = (sma50 > sma150) and (sma50 > sma200) ? 1 : 0
c_5 = close > sma50 ? 1 : 0
c_6 = ((close/lowest_price)-1) * 100 >= 25 ? 1 : 0
c_7 = (1-(close/highest_price)) * 100 <= 25 ? 1 : 0
c_8 = rs_rating > 70 ? 1 : 0
count = c_1 + c_2 + c_3 + c_4 + c_5 + c_6 + c_7 + c_8
show_details = (count >= 6 and count < 8 and show_mm_warning_details) or (count <= 5 and show_mm_failure_details)
mm_failures = ""
if show_details
if c_1 == 0
mm_failures += "[Price] "
if c_2 == 0
mm_failures += "[MA150] "
if c_3 == 0
mm_failures += "[MA200] "
if c_4 == 0
mm_failures += "[MA50] "
if c_5 == 0
mm_failures += "[<MA50] "
if c_6 == 0
if not na(lowest_price) and lowest_price > 0
pct_above_low = ((close/lowest_price)-1) * 100
mm_failures += "[52low +" + str.tostring(pct_above_low, "#") + "%] "
else
mm_failures += "[52low N/A] "
if c_7 == 0
if not na(highest_price) and highest_price > 0
pct_below_high = (1-(close/highest_price)) * 100
mm_failures += "[52high -" + str.tostring(pct_below_high, "#") + "%] "
else
mm_failures += "[52high N/A] "
// Always show RS rating regardless of settings
mm_rs_text = "[RS " + str.tostring(rs_rating, "#") + "]"
mm_color = count == 8 ? color_success : (count >= 6 ? color_warning : color_failure)
mm_text = "MM: " + str.tostring(count) + "/8 " + mm_failures + mm_rs_text
// ==================== ATR & EXTENSION ====================
atr_value = ta.atr(14)
atr_percent = atr_value / close * 100
// ATR coloring thresholds (used for main 14dATR%)
atr_tolerance = 0.05 // Rounding tolerance to avoid false fails at band edges
// Calculate ATR dollar values first, then convert to percentages
atr_value_ma1 = ta.atr(ma1_period)
atr_value_ma2 = ta.atr(ma2_period)
atr_value_ma3 = ta.atr(ma3_period)
atr_percent_ma1 = atr_value_ma1 / close * 100
atr_percent_ma2 = atr_value_ma2 / close * 100
atr_percent_ma3 = atr_value_ma3 / close * 100
// Color per-MA ATR% by comparing to 14ATR%: shorter periods should be lower, longer periods should be higher
// 1% tolerance zone is on the "wrong" side only (asymmetric)
atr_trend_tolerance = 1.0 // 1% yellow buffer on wrong side
// MA1: If period < 14, should be LOWER; if period > 14, should be HIGHER
atr_trend_ma1_diff = atr_percent_ma1 - atr_percent
atr_trend_ma1_color = ma1_period < 14 ? (atr_trend_ma1_diff <= 0 ? color_success : (atr_trend_ma1_diff <= atr_trend_tolerance ? color_warning : color_default)) : (atr_trend_ma1_diff >= 0 ? color_success : (atr_trend_ma1_diff >= -atr_trend_tolerance ? color_warning : color_default))
// MA2: Same logic
atr_trend_ma2_diff = atr_percent_ma2 - atr_percent
atr_trend_ma2_color = ma2_period < 14 ? (atr_trend_ma2_diff <= 0 ? color_success : (atr_trend_ma2_diff <= atr_trend_tolerance ? color_warning : color_default)) : (atr_trend_ma2_diff >= 0 ? color_success : (atr_trend_ma2_diff >= -atr_trend_tolerance ? color_warning : color_default))
// MA3: Same logic
atr_trend_ma3_diff = atr_percent_ma3 - atr_percent
atr_trend_ma3_color = ma3_period < 14 ? (atr_trend_ma3_diff <= 0 ? color_success : (atr_trend_ma3_diff <= atr_trend_tolerance ? color_warning : color_default)) : (atr_trend_ma3_diff >= 0 ? color_success : (atr_trend_ma3_diff >= -atr_trend_tolerance ? color_warning : color_default))
format_atr_dollars(float val) =>
show_atr_dollars ? " (" + str.tostring(val, "#.##") + ")" : ""
atr_trend_ma1_text = str.tostring(ma1_period) + "dATR " + str.tostring(atr_percent_ma1, "#.#") + "%" + format_atr_dollars(atr_value_ma1)
atr_trend_ma2_text = str.tostring(ma2_period) + "dATR " + str.tostring(atr_percent_ma2, "#.#") + "%" + format_atr_dollars(atr_value_ma2)
atr_trend_ma3_text = str.tostring(ma3_period) + "dATR " + str.tostring(atr_percent_ma3, "#.#") + "%" + format_atr_dollars(atr_value_ma3)
// Extension: Jeff Sun method (ma gain % / ATR %)
ma_gain_pct = ((close - sma_custom) / sma_custom) * 100
extension_value_percent = ma_gain_pct / atr_percent
extension_value = extension_value_percent
// Main 14ATR% coloring using settings-based thresholds
atr_pass_green = atr_percent >= (atr_min - atr_tolerance) and atr_percent <= (atr_max + atr_tolerance)
atr_pass_yellow = atr_percent >= (atr_min - atr_warn_buffer) and atr_percent <= (atr_max + atr_warn_buffer)
atr_detail = ""
if show_atr_details and not atr_pass_green
if atr_percent < atr_min
atr_detail := " [<" + str.tostring(atr_min, "#.#") + "]"
else if atr_percent > atr_max
atr_detail := " [>" + str.tostring(atr_max, "#.#") + "]"
atr_color = atr_pass_green ? color_success : (atr_pass_yellow ? color_warning : color_failure)
atr_text = "14dATR " + str.tostring(atr_percent, "#.#") + "%" + format_atr_dollars(atr_value) + atr_detail
// Use 0.05 tolerance for extension to match display rounding
ext_tolerance = 0.05
ext_pass_green = extension_value >= (ext_min - ext_tolerance) and extension_value <= (ext_max + ext_tolerance)
ext_pass_yellow = extension_value > (ext_max + ext_tolerance) and extension_value <= (ext_yellow_max + ext_tolerance)
ext_detail = ""
if show_atr_details and not (ext_pass_green or ext_pass_yellow)
if extension_value < (ext_min - ext_tolerance)
ext_detail := " [<" + str.tostring(ext_min, "#.#") + "]"
else
ext_detail := " [>" + str.tostring(ext_yellow_max, "#.#") + "]"
ext_color = ext_pass_green ? color_success : (ext_pass_yellow ? color_warning : color_failure)
ext_text = "xFrom" + str.tostring(ma_period) + ": " + str.tostring(extension_value_percent, "#.#") + ext_detail
// %MaxATRx — same as screener: current xFrom / highest(xFrom, lookback) × 100 (own cell; pairs under xFrom)
max_extension = ta.highest(extension_value, xfrom_max_lookback)
pct_max_atrx = max_extension > 0 ? extension_value / max_extension * 100 : na
pct_max_atrx_text = not na(pct_max_atrx) ? "%MaxATRx: " + str.tostring(pct_max_atrx, "#") + "%" : "%MaxATRx: N/A"
pct_max_atrx_color = na(pct_max_atrx) ? color_default : (pct_max_atrx <= 40 ? color_success : (pct_max_atrx <= 65 ? color_warning : color_failure))
// xFromLoD: distance from session low in ATR multiples
newDay = ta.change(time("D")) != 0
var float lowToday = na
if newDay
lowToday := low
else
lowToday := math.min(lowToday, low)
lod_atr_mult = atr_value > 0 ? (close - lowToday) / atr_value : na
lod_pass_green = lod_atr_mult < lod_green_max
lod_pass_yellow = lod_atr_mult < lod_yellow_max
lod_color = lod_pass_green ? color_success : (lod_pass_yellow ? color_warning : color_failure)
lod_text = "xFromLoD: " + str.tostring(lod_atr_mult, "#.#") + "x"
// ==================== STOP LOSS MAs ====================
ma1_value = ma1_type == 'SMA' ? ta.sma(close, ma1_period) : ta.ema(close, ma1_period)
ma2_value = ma2_type == 'SMA' ? ta.sma(close, ma2_period) : ta.ema(close, ma2_period)
ma3_value = ma3_type == 'SMA' ? ta.sma(close, ma3_period) : ta.ema(close, ma3_period)
// Negative values show MA is below current price
ma1_dist_pct = ((ma1_value - close) / close) * 100
ma2_dist_pct = ((ma2_value - close) / close) * 100
ma3_dist_pct = ((ma3_value - close) / close) * 100
// Gain percentages (how much price has risen from MA)
ma1_gain_pct = ((close - ma1_value) / ma1_value) * 100
ma2_gain_pct = ((close - ma2_value) / ma2_value) * 100
ma3_gain_pct = ((close - ma3_value) / ma3_value) * 100
// ATR multiples: Negative values show MA is below current price
ma1_atr_mult = (ma1_value - close) / atr_value
ma2_atr_mult = (ma2_value - close) / atr_value
ma3_atr_mult = (ma3_value - close) / atr_value
// Percentage distance color logic (Row 3)
// Negative values = MA below price (normal), check absolute value against thresholds
// Green: 0-3% below price, Yellow: 3-5% below price, Red: price below MA, Gray: >5% away
ma1_color = ma1_dist_pct > 0 ? color_failure : ((math.abs(ma1_dist_pct) >= stop_pct_min and math.abs(ma1_dist_pct) <= stop_pct_max) ? color_success : (math.abs(ma1_dist_pct) <= stop_pct_warn_max ? color_warning : color_default))
ma2_color = ma2_dist_pct > 0 ? color_failure : ((math.abs(ma2_dist_pct) >= stop_pct_min and math.abs(ma2_dist_pct) <= stop_pct_max) ? color_success : (math.abs(ma2_dist_pct) <= stop_pct_warn_max ? color_warning : color_default))
ma3_color = ma3_dist_pct > 0 ? color_failure : ((math.abs(ma3_dist_pct) >= stop_pct_min and math.abs(ma3_dist_pct) <= stop_pct_max) ? color_success : (math.abs(ma3_dist_pct) <= stop_pct_warn_max ? color_warning : color_default))
ma1_label = str.tostring(ma1_period) + ma1_type
ma2_label = str.tostring(ma2_period) + ma2_type
ma3_label = str.tostring(ma3_period) + ma3_type
ma1_text = ma1_label + ": " + (ma1_dist_pct >= 0 ? "+" : "") + str.tostring(ma1_dist_pct, "#.#") + "% / " + (ma1_gain_pct >= 0 ? "+" : "") + str.tostring(ma1_gain_pct, "#.#") + "%"
ma2_text = ma2_label + ": " + (ma2_dist_pct >= 0 ? "+" : "") + str.tostring(ma2_dist_pct, "#.#") + "% / " + (ma2_gain_pct >= 0 ? "+" : "") + str.tostring(ma2_gain_pct, "#.#") + "%"
ma3_text = ma3_label + ": " + (ma3_dist_pct >= 0 ? "+" : "") + str.tostring(ma3_dist_pct, "#.#") + "% / " + (ma3_gain_pct >= 0 ? "+" : "") + str.tostring(ma3_gain_pct, "#.#") + "%"
// ATR multiple text and coloring (pass/warn/default logic)
ma1_atr_text = "ATRx: " + str.tostring(ma1_atr_mult, "#.#")
ma2_atr_text = "ATRx: " + str.tostring(ma2_atr_mult, "#.#")
ma3_atr_text = "ATRx: " + str.tostring(ma3_atr_mult, "#.#")
// ATR multiple distance color logic (Row 4)
// Negative values = MA below price (normal), check absolute value against thresholds
// Green: 0-1.5x, Yellow: to warn max, Default: warn-fail gap, Red: price below MA or > fail max
ma1_atr_color = ma1_atr_mult > 0 ? color_failure : math.abs(ma1_atr_mult) > atr_dist_fail_max ? color_failure : (math.abs(ma1_atr_mult) >= atr_dist_min and math.abs(ma1_atr_mult) <= atr_dist_max ? color_success : (math.abs(ma1_atr_mult) <= atr_dist_warn_max ? color_warning : color_default))
ma2_atr_color = ma2_atr_mult > 0 ? color_failure : math.abs(ma2_atr_mult) > atr_dist_fail_max ? color_failure : (math.abs(ma2_atr_mult) >= atr_dist_min and math.abs(ma2_atr_mult) <= atr_dist_max ? color_success : (math.abs(ma2_atr_mult) <= atr_dist_warn_max ? color_warning : color_default))
ma3_atr_color = ma3_atr_mult > 0 ? color_failure : math.abs(ma3_atr_mult) > atr_dist_fail_max ? color_failure : (math.abs(ma3_atr_mult) >= atr_dist_min and math.abs(ma3_atr_mult) <= atr_dist_max ? color_success : (math.abs(ma3_atr_mult) <= atr_dist_warn_max ? color_warning : color_default))
// ==================== BOLLINGER BANDS ====================
bb_ma_func(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)
=> ta.sma(source, length)
// BB for MA 1
bb1_basis = bb_ma_func(bb_source, ma1_period, ma1_type)
bb1_dev = bb_stddev * ta.stdev(bb_source, ma1_period)
bb1_upper = bb1_basis + bb1_dev
bb1_lower = bb1_basis - bb1_dev
// BB for MA 2
bb2_basis = bb_ma_func(bb_source, ma2_period, ma2_type)
bb2_dev = bb_stddev * ta.stdev(bb_source, ma2_period)
bb2_upper = bb2_basis + bb2_dev
bb2_lower = bb2_basis - bb2_dev
// BB for MA 3
bb3_basis = bb_ma_func(bb_source, ma3_period, ma3_type)
bb3_dev = bb_stddev * ta.stdev(bb_source, ma3_period)
bb3_upper = bb3_basis + bb3_dev
bb3_lower = bb3_basis - bb3_dev
// Plot MA lines on chart (optional)
// Note: Titles must be constant strings in Pine Script v6, so we use generic labels
plot(show_ma_lines ? ma1_value : na, title="MA 1", color=ma1_line_color, linewidth=ma_line_width, offset=0)
plot(show_ma_lines ? ma2_value : na, title="MA 2", color=ma2_line_color, linewidth=ma_line_width, offset=0)
plot(show_ma_lines ? ma3_value : na, title="MA 3", color=ma3_line_color, linewidth=ma_line_width, offset=0)
// Plot Bollinger Bands — Style labels BB1/BB2/BB3 Upper|Lower
bb1_upper_plot = plot(show_bb1 ? bb1_upper : na, title="BB1 Upper", color=bb_upper_color, linewidth=bb_line_width, offset=bb_offset)
bb1_lower_plot = plot(show_bb1 ? bb1_lower : na, title="BB1 Lower", color=bb_lower_color, linewidth=bb_line_width, offset=bb_offset)
fill(bb1_upper_plot, bb1_lower_plot, color=show_bb1 ? bb_fill_color : na, title="BB1 Fill")
// Plot Bollinger Bands for MA 2 (default ON — 21 EMA)
bb2_upper_plot = plot(show_bb2 ? bb2_upper : na, title="BB2 Upper", color=bb_upper_color, linewidth=bb_line_width, offset=bb_offset)
bb2_lower_plot = plot(show_bb2 ? bb2_lower : na, title="BB2 Lower", color=bb_lower_color, linewidth=bb_line_width, offset=bb_offset)
fill(bb2_upper_plot, bb2_lower_plot, color=show_bb2 ? bb_fill_color : na, title="BB2 Fill")
// Plot Bollinger Bands for MA 3
bb3_upper_plot = plot(show_bb3 ? bb3_upper : na, title="BB3 Upper", color=bb_upper_color, linewidth=bb_line_width, offset=bb_offset)
bb3_lower_plot = plot(show_bb3 ? bb3_lower : na, title="BB3 Lower", color=bb_lower_color, linewidth=bb_line_width, offset=bb_offset)
fill(bb3_upper_plot, bb3_lower_plot, color=show_bb3 ? bb_fill_color : na, title="BB3 Fill")
// ==================== VOLUME / OBV ====================
format_volume(vol) =>
if vol >= 1000000
str.tostring(vol / 1000000, "#.#") + "m"
else if vol >= 1000
str.tostring(vol / 1000, "#") + "k"
else
str.tostring(vol, "#")
// Jeff Sun: avg vol + proj vol (Avg/Proj row)
tfJeff = timeframe.period
sJeff = syminfo.tickerid
volJeff = request.security(sJeff, tfJeff, volume, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
volMaJeff = ta.sma(volJeff, vol_ma_len)
avgVolJeff = request.security(sJeff, tfJeff, volMaJeff, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
// Avg/Proj = Jeff Avg Vol + Bob-Lablaw projected bar volume
time_passed = (timenow - time) / 1000
time_left = (time_close - timenow) / 1000
projectedVolJeff = float(volume)
if time_left > 0
volume_per_second = volume / time_passed
projectedVolJeff := volume + volume_per_second * time_left
proj_vs_avg_pct = avgVolJeff > 0 ? 100 * projectedVolJeff / avgVolJeff : na
vol_avg_proj_color = proj_vs_avg_pct >= 100 ? color_success : (proj_vs_avg_pct >= 75 ? color_warning : color_failure)
vol_avg_proj_text = "Proj/Avg: " + format_volume(projectedVolJeff) + "/" + format_volume(avgVolJeff)
// RelVol Proj — projected bar vol ÷ 50-day avg (matches Proj/Avg cell beside it)
rvol_intra_pct = proj_vs_avg_pct
rvol_intra_color = rvol_intra_pct >= 100 ? color_success : (rvol_intra_pct >= 75 ? color_warning : color_failure)
rvol_intra_text = "RelVol Proj: " + str.tostring(rvol_intra_pct, "#") + "%"
// RelVol Day — TV rel vol at time: cumulative vol now ÷ avg at same clock time (ta.relativeVolume)
[relvol_time_cur, relvol_time_avg, _] = ta.relativeVolume(relvol_time_len, "1D", true, true)
rel_vol_pct = relvol_time_avg > 0 ? 100 * relvol_time_cur / relvol_time_avg : na
rel_vol_color = rel_vol_pct >= 100 ? color_success : (rel_vol_pct >= 75 ? color_warning : color_failure)
rel_vol_text = "RelVol Day: " + str.tostring(rel_vol_pct, "#") + "%"
// Vol Buzz (Jeff Sun): current bar vs volume MA
vol_buzz = 100 * (volume / ta.sma(volume, vol_ma_len) - 1)
vol_buzz_color = vol_buzz >= vol_buzz_green_min ? color_success : (vol_buzz >= vol_buzz_red_below ? color_warning : color_failure)
vol_buzz_text = "Vol Buzz: " + str.tostring(vol_buzz, "#") + "%"
// OBV calculation and direction
obv_value = ta.cum(math.sign(ta.change(close)) * volume)
obv_lookback_long = 20 // Compare to ~4 weeks ago to avoid false declining signals
obv_prev = obv_value[obv_lookback_long]
obv_change = obv_value - obv_prev
obv_change_pct = (obv_change / math.abs(obv_prev)) * 100
// OBV direction: Green ↑ rising >2%, Yellow → flat ±2%, Red ↓ falling <-2%
obv_flat_threshold = 2.0 // Percentage threshold for flat zone
obv_direction = obv_change_pct > obv_flat_threshold ? "↑" : (obv_change_pct < -obv_flat_threshold ? "↓" : "→")
obv_dir_color = obv_change_pct > obv_flat_threshold ? color_success : (obv_change_pct < -obv_flat_threshold ? color_failure : color_warning)
obv_text = "OBV: " + obv_direction
// ==================== STS (Short Term Strength vs SPY) ====================
// Jeff Sun methodology: Stock/SPY ratio percentile rank over lookback period
spy_close = request.security("SPY", timeframe.period, close)
rs_ratio = spy_close > 0 ? close / spy_close : na
// Calculate percentile rank of current RS ratio vs last N bars
rs_percentile_count = 0.0
if not na(rs_ratio)
for i = 1 to sts_lookback
if not na(rs_ratio[i]) and rs_ratio > rs_ratio[i]
rs_percentile_count += 1
sts_score = (rs_percentile_count / sts_lookback) * 100
// Direction indicator: compare to previous bar
sts_prev = sts_score[1]
sts_direction = na(sts_prev) ? "" : (sts_score > sts_prev ? " ↑" : (sts_score < sts_prev ? " ↓" : " →"))
// Color logic: Green ≥90%, Yellow 65-89%, Red <65% (defaults)
sts_color = sts_score >= sts_green_min ? color_success : (sts_score >= sts_yellow_min ? color_warning : color_failure)
sts_text = "STS: " + str.tostring(sts_score, "#") + "%" + sts_direction
// ==================== VCP TIGHTNESS ====================
// VCP (Volatility Contraction Pattern) Tightness Score: 0-100 scale
// Lower score = tighter consolidation (ideal for breakout entries)
// Based on closing spread and price swing relative to ADR%
// 1. Calculate Average Daily Range % (ADR%)
bar_range_pct = ((high - low) / low) * 100
adr_pct = ta.sma(bar_range_pct, vcp_adr_len)
safe_adr = adr_pct == 0 ? 0.0001 : adr_pct
// 2. Closing spread % over lookback period
hi_c = ta.highest(close, vcp_tightness_len)
lo_c = ta.lowest(close, vcp_tightness_len)
close_spread_pct = ((hi_c - lo_c) / lo_c) * 100
// 3. Total price swing (High-Low) % over lookback period
hi_p = ta.highest(high, vcp_tightness_len)
lo_p = ta.lowest(low, vcp_tightness_len)
price_spread_pct = ((hi_p - lo_p) / lo_p) * 100
// 4. Ratios relative to ADR%
close_ratio = close_spread_pct / safe_adr
price_ratio = price_spread_pct / safe_adr
// 5. Combined ratio (average of both)
combined_ratio = (close_ratio + price_ratio) / 2
// 6. Normalize to 0-100 based on historical extremes
highest_ratio = ta.highest(combined_ratio, vcp_baseline)
lowest_ratio = ta.lowest(combined_ratio, vcp_baseline)
range_ratio = highest_ratio - lowest_ratio
vcp_score = range_ratio == 0 ? 0 : ((combined_ratio - lowest_ratio) / range_ratio) * 100
// Direction indicator: compare to previous bar
vcp_prev = vcp_score[1]
vcp_direction = na(vcp_prev) ? "" : (vcp_score > vcp_prev ? " ↑" : (vcp_score < vcp_prev ? " ↓" : " →"))
// Thresholds: ≤10 success, ≤25 warning, >25 failure — same Appearance text colors as Vol Buzz
vcp_color = vcp_score <= vcp_tight_max ? color_success : (vcp_score <= vcp_yellow_max ? color_warning : color_failure)
vcp_text = "VCPT: " + str.tostring(vcp_score, "#") + vcp_direction
// ==================== DISPLAY ====================
// RS block = Sector + Industry + STS + VCP (join/separate via Main vs RS Block positions)
same_position = posTable == posTable_SI
if layout_mode == 'Wide' and same_position
total_rows = 2 + add_empty_row_above + add_empty_row_below
var table gs2_table_combined = table.new(tablePos, 14, total_rows, bgcolor=blank_bg_col, frame_width=0, border_width=0)
content_row0 = add_empty_row_above
content_row1 = add_empty_row_above + 1
if barstate.islast
if add_empty_row_above > 0
for i = 0 to add_empty_row_above - 1
for col = 0 to 13
table.cell(gs2_table_combined, col, i, "", bgcolor=blank_bg_col, text_size=size_tbl, width=(col == 7 or col == 9 or col == 11) ? ma_swatch_cell_width : 0)
// Wide joined: Sector|Industry | core. MM always paired with STS.
// Volume ON: ATR|xFrom|VCPT|RelVolDay|RelVolProj|MM
// %Max|LoD|OBV|VolBuzz|Proj/Avg|STS
// Volume OFF: ATR|xFrom|VCPT|MM (OBV stays under VCPT — no gap)
// %Max|LoD|OBV|STS
table.cell(gs2_table_combined, 0, content_row0, sector_text, text_color=sector_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 1, content_row0, atr_text, text_color=atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 2, content_row0, ext_text, text_color=ext_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 3, content_row0, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if show_volume_section
table.cell(gs2_table_combined, 4, content_row0, rel_vol_text, text_color=rel_vol_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 5, content_row0, rvol_intra_text, text_color=rvol_intra_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 6, content_row0, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
else
table.cell(gs2_table_combined, 4, content_row0, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 5, content_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 6, content_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
// MA: ▌ = MA line color in narrow col; label uses ATRx color
table.cell(gs2_table_combined, 7, content_row0, show_ma_section ? ma_swatch_glyph : "", text_color=ma1_line_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 8, content_row0, show_ma_section ? ma1_text : "", text_color=ma1_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 9, content_row0, show_ma_section ? ma_swatch_glyph : "", text_color=ma2_line_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 10, content_row0, show_ma_section ? ma2_text : "", text_color=ma2_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 11, content_row0, show_ma_section ? ma_swatch_glyph : "", text_color=ma3_line_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 12, content_row0, show_ma_section ? ma3_text : "", text_color=ma3_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 13, content_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 0, content_row1, industry_text, text_color=industry_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 1, content_row1, pct_max_atrx_text, text_color=pct_max_atrx_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 2, content_row1, lod_text, text_color=lod_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 3, content_row1, obv_text, text_color=obv_dir_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if show_volume_section
table.cell(gs2_table_combined, 4, content_row1, vol_buzz_text, text_color=vol_buzz_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 5, content_row1, vol_avg_proj_text, text_color=vol_avg_proj_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 6, content_row1, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
else
table.cell(gs2_table_combined, 4, content_row1, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 5, content_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 6, content_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 7, content_row1, "", text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 8, content_row1, show_ma_section ? ma1_atr_text : "", text_color=ma1_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 9, content_row1, "", text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 10, content_row1, show_ma_section ? ma2_atr_text : "", text_color=ma2_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 11, content_row1, "", text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_combined, 12, content_row1, show_ma_section ? ma3_atr_text : "", text_color=ma3_atr_color, text_size=size_tbl, bgcolor=show_ma_section ? bg_col : blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined, 13, content_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if add_empty_row_below > 0
for i = 1 to add_empty_row_below
for col = 0 to 13
table.cell(gs2_table_combined, col, content_row1 + i, "", bgcolor=blank_bg_col, text_size=size_tbl, width=(col == 7 or col == 9 or col == 11) ? ma_swatch_cell_width : 0)
else if layout_mode == 'Wide'
// Same 6×2 core order as joined (Sector/Industry on separate SI table)
total_rows_main = 5 + add_empty_row_above + add_empty_row_below
total_rows_si = 2 + add_empty_row_above_si + add_empty_row_below_si
var table gs2_table_main = table.new(tablePos, 6, total_rows_main, bgcolor=blank_bg_col, frame_width=0, border_width=0)
var table gs2_table_si = table.new(tablePos_SI, 2, total_rows_si, bgcolor=blank_bg_col, frame_width=0, border_width=0)
content_row0 = add_empty_row_above
content_row1 = add_empty_row_above + 1
content_row4 = add_empty_row_above + 2 // MA texts
content_row5 = add_empty_row_above + 3 // MA ATR texts
swatch_row1 = add_empty_row_above + 4 // MA swatches
si_row0 = add_empty_row_above_si
si_row1 = add_empty_row_above_si + 1
if barstate.islast
if add_empty_row_above > 0
for i = 0 to add_empty_row_above - 1
for col = 0 to 5
table.cell(gs2_table_main, col, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
// MM paired with STS. OBV under VCPT always (fills gap when volume off). VolBuzz swapped with former OBV slot.
table.cell(gs2_table_main, 0, content_row0, atr_text, text_color=atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 1, content_row0, ext_text, text_color=ext_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 2, content_row0, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 0, content_row1, pct_max_atrx_text, text_color=pct_max_atrx_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 1, content_row1, lod_text, text_color=lod_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 2, content_row1, obv_text, text_color=obv_dir_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if show_volume_section
table.cell(gs2_table_main, 3, content_row0, rel_vol_text, text_color=rel_vol_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row0, rvol_intra_text, text_color=rvol_intra_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 5, content_row0, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 3, content_row1, vol_buzz_text, text_color=vol_buzz_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row1, vol_avg_proj_text, text_color=vol_avg_proj_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 5, content_row1, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
else
table.cell(gs2_table_main, 3, content_row0, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 5, content_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 3, content_row1, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 5, content_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if show_ma_section
// Wide-separate: ▌ = MA line color in narrow col; label matches ATRx
table.cell(gs2_table_main, 0, content_row4, ma_swatch_glyph, text_color=ma1_line_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 1, content_row4, ma1_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 2, content_row4, ma_swatch_glyph, text_color=ma2_line_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 3, content_row4, ma2_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row4, ma_swatch_glyph, text_color=ma3_line_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 5, content_row4, ma3_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 0, content_row5, "", text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 1, content_row5, ma1_atr_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 2, content_row5, "", text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 3, content_row5, ma2_atr_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, content_row5, "", text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left, width=ma_swatch_cell_width)
table.cell(gs2_table_main, 5, content_row5, ma3_atr_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 0, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 1, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 2, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 3, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 4, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_main, 5, swatch_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if add_empty_row_below > 0
for i = 1 to add_empty_row_below
for col = 0 to 5
table.cell(gs2_table_main, col, swatch_row1 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
if add_empty_row_above_si > 0
for i = 0 to add_empty_row_above_si - 1
table.cell(gs2_table_si, 0, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
table.cell(gs2_table_si, 1, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
// Sector / Industry alone (STS/VCPT live on main)
table.cell(gs2_table_si, 0, si_row0, sector_text, text_color=sector_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_si, 1, si_row0, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_si, 0, si_row1, industry_text, text_color=industry_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_si, 1, si_row1, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if add_empty_row_below_si > 0
for i = 1 to add_empty_row_below_si
table.cell(gs2_table_si, 0, si_row1 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
table.cell(gs2_table_si, 1, si_row1 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
else if layout_mode == 'Stacked' and same_position
total_rows = 25 + add_empty_row_above + add_empty_row_below
var table gs2_table_combined_stacked = table.new(tablePos, 1, total_rows, bgcolor=blank_bg_col, frame_width=0, border_width=0)
// RS block at top (Sector, Industry, STS, VCP)
row0 = add_empty_row_above
row1 = add_empty_row_above + 1
row_sts = add_empty_row_above + 2
row_vcp = add_empty_row_above + 3
// Main metrics
row2 = add_empty_row_above + 4
row3 = add_empty_row_above + 5
row4 = add_empty_row_above + 6
row_lod = add_empty_row_above + 7
row5 = add_empty_row_above + 8
row6 = add_empty_row_above + 9
row7 = add_empty_row_above + 10
// Volume section
row8 = add_empty_row_above + 11
row9 = add_empty_row_above + 12
row10 = add_empty_row_above + 13
row11 = add_empty_row_above + 14
row12 = add_empty_row_above + 15
// MA section
row13 = add_empty_row_above + 16 // MA1 text
row14 = add_empty_row_above + 17 // MA1 ATR text
row15 = add_empty_row_above + 18 // MA1 swatch
row16 = add_empty_row_above + 19 // MA2 text
row17 = add_empty_row_above + 20 // MA2 ATR text
row18 = add_empty_row_above + 21 // MA2 swatch
row19 = add_empty_row_above + 22 // MA3 text
row20 = add_empty_row_above + 23 // MA3 ATR text
row21 = add_empty_row_above + 24 // MA3 swatch
if barstate.islast
if add_empty_row_above > 0
for i = 0 to add_empty_row_above - 1
table.cell(gs2_table_combined_stacked, 0, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
table.cell(gs2_table_combined_stacked, 0, row0, sector_text, text_color=sector_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row1, industry_text, text_color=industry_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row_sts, ext_text, text_color=ext_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row_vcp, pct_max_atrx_text, text_color=pct_max_atrx_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row2, atr_text, text_color=atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row3, lod_text, text_color=lod_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row4, show_volume_section ? vol_buzz_text : "", text_color=vol_buzz_color, text_size=size_tbl, bgcolor=show_volume_section ? bg_col : blank_bg_col, text_halign=text.align_left)
// Per-MA ATR% — commented out
// table.cell(... atr_trend_ma1/2/3 ...)
if show_volume_section
table.cell(gs2_table_combined_stacked, 0, row_lod, vol_avg_proj_text, text_color=vol_avg_proj_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row5, rel_vol_text, text_color=rel_vol_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row6, rvol_intra_text, text_color=rvol_intra_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row7, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row8, obv_text, text_color=obv_dir_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row9, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row10, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
else
table.cell(gs2_table_combined_stacked, 0, row_lod, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row5, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row6, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if show_ma_section
// Stacked: label matches ATRx color (no side swatch col for MA line color)
table.cell(gs2_table_combined_stacked, 0, row13, ma1_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row14, ma1_atr_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row15, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row16, ma2_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row17, ma2_atr_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row18, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row19, ma3_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row20, ma3_atr_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_combined_stacked, 0, row21, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if add_empty_row_below > 0
for i = 1 to add_empty_row_below
table.cell(gs2_table_combined_stacked, 0, row21 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
else
total_rows_main = 21 + add_empty_row_above + add_empty_row_below
total_rows_si = 2 + add_empty_row_above_si + add_empty_row_below_si
var table gs2_table_stacked = table.new(tablePos, 1, total_rows_main, bgcolor=blank_bg_col, frame_width=0, border_width=0)
var table gs2_table_si_stacked = table.new(tablePos_SI, 1, total_rows_si, bgcolor=blank_bg_col, frame_width=0, border_width=0)
row0 = add_empty_row_above
row1 = add_empty_row_above + 1
row2 = add_empty_row_above + 2
row3 = add_empty_row_above + 3
row4 = add_empty_row_above + 4
row5 = add_empty_row_above + 5
row6 = add_empty_row_above + 6
row7 = add_empty_row_above + 7
row8 = add_empty_row_above + 8
row9 = add_empty_row_above + 9
row10 = add_empty_row_above + 10
row11 = add_empty_row_above + 11
row12 = add_empty_row_above + 12 // MA1 text
row13 = add_empty_row_above + 13 // MA1 ATR text
row14 = add_empty_row_above + 14 // MA1 swatch
row15 = add_empty_row_above + 15 // MA2 text
row16 = add_empty_row_above + 16 // MA2 ATR text
row17 = add_empty_row_above + 17 // MA2 swatch
row18 = add_empty_row_above + 18 // MA3 text
row19 = add_empty_row_above + 19 // MA3 ATR text
row20 = add_empty_row_above + 20 // MA3 swatch
si_row0 = add_empty_row_above_si
si_row1 = add_empty_row_above_si + 1
si_row_sts = add_empty_row_above_si + 2
si_row_vcp = add_empty_row_above_si + 3
if barstate.islast
if add_empty_row_above > 0
for i = 0 to add_empty_row_above - 1
table.cell(gs2_table_stacked, 0, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
table.cell(gs2_table_stacked, 0, row0, ext_text, text_color=ext_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row1, pct_max_atrx_text, text_color=pct_max_atrx_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row2, atr_text, text_color=atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row3, lod_text, text_color=lod_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row4, show_volume_section ? vol_buzz_text : "", text_color=vol_buzz_color, text_size=size_tbl, bgcolor=show_volume_section ? bg_col : blank_bg_col, text_halign=text.align_left)
// Per-MA ATR% — commented out
// table.cell(... atr_trend_ma1/2/3 ...)
if show_volume_section
table.cell(gs2_table_stacked, 0, row5, vol_avg_proj_text, text_color=vol_avg_proj_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row6, rel_vol_text, text_color=rel_vol_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row7, rvol_intra_text, text_color=rvol_intra_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row8, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row9, obv_text, text_color=obv_dir_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row10, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row11, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
else
table.cell(gs2_table_stacked, 0, row5, mm_text, text_color=mm_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row6, sts_text, text_color=sts_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row7, vcp_text, text_color=vcp_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if show_ma_section
table.cell(gs2_table_stacked, 0, row12, ma1_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row13, ma1_atr_text, text_color=ma1_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row14, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row15, ma2_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row16, ma2_atr_text, text_color=ma2_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row17, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row18, ma3_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row19, ma3_atr_text, text_color=ma3_atr_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_stacked, 0, row20, "", text_size=size_tbl, bgcolor=blank_bg_col, text_halign=text.align_left)
if add_empty_row_below > 0
for i = 1 to add_empty_row_below
table.cell(gs2_table_stacked, 0, row20 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
if add_empty_row_above_si > 0
for i = 0 to add_empty_row_above_si - 1
table.cell(gs2_table_si_stacked, 0, i, "", bgcolor=blank_bg_col, text_size=size_tbl)
// Sector / Industry alone (STS/VCPT on main)
table.cell(gs2_table_si_stacked, 0, si_row0, sector_text, text_color=sector_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
table.cell(gs2_table_si_stacked, 0, si_row1, industry_text, text_color=industry_color, text_size=size_tbl, bgcolor=bg_col, text_halign=text.align_left)
if add_empty_row_below_si > 0
for i = 1 to add_empty_row_below_si
table.cell(gs2_table_si_stacked, 0, si_row1 + i, "", bgcolor=blank_bg_col, text_size=size_tbl)
// ==================== HIDDEN PLOTS FOR ALERTS ====================
// display.none = off chart; editable=false = hidden from Style tab (still alertable)
// Removed GS2 MA1/2/3 — duplicate of Style "MA 1/2/3" (use those for MA alerts)
// Reference MA used for xFrom (not the stop MAs)
plot(sma_custom, title="Reference MA", display=display.none, editable=false)
// ATR & Extension
plot(atr_value, title="ATR $", display=display.none, editable=false)
plot(atr_percent, title="ATR %", display=display.none, editable=false)
plot(extension_value, title="xFromMA", display=display.none, editable=false)
plot(pct_max_atrx, title="%MaxATRx", display=display.none, editable=false)
plot(lod_atr_mult, title="xFromLoD", display=display.none, editable=false)
plot(atr_percent_ma1, title="MA1 ATR %", display=display.none, editable=false)
plot(atr_percent_ma2, title="MA2 ATR %", display=display.none, editable=false)
plot(atr_percent_ma3, title="MA3 ATR %", display=display.none, editable=false)
// MA Distances
plot(ma1_dist_pct, title="MA1 Distance %", display=display.none, editable=false)
plot(ma2_dist_pct, title="MA2 Distance %", display=display.none, editable=false)
plot(ma3_dist_pct, title="MA3 Distance %", display=display.none, editable=false)
plot(ma1_atr_mult, title="MA1 ATRx", display=display.none, editable=false)
plot(ma2_atr_mult, title="MA2 ATRx", display=display.none, editable=false)
plot(ma3_atr_mult, title="MA3 ATRx", display=display.none, editable=false)
// Relative Strength
plot(sts_score, title="STS %", display=display.none, editable=false)
plot(rs_ratio, title="Stock/SPY Ratio", display=display.none, editable=false)
plot(sector_rs, title="Sector RS", display=display.none, editable=false)
plot(industry_rs, title="Industry RS", display=display.none, editable=false)