本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org
// © 2026 David F. Henss aka "TexHenss" (dave.henss@gmail.com). All rights reserved.
// For Educational Purposes only, Not Financial Advice - 10.31.2026 Free to Use, Read Matthew 6:31–33 is all I ask
// Open-Source Distribution | Public Release Matrix
// Notice: Free to use, redistribute, and modify under MPL 2.0 terms. Please retain author credentials and contact info in all derivative works.
// DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES, OR LOSSES ARISING FROM THE USE OF THIS CODE.
//@version=6
indicator("TexHenss Core Matrix (SMA, Clouds & Gaps)", overlay=true)
var string G_FIB = "Fibonacci Cloud Layout Settings"
var string G_GEN = "General Settings"
var string G_GAP = "Daily Gap Pattern Tracking Engine"
fib_mult1 = input.float(1.618, title="Cloud Tier 1 Multiplier", step=0.01, group=G_FIB)
fib_mult2 = input.float(2.272, title="Cloud Tier 2 Multiplier", step=0.01, group=G_FIB)
fib_mult3 = input.float(2.786, title="Cloud Tier 3 Multiplier", step=0.01, group=G_FIB)
fib_mult4 = input.float(3.272, title="Cloud Tier 4 Multiplier", step=0.01, group=G_FIB)
line_width = input.int(1, title="Line Width (Master Scaling)", minval=1, maxval=5, group=G_GEN)
sma_len1 = input.int(9, title="SMA 1 Length", minval=1, group=G_GEN)
sma_len2 = input.int(20, title="SMA 2 Length", minval=1, group=G_GEN)
sma_len3 = input.int(50, title="SMA 3 Length", minval=1, group=G_GEN)
sma_len4 = input.int(100, title="SMA 4 Length", minval=1, group=G_GEN)
sma_len5 = input.int(200, title="SMA 5 Length", minval=1, group=G_GEN)
sma_len6 = input.int(400, title="SMA 6 Length", minval=1, group=G_GEN)
sma_len7 = input.int(600, title="SMA 7 Length", minval=1, group=G_GEN)
sma_len8 = input.int(800, title="SMA 8 Length", minval=1, group=G_GEN)
use_gap_engine = input.bool(true, title="Enable Auto-Gap Discovery Renders", group=G_GAP)
gap_bull_border = input.color(#4caf50, title="Bullish Gap Border Color", group=G_GAP)
gap_bear_border = input.color(#f44336, title="Bearish Gap Border Color", group=G_GAP)
gap_border_width = input.int(1, title="Gap Border Line Boldness", minval=1, maxval=5, group=G_GAP)
f_daily_calculations(l1, l2, l3, l4, l5, l6, l7, l8) =>
s1 = ta.sma(close, l1)
s2 = ta.sma(close, l2)
s3 = ta.sma(close, l3)
s4 = ta.sma(close, l4)
s5 = ta.sma(close, l5)
s6 = ta.sma(close, l6)
s7 = ta.sma(close, l7)
s8 = ta.sma(close, l8)
dev = ta.stdev(close, l3)
[s1, s2, s3, s4, s5, s6, s7, s8, dev]
[mtf_sma1, mtf_sma2, mtf_sma3, mtf_sma4, mtf_sma5, mtf_sma6, mtf_sma7, mtf_sma8, daily_dev] = request.security(syminfo.tickerid, "D", f_daily_calculations(sma_len1, sma_len2, sma_len3, sma_len4, sma_len5, sma_len6, sma_len7, sma_len8), lookahead=barmerge.lookahead_off)
fib_upper_t1 = mtf_sma3 + (fib_mult1 * daily_dev)
fib_upper_t2 = mtf_sma3 + (fib_mult2 * daily_dev)
fib_upper_t3 = mtf_sma3 + (fib_mult3 * daily_dev)
fib_upper_t4 = mtf_sma3 + (fib_mult4 * daily_dev)
fib_lower_t1 = mtf_sma3 - (fib_mult1 * daily_dev)
fib_lower_t2 = mtf_sma3 - (fib_mult2 * daily_dev)
fib_lower_t3 = mtf_sma3 - (fib_mult3 * daily_dev)
fib_lower_t4 = mtf_sma3 - (fib_mult4 * daily_dev)
plot(mtf_sma1, title="Daily SMA 1", color=#7e57c2, linewidth=line_width, style=plot.style_steplinebr)
plot(mtf_sma2, title="Daily SMA 2", color=#4caf50, linewidth=line_width, style=plot.style_steplinebr)
plot(mtf_sma3, title="Daily SMA 3", color=#ff9800, linewidth=2, style=plot.style_steplinebr)
plot(mtf_sma4, title="Daily SMA 4", color=#f44336, linewidth=2)
plot(mtf_sma5, title="Daily SMA 5", color=#787b86, linewidth=line_width)
plot(mtf_sma6, title="Daily SMA 6", color=#ffffff, linewidth=line_width)
plot(mtf_sma7, title="Daily SMA 7", color=#f06292, linewidth=line_width)
plot(mtf_sma8, title="Daily SMA 8", color=#673ab7, linewidth=line_width)
var label lbl_sma1 = na, var label lbl_sma2 = na, var label lbl_sma3 = na
var label lbl_sma4 = na, var label lbl_sma5 = na, var label lbl_sma6 = na, var label lbl_sma7 = na, var label lbl_sma8 = na
if barstate.islast
label.delete(lbl_sma1), label.delete(lbl_sma2), label.delete(lbl_sma3)
label.delete(lbl_sma4), label.delete(lbl_sma5), label.delete(lbl_sma6), label.delete(lbl_sma7), label.delete(lbl_sma8)
color trans_bg = color.new(color.black, 100)
int inner_offset = bar_index + 1
if not na(mtf_sma1)
lbl_sma1 := label.new(x=inner_offset, y=mtf_sma1, text="SMA " + str.tostring(sma_len1), color=trans_bg, textcolor=#7e57c2, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma2)
lbl_sma2 := label.new(x=inner_offset, y=mtf_sma2, text="SMA " + str.tostring(sma_len2), color=trans_bg, textcolor=#4caf50, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma3)
lbl_sma3 := label.new(x=inner_offset, y=mtf_sma3, text="SMA " + str.tostring(sma_len3), color=trans_bg, textcolor=#ff9800, style=label.style_none, size=size.small, textalign=text.align_left)
int outer_offset = bar_index + 4
if not na(mtf_sma4)
lbl_sma4 := label.new(x=outer_offset, y=mtf_sma4, text="SMA " + str.tostring(sma_len4), color=trans_bg, textcolor=#f44336, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma5)
lbl_sma5 := label.new(x=outer_offset, y=mtf_sma5, text="SMA " + str.tostring(sma_len5), color=trans_bg, textcolor=#787b86, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma6)
lbl_sma6 := label.new(x=outer_offset, y=mtf_sma6, text="SMA " + str.tostring(sma_len6), color=trans_bg, textcolor=#ffffff, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma7)
lbl_sma7 := label.new(x=outer_offset, y=mtf_sma7, text="SMA " + str.tostring(sma_len7), color=trans_bg, textcolor=#f06292, style=label.style_none, size=size.small, textalign=text.align_left)
if not na(mtf_sma8)
lbl_sma8 := label.new(x=outer_offset, y=mtf_sma8, text="SMA " + str.tostring(sma_len8), color=trans_bg, textcolor=#673ab7, style=label.style_none, size=size.small, textalign=text.align_left)
p_u_t1 = plot(fib_upper_t1, title="Fib Upper T1", color=color.new(color.purple, 100), display=display.none)
p_u_t2 = plot(fib_upper_t2, title="Fib Upper T2", color=color.new(color.purple, 100), display=display.none)
p_u_t3 = plot(fib_upper_t3, title="Fib Upper T3", color=color.new(color.purple, 100), display=display.none)
p_u_t4 = plot(fib_upper_t4, title="Fib Upper T4", color=color.new(color.purple, 100), display=display.none)
p_l_t1 = plot(fib_lower_t1, title="Fib Lower T1", color=color.new(color.gray, 100), display=display.none)
p_l_t2 = plot(fib_lower_t2, title="Fib Lower T2", color=color.new(color.gray, 100), display=display.none)
p_l_t3 = plot(fib_lower_t3, title="Fib Lower T3", color=color.new(color.gray, 100), display=display.none)
p_l_t4 = plot(fib_lower_t4, title="Fib Lower T4", color=color.new(color.gray, 100), display=display.none)
fill(p_u_t1, p_u_t2, color=color.new(color.purple, 85), title="Upper Cloud Tier 1-2")
fill(p_u_t2, p_u_t3, color=color.new(color.purple, 70), title="Upper Cloud Tier 2-3")
fill(p_u_t3, p_u_t4, color=color.new(color.purple, 50), title="Upper Cloud Tier 3-4")
fill(p_l_t1, p_l_t2, color=color.new(color.gray, 85), title="Lower Cloud Tier 1-2")
fill(p_l_t2, p_l_t3, color=color.new(color.gray, 70), title="Lower Cloud Tier 2-3")
fill(p_l_t3, p_l_t4, color=color.new(color.gray, 50), title="Lower Cloud Tier 3-4")
type DailyGapRay
line top_ray
line bot_ray
label gap_lbl
bool is_up_gap
float boundary_high
float boundary_low
int start_bar
var DailyGapRay[] active_rays = array.new<DailyGapRay>()
f_get_gap_date_string() =>
string day_name = str.format("{0,date,EEEE}", time)
string m_name = str.format("{0,date,MMMM}", time)
int d_num = dayofmonth(time)
string suffix = "th"
if d_num == 1 or d_num == 21 or d_num == 31
suffix := "st"
else if d_num == 2 or d_num == 22
suffix := "nd"
else if d_num == 3 or d_num == 23
suffix := "rd"
day_name + " " + m_name + " " + str.tostring(d_num) + suffix + " Gap"
[d_high, d_low] = request.security(syminfo.tickerid, "D", [high, low], lookahead=barmerge.lookahead_off)
[d_prev_high, d_prev_low] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead=barmerge.lookahead_off)
bool is_new_daily_bar = ta.change(time("D")) != 0
if use_gap_engine and is_new_daily_bar and not na(d_prev_high) and not na(d_low)
bool is_up = d_low > d_prev_high
bool is_down = d_high < d_prev_low
if is_up or is_down
float g_top = is_up ? d_low : d_prev_low
float g_bottom = is_up ? d_prev_high : d_high
color c_line = is_up ? gap_bull_border : gap_bear_border
line t_l = line.new(x1=time, y1=g_top, x2=time + 86400000, y2=g_top, color=c_line, width=gap_border_width, extend=extend.right, xloc=xloc.bar_time)
line b_l = line.new(x1=time, y1=g_bottom, x2=time + 86400000, y2=g_bottom, color=c_line, width=gap_border_width, extend=extend.right, xloc=xloc.bar_time)
label l = label.new(x=time, y=(g_top + g_bottom) / 2, text=f_get_gap_date_string(), color=color.new(color.black, 100), textcolor=c_line, style=label.style_none, size=size.small, textalign=text.align_left, xloc=xloc.bar_time)
array.push(active_rays, DailyGapRay.new(t_l, b_l, l, is_up, g_top, g_bottom, bar_index))
if use_gap_engine and array.size(active_rays) > 0
for i = array.size(active_rays) - 1 to 0 by 1
DailyGapRay ray = array.get(active_rays, i)
bool is_wiped = false
if ray.is_up_gap
if low <= ray.boundary_low and bar_index > ray.start_bar
is_wiped := true
else
if high >= ray.boundary_high and bar_index > ray.start_bar
is_wiped := true
if is_wiped
line.delete(ray.top_ray), line.delete(ray.bot_ray), label.delete(ray.gap_lbl)
array.remove(active_rays, i)
else if barstate.islast
label.set_x(ray.gap_lbl, time)