本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//══════════════════════════════════════════════════════════════════════════════
//
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// ----------------------------------------------------------------------------
// SMART MONEY VOLUME MATRIX [Ata]
// ----------------------------------------------------------------------------
// Copyright (c) 2025 Ata Sabancı
// Coding by Ata Sabancı
// ----------------------------------------------------------------------------
// FEATURES:
// 1. VSA LOGIC: Detecting Distribution, No Demand, Absorption, and Exhaustion.
// 2. SNAPSHOT SYNC: 100% Data match between Chart Labels and Dashboard Table.
// 3. SMART ZONES: Auto-detection of critical Support/Resistance based on Volume Leaders.
// 4. TREND ENGINE: Linear Regression Trend Lines with Channel Fill.
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
//
//══════════════════════════════════════════════════════════════════════════════
// @version=6
indicator("Smart Money Volume Matrix [Ata]", shorttitle="SMV Matrix", overlay=true, max_labels_count=500, max_bars_back=500, max_lines_count=500, max_boxes_count=500)
//══════════════
// Imports & Settings
//══════════════
import TradingView/ta/10 as tvta
string grpMain = "Matrix Settings"
int lookback_len = input.int(100, "Lookback Period", minval=10, group=grpMain)
int top_count = input.int(10, "Top Rank Count", minval=1, group=grpMain)
int proj_len = input.int(26, "Projection Length (Bars)", minval=1, group=grpMain)
string grpVol = "Volume Engine"
string calc_method = input.string("Geometry (Approx)", "Calculation Method", options = ["Geometry (Approx)", "Intrabar (Precise)"], group=grpVol)
string ltf_input = input.timeframe("15S", "Intrabar Timeframe", group=grpVol)
string grpVis = "Visuals"
bool show_table = input.bool(true, "Show Dashboard Table", group=grpVis)
bool show_labels = input.bool(true, "Show Chart Labels", group=grpVis)
bool show_lines = input.bool(true, "Show Label Guide Lines", group=grpVis)
bool show_zones = input.bool(true, "Show S/R Zones", group=grpVis)
int lbl_transp = input.int(20, "Label Transparency", minval=0, maxval=90, group=grpVis)
string txt_size_tbl = input.string("Small", "Table Font Size", options=["Tiny", "Small", "Normal", "Large"], group=grpVis)
string txt_size_lbl = input.string("Small", "Chart Label Size", options=["Tiny", "Small", "Normal", "Large"], group=grpVis)
string grpTrend = "Trend Lines"
bool show_trend = input.bool(true, "Show Trend Channel", group=grpTrend)
string tr_style_in = input.string("Dashed", "Line Style", options=["Solid", "Dashed", "Dotted"], group=grpTrend)
int tr_width = input.int(2, "Line Width", minval=1, group=grpTrend)
color tr_col_h = input.color(color.new(#ffcd03, 0), "High Line Color", group=grpTrend)
color tr_col_l = input.color(color.new(#ffcd03, 0), "Low Line Color", group=grpTrend)
color tr_fill_col = input.color(color.new(color.orange, 90), "Channel Fill Color", group=grpTrend)
// Group Colors
color col_g1 = input.color(#ff0000, "G1: Distribution", group=grpVis)
color col_g2 = input.color(#ffcd03, "G2: No Demand", group=grpVis)
color col_g3 = input.color(#00E676, "G3: Absorption", group=grpVis)
color col_g4 = input.color(#00bcd4, "G4: Exhaustion", group=grpVis)
string tbl_pos = input.string(position.top_right, "Table Position", options=[position.top_right, position.bottom_right, position.top_left], group=grpVis)
//══════════════
// Data Structures
//══════════════
type BarData
int idx
float price_h
float price_l
float price_c
float vol_b
float vol_s
int rank_h = 0
int rank_l = 0
[u_intra, d_intra, _] = tvta.requestUpAndDownVolume(ltf_input)
float b_curr = 0.0
float s_curr = 0.0
if calc_method == "Intrabar (Precise)"
b_curr := nz(math.abs(u_intra))
s_curr := nz(math.abs(d_intra))
else
float range_i = high - low
if range_i == 0
b_curr := volume * 0.5
s_curr := volume * 0.5
else
b_curr := volume * ((close - low) / range_i)
s_curr := volume * ((high - close) / range_i)
// --- Helpers ---
get_curr_symbol() =>
string c = syminfo.currency
string s = c
if c == "USD"
s := "$"
else if c == "EUR"
s := "€"
else if c == "TRY"
s := "₺"
else if c == "GBP"
s := "£"
else if c == "JPY"
s := "¥"
s
format_vol(float v) =>
string s = ""
if v >= 1000000000
s := str.format("{0,number,#.##}B", v / 1000000000)
else if v >= 1000000
s := str.format("{0,number,#.##}M", v / 1000000)
else if v >= 1000
s := str.format("{0,number,#.##}K", v / 1000)
else
s := str.format("{0,number,#.##}", v)
s
get_txt_size(string s) =>
string res = size.small
if s == "Tiny"
res := size.tiny
else if s == "Normal"
res := size.normal
else if s == "Large"
res := size.large
else if s == "Huge"
res := size.huge
res
get_line_style(string s) =>
string st = line.style_solid
if s == "Dashed"
st := line.style_dashed
else if s == "Dotted"
st := line.style_dotted
st
// Management Arrays
var label[] managed_labels = array.new_label()
var line[] managed_lines = array.new_line()
var linefill[] managed_fills = array.new_linefill()
var box[] managed_boxes = array.new_box()
float atr = ta.atr(14)
//══════════════
// CORE LOGIC (SNAPSHOT ENGINE)
//══════════════
// Executed only on the last bar to ensure zero-lag historical match
if barstate.islast
// 1. CLEANUP: Remove old drawings
while array.size(managed_labels) > 0
label.delete(array.pop(managed_labels))
while array.size(managed_lines) > 0
line.delete(array.pop(managed_lines))
while array.size(managed_fills) > 0
linefill.delete(array.pop(managed_fills))
while array.size(managed_boxes) > 0
box.delete(array.pop(managed_boxes))
// 2. Data Collection
BarData[] window_data = array.new<BarData>()
for i = 0 to lookback_len - 1
if (bar_index - i) < 0
break
float p_h = high[i]
float p_l = low[i]
float p_c = close[i]
float v_b = b_curr[i]
float v_s = s_curr[i]
int id = bar_index - i
array.push(window_data, BarData.new(id, p_h, p_l, p_c, v_b, v_s))
// 3. Volume Threshold Calculation
float[] all_vb = array.new_float()
float[] all_vs = array.new_float()
for item in window_data
array.push(all_vb, item.vol_b)
array.push(all_vs, item.vol_s)
array.sort(all_vb)
array.sort(all_vs)
int sz = array.size(all_vb)
float t_vb_hi = (sz > top_count) ? array.get(all_vb, sz - top_count) : 0.0
float t_vs_hi = (sz > top_count) ? array.get(all_vs, sz - top_count) : 0.0
float t_vb_lo = (sz > top_count) ? array.get(all_vb, top_count - 1) : 999999.9
float t_vs_lo = (sz > top_count) ? array.get(all_vs, top_count - 1) : 999999.9
// 4. Ranking Logic (Based on CLOSE Price)
BarData[] top_highs_c = array.copy(window_data)
int n = array.size(top_highs_c)
for i = 0 to math.min(top_count + 5, n - 1)
for j = 0 to n - 2 - i
BarData b1 = array.get(top_highs_c, j)
BarData b2 = array.get(top_highs_c, j + 1)
if b1.price_c < b2.price_c
array.set(top_highs_c, j, b2)
array.set(top_highs_c, j + 1, b1)
for i = 0 to n - 1
if i < top_count
BarData b = array.get(top_highs_c, i)
b.rank_h := i + 1
BarData[] top_lows_c = array.copy(window_data)
for i = 0 to math.min(top_count + 5, n - 1)
for j = 0 to n - 2 - i
BarData b1 = array.get(top_lows_c, j)
BarData b2 = array.get(top_lows_c, j + 1)
if b1.price_c > b2.price_c
array.set(top_lows_c, j, b2)
array.set(top_lows_c, j + 1, b1)
for i = 0 to n - 1
if i < top_count
BarData b = array.get(top_lows_c, i)
b.rank_l := i + 1
//══════════════
// ZONE DETECTION (Smart S/R)
//══════════════
float z_res_top = na
float z_res_bot = na
int z_res_idx = na
float z_sup_top = na
float z_sup_bot = na
int z_sup_idx = na
// Find Resistance (Highest Close with High Vol)
float max_c = na
for i = 0 to top_count - 1
BarData b = array.get(top_highs_c, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
if is_high_v
if na(max_c) or b.price_c > max_c
max_c := b.price_c
z_res_top := b.price_h
z_res_bot := b.price_l
z_res_idx := b.idx
// Find Support (Lowest Close with High Vol)
float min_c = na
for i = 0 to top_count - 1
BarData b = array.get(top_lows_c, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
if is_high_v
if na(min_c) or b.price_c < min_c
min_c := b.price_c
z_sup_top := b.price_h
z_sup_bot := b.price_l
z_sup_idx := b.idx
// Draw Zones
if show_zones
if not na(z_res_top)
box bx = box.new(z_res_idx, z_res_top, bar_index + proj_len, z_res_bot, color.new(col_g1, 50), 1, line.style_dashed, extend.none, xloc.bar_index, color.new(col_g1, 90))
array.push(managed_boxes, bx)
if not na(z_sup_top)
box bx = box.new(z_sup_idx, z_sup_top, bar_index + proj_len, z_sup_bot, color.new(col_g3, 50), 1, line.style_dashed, extend.none, xloc.bar_index, color.new(col_g3, 90))
array.push(managed_boxes, bx)
//══════════════
// TREND LINES (Linear Regression)
//══════════════
if show_trend
BarData[] trend_highs = array.copy(window_data)
int nt = array.size(trend_highs)
for i = 0 to math.min(top_count + 5, nt - 1)
for j = 0 to nt - 2 - i
BarData b1 = array.get(trend_highs, j)
BarData b2 = array.get(trend_highs, j + 1)
if b1.price_h < b2.price_h
array.set(trend_highs, j, b2)
array.set(trend_highs, j + 1, b1)
BarData[] trend_lows = array.copy(window_data)
for i = 0 to math.min(top_count + 5, nt - 1)
for j = 0 to nt - 2 - i
BarData b1 = array.get(trend_lows, j)
BarData b2 = array.get(trend_lows, j + 1)
if b1.price_l > b2.price_l
array.set(trend_lows, j, b2)
array.set(trend_lows, j + 1, b1)
float sum_x_h = 0.0, sum_y_h = 0.0, sum_xy_h = 0.0, sum_xx_h = 0.0
float sum_x_l = 0.0, sum_y_l = 0.0, sum_xy_l = 0.0, sum_xx_l = 0.0
int N = top_count
for i = 0 to top_count - 1
BarData bh = array.get(trend_highs, i)
sum_x_h += bh.idx
sum_y_h += bh.price_h
sum_xy_h += (bh.idx * bh.price_h)
sum_xx_h += (bh.idx * bh.idx)
BarData bl = array.get(trend_lows, i)
sum_x_l += bl.idx
sum_y_l += bl.price_l
sum_xy_l += (bl.idx * bl.price_l)
sum_xx_l += (bl.idx * bl.idx)
float m_h = (N * sum_xy_h - sum_x_h * sum_y_h) / (N * sum_xx_h - sum_x_h * sum_x_h)
float c_h = (sum_y_h - m_h * sum_x_h) / N
float m_l = (N * sum_xy_l - sum_x_l * sum_y_l) / (N * sum_xx_l - sum_x_l * sum_x_l)
float c_l = (sum_y_l - m_l * sum_x_l) / N
int x1 = bar_index - lookback_len + 1
int x2_proj = bar_index + proj_len
float y1_h = m_h * x1 + c_h
float y2_h = m_h * x2_proj + c_h
float y1_l = m_l * x1 + c_l
float y2_l = m_l * x2_proj + c_l
string tr_st_str = get_line_style(tr_style_in)
line ln_h = line.new(x1, y1_h, x2_proj, y2_h, xloc.bar_index, extend.none, tr_col_h, tr_st_str, tr_width)
line ln_l = line.new(x1, y1_l, x2_proj, y2_l, xloc.bar_index, extend.none, tr_col_l, tr_st_str, tr_width)
linefill lf = linefill.new(ln_h, ln_l, tr_fill_col)
array.push(managed_lines, ln_h)
array.push(managed_lines, ln_l)
array.push(managed_fills, lf)
//══════════════
// VISUALIZATION (Smart Labels)
//══════════════
if show_labels
string l_size = get_txt_size(txt_size_lbl)
float spacer = atr * 0.6
float gap = atr * 0.2
// Prepare Highs (Sort by Index for Stack logic)
BarData[] draw_highs = array.new<BarData>()
for i = 0 to top_count - 1
array.push(draw_highs, array.get(top_highs_c, i))
int nd = array.size(draw_highs)
if nd > 1
for i = 0 to nd - 2
for j = 0 to nd - 2 - i
BarData b1 = array.get(draw_highs, j)
BarData b2 = array.get(draw_highs, j + 1)
if b1.idx > b2.idx
array.set(draw_highs, j, b2)
array.set(draw_highs, j + 1, b1)
float last_y_h = 0.0
int last_x_h = -9999
for i = 0 to nd - 1
BarData b = array.get(draw_highs, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
bool is_low_v = (b.vol_b <= t_vb_lo) or (b.vol_s <= t_vs_lo)
bool sell_dom = b.vol_s > b.vol_b
string txt = "P " + str.tostring(b.rank_h)
string grp = ""
color col = color.gray
if is_high_v
col := col_g1
grp := sell_dom ? "Distribution" : "Buy Climax"
else if is_low_v
col := col_g2
grp := "No Demand"
if grp != ""
txt += "\n" + grp
float y_pos = b.price_h + spacer
// Smart Stack Up
if (b.idx - last_x_h) < 6
if y_pos < (last_y_h + spacer/2)
y_pos := math.max(y_pos, last_y_h + spacer)
label lbl = label.new(b.idx, y_pos, txt, xloc.bar_index, yloc.price, color.new(col, lbl_transp), label.style_label_down, color.white, l_size)
array.push(managed_labels, lbl)
if show_lines
line ln = line.new(b.idx, y_pos, b.idx, b.price_h + gap, xloc.bar_index, extend.none, color.new(col, 30), line.style_dashed, 1)
array.push(managed_lines, ln)
last_y_h := y_pos
last_x_h := b.idx
// Prepare Lows (Sort by Index for Stack logic)
BarData[] draw_lows = array.new<BarData>()
for i = 0 to top_count - 1
array.push(draw_lows, array.get(top_lows_c, i))
int ndl = array.size(draw_lows)
if ndl > 1
for i = 0 to ndl - 2
for j = 0 to ndl - 2 - i
BarData b1 = array.get(draw_lows, j)
BarData b2 = array.get(draw_lows, j + 1)
if b1.idx > b2.idx
array.set(draw_lows, j, b2)
array.set(draw_lows, j + 1, b1)
float last_y_l = 10000000.0
int last_x_l = -9999
for i = 0 to ndl - 1
BarData b = array.get(draw_lows, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
bool is_low_v = (b.vol_b <= t_vb_lo) or (b.vol_s <= t_vs_lo)
bool buy_dom = b.vol_b > b.vol_s
string txt = "L " + str.tostring(b.rank_l)
string grp = ""
color col = color.gray
if is_high_v
col := col_g3
grp := buy_dom ? "Absorption" : "Panic Sell"
else if is_low_v
col := col_g4
grp := "Exhaustion"
if grp != ""
txt += "\n" + grp
float y_pos_l = b.price_l - spacer
// Smart Stack Down
if (b.idx - last_x_l) < 6
if y_pos_l > (last_y_l - spacer/2)
y_pos_l := math.min(y_pos_l, last_y_l - spacer)
label lbl = label.new(b.idx, y_pos_l, txt, xloc.bar_index, yloc.price, color.new(col, lbl_transp), label.style_label_up, color.white, l_size)
array.push(managed_labels, lbl)
if show_lines
line ln = line.new(b.idx, y_pos_l, b.idx, b.price_l - gap, xloc.bar_index, extend.none, color.new(col, 30), line.style_dashed, 1)
array.push(managed_lines, ln)
last_y_l := y_pos_l
last_x_l := b.idx
//══════════════
// DASHBOARD RENDER
//══════════════
if show_table
string t_size = get_txt_size(txt_size_tbl)
var table tbl = table.new(tbl_pos, 5, 45, border_width=1, frame_color=color.gray, border_color=color.gray)
table.cell(tbl, 0, 0, "HIGH PRICE LEADERS (Close)", text_color=color.white, bgcolor=color.new(col_g1, 30), text_size=t_size)
table.merge_cells(tbl, 0, 0, 4, 0)
color header_bg = #333333
table.cell(tbl, 0, 1, "Rank", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 1, 1, "Close", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 2, 1, "Buy Vol", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 3, 1, "Sell Vol", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 4, 1, "Group", bgcolor=header_bg, text_color=color.white, text_size=t_size)
for i = 0 to top_count - 1
BarData b = array.get(top_highs_c, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
bool is_low_v = (b.vol_b <= t_vb_lo) or (b.vol_s <= t_vs_lo)
bool sell_dom = b.vol_s > b.vol_b
string status = "-"
color bg = color.black
if is_high_v
bg := color.new(col_g1, 60)
status := sell_dom ? "Distribution" : "Buy Climax"
else if is_low_v
bg := color.new(col_g2, 60)
status := "No Demand"
table.cell(tbl, 0, i+2, str.tostring(i+1), text_color=color.white, bgcolor=bg, text_size=t_size)
table.cell(tbl, 1, i+2, str.tostring(b.price_c, format.mintick), text_color=color.white, bgcolor=bg, text_size=t_size)
table.cell(tbl, 2, i+2, format_vol(b.vol_b), text_color=color.green, bgcolor=bg, text_size=t_size)
table.cell(tbl, 3, i+2, format_vol(b.vol_s), text_color=color.red, bgcolor=bg, text_size=t_size)
table.cell(tbl, 4, i+2, status, text_color=color.white, bgcolor=bg, text_size=t_size)
int row_offset = top_count + 3
table.cell(tbl, 0, row_offset, "LOW PRICE LEADERS (Close)", text_color=color.white, bgcolor=color.new(col_g3, 30), text_size=t_size)
table.merge_cells(tbl, 0, row_offset, 4, row_offset)
table.cell(tbl, 0, row_offset+1, "Rank", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 1, row_offset+1, "Close", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 2, row_offset+1, "Buy Vol", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 3, row_offset+1, "Sell Vol", bgcolor=header_bg, text_color=color.white, text_size=t_size)
table.cell(tbl, 4, row_offset+1, "Group", bgcolor=header_bg, text_color=color.white, text_size=t_size)
for i = 0 to top_count - 1
BarData b = array.get(top_lows_c, i)
bool is_high_v = (b.vol_b >= t_vb_hi) or (b.vol_s >= t_vs_hi)
bool is_low_v = (b.vol_b <= t_vb_lo) or (b.vol_s <= t_vs_lo)
bool buy_dom = b.vol_b > b.vol_s
string status = "-"
color bg = color.black
if is_high_v
bg := color.new(col_g3, 60)
status := buy_dom ? "Absorption" : "Panic Sell"
else if is_low_v
bg := color.new(col_g4, 60)
status := "Exhaustion"
table.cell(tbl, 0, row_offset + 2 + i, str.tostring(i+1), text_color=color.white, bgcolor=bg, text_size=t_size)
table.cell(tbl, 1, row_offset + 2 + i, str.tostring(b.price_c, format.mintick), text_color=color.white, bgcolor=bg, text_size=t_size)
table.cell(tbl, 2, row_offset + 2 + i, format_vol(b.vol_b), text_color=color.green, bgcolor=bg, text_size=t_size)
table.cell(tbl, 3, row_offset + 2 + i, format_vol(b.vol_s), text_color=color.red, bgcolor=bg, text_size=t_size)
table.cell(tbl, 4, row_offset + 2 + i, status, text_color=color.white, bgcolor=bg, text_size=t_size)
// --- FOOTER ---
int f_start = row_offset + top_count + 2
string cur_sym = get_curr_symbol()
// Resistance
string res_txt = "No Major Resistance"
if not na(z_res_top)
res_txt := "[R] RESISTANCE ZONE: " + str.tostring(z_res_bot, format.mintick) + " ~ " + str.tostring(z_res_top, format.mintick) + " " + cur_sym
table.cell(tbl, 0, f_start, res_txt, text_color=color.white, bgcolor=color.new(col_g1, 80), text_size=t_size)
table.merge_cells(tbl, 0, f_start, 4, f_start)
// Status
string stat_txt = "Waiting..."
color stat_col = color.gray
float cur = close
if not na(z_res_top) and not na(z_sup_top)
if cur > z_res_top
stat_txt := ">> BREAKOUT! (Flip to Support)"
stat_col := #00E676
else if cur < z_sup_bot
stat_txt := "<< BROKEN! (Flip to Resistance)"
stat_col := #ff0000
else if cur > (z_res_bot * 0.99)
stat_txt := "[!] TESTING RESISTANCE"
stat_col := #ffcd03
else if cur < (z_sup_top * 1.01)
stat_txt := "[!] AT SUPPORT AREA"
stat_col := #00E676
else
stat_txt := "~ MID RANGE"
table.cell(tbl, 0, f_start+1, stat_txt, text_color=stat_col, bgcolor=#333333, text_size=t_size)
table.merge_cells(tbl, 0, f_start+1, 4, f_start+1)
// Support
string sup_txt = "No Major Support"
if not na(z_sup_top)
sup_txt := "[S] SUPPORT ZONE: " + str.tostring(z_sup_bot, format.mintick) + " ~ " + str.tostring(z_sup_top, format.mintick) + " " + cur_sym
table.cell(tbl, 0, f_start+2, sup_txt, text_color=color.white, bgcolor=color.new(col_g3, 80), text_size=t_size)
table.merge_cells(tbl, 0, f_start+2, 4, f_start+2)