StormCore | SMC & Divergence Master [Auto-HTF]

StormCore · study · 538 行 · 点赞 80 · TradingView 原页

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

Pine Script

//@version=6
// @author Andy Storm | AI-StormCore
indicator("StormCore | SMC & Div Master v1.10", shorttitle="SC | SMC & Div v1.10", overlay=true, max_boxes_count=100, max_lines_count=500, max_labels_count=500, max_bars_back=4000)
 
// ==============================================================================
// ━━━ SMC MODULE SETTINGS ━━━
// ==============================================================================
grp_main_smc  = "━━━ SMC: MAIN SETTINGS ━━━"
bool showFVG   = input.bool(true, title="StormCore Auto: Show HTF FVG", group=grp_main_smc, tooltip="Toggle visibility of the Higher Timeframe Fair Value Gap.")
bool showOB    = input.bool(true, title="StormCore Auto: Show HTF OB", group=grp_main_smc, tooltip="Toggle visibility of the Higher Timeframe Order Block.")
bool showCHoCH = input.bool(true, title="StormCore Auto: Show HTF CHoCH", group=grp_main_smc, tooltip="Toggle visibility of the Higher Timeframe Change of Character level.")
 
grp_logic_smc = "━━━ SMC: LOGIC & SENSITIVITY ━━━"
int pivotLeft  = input.int(5, title="Pivot Left Bars", minval=1, group=grp_logic_smc)
int pivotRight = input.int(3, title="Pivot Right Bars", minval=1, group=grp_logic_smc)
int lookbackOB = input.int(50, title="Lookback for FVG/OB (Bars)", minval=10, group=grp_logic_smc)
int maxHistory = input.int(15, title="Max Historical Setups", minval=1, maxval=40, group=grp_logic_smc)
 
grp_vis_smc   = "━━━ SMC: VISUALS & ZONES ━━━"
string posHTF    = input.string("Bottom Right", "HTF Dashboard Position", options=["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group=grp_vis_smc, tooltip="Позиция информационного блока старшего таймфрейма.")
color colOB_Bull = input.color(color.new(color.teal, 80), title="Bullish OB Color", group=grp_vis_smc)
color colOB_Bear = input.color(color.new(color.maroon, 80), title="Bearish OB Color", group=grp_vis_smc)
color colFVG_Bull= input.color(color.new(color.green, 85), title="Bullish FVG Color", group=grp_vis_smc)
color colFVG_Bear= input.color(color.new(color.red, 85), title="Bearish FVG Color", group=grp_vis_smc)
color colCHoCH   = input.color(#ffffffab, title="CHoCH Line Color", group=grp_vis_smc)
 
 
// ==============================================================================
// ━━━ DIV MODULE SETTINGS ━━━
// ==============================================================================
grp_main_div = "━━━ DIV: MAIN SETTINGS ━━━"
auto_mtf = input.bool(true, "StormCore Auto: MTF Dynamics", group=grp_main_div, tooltip="Автоматически меняет Pivot Period в зависимости от таймфрейма (1M=2, 1W=4, 1D=20). Отключает расчеты внутри дня для фильтрации шума.")
show_reg = input.bool(true, "StormCore Auto: Regular Divergences", group=grp_main_div)
show_hid = input.bool(true, "StormCore Auto: Hidden Divergences", group=grp_main_div)
prd      = input.int(5, "Pivot Period (Manual Mode)", minval=1, maxval=50, group=grp_main_div, tooltip="Используется только если выключен MTF Dynamics.")
src_type = input.string("Close", "Pivot Source", options=["Close", "High/Low"], group=grp_main_div)
min_divs = input.int(1, "Minimum Number of Divergence", minval=1, maxval=11, group=grp_main_div, tooltip="Минимальное количество индикаторов для подтверждения.")
max_bars = input.int(100, "Maximum Bars to Check", minval=30, maxval=300, group=grp_main_div)
show_last= input.bool(false, "Show Only Last Divergence", group=grp_main_div, tooltip="Очищает график от исторических линий.")
 
grp_ind_div = "━━━ DIV: INDICATORS TOGGLES ━━━"
use_macd  = input.bool(true, "MACD", group=grp_ind_div)
use_macdh = input.bool(true, "MACD Histogram", group=grp_ind_div)
use_rsi   = input.bool(true, "RSI", group=grp_ind_div)
use_stoch = input.bool(true, "Stochastic", group=grp_ind_div)
use_cci   = input.bool(true, "CCI", group=grp_ind_div)
use_mom   = input.bool(true, "Momentum", group=grp_ind_div)
use_obv   = input.bool(true, "OBV", group=grp_ind_div)
use_vwmacd= input.bool(true, "VW MACD", group=grp_ind_div)
use_cmf   = input.bool(true, "Chaikin Money Flow", group=grp_ind_div)
use_mfi   = input.bool(true, "Money Flow Index", group=grp_ind_div)
use_ext   = input.bool(true, "External Indicator", group=grp_ind_div)
ext_src   = input.source(close, "External Source", group=grp_ind_div)
 
grp_vis_div = "━━━ DIV: VISUALS & STYLES ━━━"
show_indis  = input.string("Don't Show", "Show Indicator Names", options=["Full", "First Letter", "Don't Show"], group=grp_vis_div)
show_num    = input.bool(true, "Show Divergence Number", group=grp_vis_div)
show_lines  = input.bool(false, "Draw Divergence Lines", group=grp_vis_div)
pos_reg_col = input.color(color.yellow, "Positive Regular", group=grp_vis_div, inline="c1")
neg_reg_col = input.color(color.navy, "Negative Regular", group=grp_vis_div, inline="c1")
pos_hid_col = input.color(color.lime, "Positive Hidden", group=grp_vis_div, inline="c2")
neg_hid_col = input.color(color.red, "Negative Hidden", group=grp_vis_div, inline="c2")
show_mas    = input.bool(false, "Show MAs (50 & 200)", group=grp_vis_div)
ma50_col    = input.color(color.lime, "MA 50", group=grp_vis_div, inline="ma")
ma200_col   = input.color(color.red, "MA 200", group=grp_vis_div, inline="ma")
 
 
// ==============================================================================
// ━━━ DIV DATA STRUCTURES & GLOBAL VARS ━━━
// ==============================================================================
type Pivot
    int bar
    float price
 
type DivSignal
    int type       
    int offset     
    string txt     
    color col
    int count      
 
var ph_arr = array.new<Pivot>()
var pl_arr = array.new<Pivot>()
 
var active_lines  = array.new_line()
var active_labels = array.new_label()
 
get_name(string full, string short) =>
    show_indis == "Full" ? full : (show_indis == "First Letter" ? short : "")
 
// ==============================================================================
// ━━━ SMC DATA STRUCTURES & GLOBAL VARS ━━━
// ==============================================================================
type RenderSetup
    box   b_ob
    box   b_fvg
    line  l_ch
    label lb_ch
    bool  isActive
    int   dir
    float ob_mit_level
    float fvg_mit_level
    bool  ob_mitigated
    bool  fvg_mitigated
 
var array<RenderSetup> setupPool = array.new<RenderSetup>()
var int currentSetupIdx = 0
var int activeSetupIdx = -1
var int lastProcessedSetupTime = na
 
if barstate.isfirst
    for i = 1 to maxHistory
        array.push(setupPool, RenderSetup.new(
             box.new(na,na,na,na, xloc=xloc.bar_time, border_color=color.new(color.white, 100)),
             box.new(na,na,na,na, xloc=xloc.bar_time, border_color=color.new(color.white, 100)),
             line.new(na,na,na,na, xloc=xloc.bar_time, style=line.style_dashed),
             label.new(na,na,"CHoCH", xloc=xloc.bar_time, style=label.style_label_left, size=size.small),
             false, 0, na, na, false, false
         ))
 
 
// ==============================================================================
// ━━━ DIV: MTF DYNAMICS LOGIC ━━━
// ==============================================================================
int calc_prd = prd
bool disable_calc = false
 
if auto_mtf
    if timeframe.ismonthly
        calc_prd := 2
    else if timeframe.isweekly
        calc_prd := 4
    else if timeframe.isdaily
        calc_prd := 20
    else if timeframe.isintraday
        disable_calc := true
 
 
// ==============================================================================
// ━━━ SMC: AUTO-HTF ENGINE & DASHBOARD ━━━
// ==============================================================================
getAutoHTF() =>
    bool isMins = timeframe.isminutes
    bool isDaily = timeframe.isdaily
    bool isWeekly = timeframe.isweekly
    int mult = timeframe.multiplier
    string htf = "1D" 
    
    if isMins
        if mult < 60
            htf := "60"
        else if mult >= 60 and mult <= 180
            htf := "240"
        else
            htf := "1D"
    else if isDaily
        htf := "1W"
    else if isWeekly
        htf := "1M"
    else
        htf := "1M"
    htf
 
string targetHTF = getAutoHTF()
 
// Dashboard Table Implementation (Replaces floating label)
string realPos = posHTF == "Top Right" ? position.top_right : posHTF == "Bottom Right" ? position.bottom_right : posHTF == "Top Left" ? position.top_left : position.bottom_left
var table htfTable = table.new(realPos, 1, 1, bgcolor=color.new(color.black, 40), frame_color=color.new(color.gray, 70), frame_width=1)
 
if barstate.islast
    table.cell(htfTable, 0, 0, "STORMCORE HTF: " + targetHTF, text_color=color.new(color.white, 10), text_size=size.small)
 
 
// ==============================================================================
// ━━━ DIV: METHODS & LOGIC ━━━
// ==============================================================================
method validate_slope(series float src, series float ind, int c_prd, int offset, int len, float p_price, float p_ind, bool is_low) =>
    bool is_clean = true
    float price_slope = (src[c_prd] - p_price) / len
    float ind_slope = (ind[c_prd] - p_ind) / len
    
    for j = 1 to len - 1
        int check_idx = c_prd + j
        float expected_price = src[c_prd] - (price_slope * j)
        float expected_ind = ind[c_prd] - (ind_slope * j)
        
        if is_low
            if src[check_idx] < expected_price or ind[check_idx] < expected_ind
                is_clean := false
                break
        else
            if src[check_idx] > expected_price or ind[check_idx] > expected_ind
                is_clean := false
                break
    is_clean
 
method check_div(series float src, series float ind, bool is_ph, bool is_pl, array<Pivot> p_highs, array<Pivot> p_lows, int c_prd, int max_b, bool check_reg, bool check_hid) =>
    bool pos_reg = false, bool neg_reg = false
    bool pos_hid = false, bool neg_hid = false
    int opr = 0, int onr = 0, int oph = 0, int onh = 0
    
    if is_pl
        for p in p_lows
            int curr_bar = bar_index - c_prd
            int len = curr_bar - p.bar
            if len > max_b
                break
            if len > 5
                int offset = bar_index - p.bar
                float p_ind = ind[offset]
                
                if check_reg and src[c_prd] < p.price and ind[c_prd] > p_ind
                    if validate_slope(src, ind, c_prd, offset, len, p.price, p_ind, true)
                        pos_reg := true, opr := offset
                        break
                if check_hid and src[c_prd] > p.price and ind[c_prd] < p_ind
                    if validate_slope(src, ind, c_prd, offset, len, p.price, p_ind, true)
                        pos_hid := true, oph := offset
                        break
                        
    if is_ph
        for p in p_highs
            int curr_bar = bar_index - c_prd
            int len = curr_bar - p.bar
            if len > max_b
                break
            if len > 5
                int offset = bar_index - p.bar
                float p_ind = ind[offset]
                
                if check_reg and src[c_prd] > p.price and ind[c_prd] < p_ind
                    if validate_slope(src, ind, c_prd, offset, len, p.price, p_ind, false)
                        neg_reg := true, onr := offset
                        break
                if check_hid and src[c_prd] < p.price and ind[c_prd] > p_ind
                    if validate_slope(src, ind, c_prd, offset, len, p.price, p_ind, false)
                        neg_hid := true, onh := offset
                        break
                        
    [pos_reg, neg_reg, pos_hid, neg_hid, opr, onr, oph, onh]
 
method add_signal(array<DivSignal> arr, int type, int offset, string name, color col) =>
    bool found = false
    for s in arr
        if s.type == type and s.offset == offset
            if name != ""
                s.txt += (s.txt == "" ? "" : "\n") + name
            s.count += 1
            found := true
            break
    if not found
        arr.push(DivSignal.new(type, offset, name, col, 1))
 
method process_indicator(array<DivSignal> sigs, bool enabled, string name, series float src, series float ind, bool is_ph, bool is_pl, array<Pivot> phs, array<Pivot> pls, int c_prd, int mx, bool c_reg, bool c_hid) =>
    if enabled
        [pr, nr, ph, nh, opr, onr, oph, onh] = check_div(src, ind, is_ph, is_pl, phs, pls, c_prd, mx, c_reg, c_hid)
        if pr
            sigs.add_signal(0, opr, name, pos_reg_col)
        if nr
            sigs.add_signal(1, onr, name, neg_reg_col)
        if ph
            sigs.add_signal(2, oph, name, pos_hid_col)
        if nh
            sigs.add_signal(3, onh, name, neg_hid_col)
 
 
// ==============================================================================
// ━━━ SMC: HTF CORE CALCULATION (EXECUTED INSIDE SECURITY) ━━━
// ==============================================================================
calc_smc(int pLeft, int pRight, int lookback) =>
    float smc_ph = ta.pivothigh(high, pLeft, pRight)
    float smc_pl = ta.pivotlow(low, pLeft, pRight)
 
    var float lastSwingHighPrice = na
    var int   lastSwingHighTime  = na
    var float lastSwingLowPrice  = na
    var int   lastSwingLowTime   = na
 
    if not na(smc_ph)
        lastSwingHighPrice := high[pRight]
        lastSwingHighTime  := time[pRight]
    if not na(smc_pl)
        lastSwingLowPrice := low[pRight]
        lastSwingLowTime  := time[pRight]
 
    var int trendDir = 1
    int activeDir = 0
    float chochLvl = na
    int chochT = na
 
    bool bearCHoCH = false
    bool bullCHoCH = false
 
    if trendDir == 1 and not na(lastSwingLowPrice)
        if close < lastSwingLowPrice 
            trendDir := -1
            chochLvl := lastSwingLowPrice
            chochT   := lastSwingLowTime
            bearCHoCH := true
 
    else if trendDir == -1 and not na(lastSwingHighPrice)
        if close > lastSwingHighPrice 
            trendDir := 1
            chochLvl := lastSwingHighPrice
            chochT   := lastSwingHighTime
            bullCHoCH := true
 
    float oTop = na, float oBot = na, int oTime = na
    float fTop = na, float fBot = na, int fTime = na
 
    if bearCHoCH
        bool fFVG = false, bool fOB = false
        for i = 1 to lookback
            if high[i] < low[i+2] and close[i+1] < open[i+1]
                fTop := low[i+2], fBot := high[i], fTime := time[i+2]
                fFVG := true
                break
        for i = 1 to lookback
            if close[i] > open[i] and time[i] <= lastSwingHighTime
                oTop := high[i], oBot := low[i], oTime := time[i]
                fOB := true
                break
        if fFVG and fOB
            activeDir := -1
 
    if bullCHoCH
        bool fFVG = false, bool fOB = false
        for i = 1 to lookback
            if low[i] > high[i+2] and close[i+1] > open[i+1]
                fTop := low[i], fBot := high[i+2], fTime := time[i+2]
                fFVG := true
                break
        for i = 1 to lookback
            if close[i] < open[i] and time[i] <= lastSwingLowTime
                oTop := high[i], oBot := low[i], oTime := time[i]
                fOB := true
                break
        if fFVG and fOB
            activeDir := 1
 
    [activeDir, oTop, oBot, oTime, fTop, fBot, fTime, chochLvl, chochT]
 
// ==============================================================================
// ━━━ SMC: SECURITY CALL (NO REPAINT) ━━━
// ==============================================================================
[sigDir, obT, obB, obTime, fvgT, fvgB, fvgTime, chLvl, chTime] = request.security(syminfo.tickerid, targetHTF, calc_smc(pivotLeft, pivotRight, lookbackOB), barmerge.gaps_off, barmerge.lookahead_off)
 
// ==============================================================================
// ━━━ SMC: HISTORY & MITIGATION MANAGEMENT ━━━
// ==============================================================================
// 1. Detect new HTF setup and assign to object pool
if sigDir != 0 and (na(lastProcessedSetupTime) or obTime != lastProcessedSetupTime)
    lastProcessedSetupTime := obTime
    
    currentSetupIdx := (currentSetupIdx + 1) % maxHistory
    activeSetupIdx := currentSetupIdx
    RenderSetup rs = array.get(setupPool, currentSetupIdx)
    
    color obColor  = sigDir == 1 ? colOB_Bull : colOB_Bear
    color fvgColor = sigDir == 1 ? colFVG_Bull : colFVG_Bear
    
    // Reset State & Mitigation Tracking
    rs.isActive := true
    rs.dir := sigDir
    rs.ob_mitigated := false
    rs.fvg_mitigated := false
    rs.ob_mit_level  := sigDir == 1 ? obT : obB // Bullish triggers on touching top, Bearish on touching bottom
    rs.fvg_mit_level := sigDir == 1 ? fvgT : fvgB 
    
    if showOB
        rs.b_ob.set_lefttop(obTime, obT), rs.b_ob.set_rightbottom(time, obB), rs.b_ob.set_bgcolor(obColor)
    else
        rs.b_ob.set_lefttop(na, na), rs.b_ob.set_rightbottom(na, na)
        
    if showFVG
        rs.b_fvg.set_lefttop(fvgTime, fvgT), rs.b_fvg.set_rightbottom(time, fvgB), rs.b_fvg.set_bgcolor(fvgColor)
    else
        rs.b_fvg.set_lefttop(na, na), rs.b_fvg.set_rightbottom(na, na)
 
    if showCHoCH
        rs.l_ch.set_xy1(chTime, chLvl), rs.l_ch.set_xy2(time, chLvl), rs.l_ch.set_color(colCHoCH)
        rs.lb_ch.set_xy(time, chLvl), rs.lb_ch.set_textcolor(colCHoCH), rs.lb_ch.set_color(color.new(color.white, 100))
    else
        rs.l_ch.set_xy1(na, na), rs.l_ch.set_xy2(na, na), rs.lb_ch.set_xy(na, na)
 
// 2. Mitigation Engine & Dynamic Extension (Loops through all valid history)
if array.size(setupPool) > 0
    for i = 0 to maxHistory - 1
        RenderSetup rs = array.get(setupPool, i)
        
        if rs.isActive
            // Check & Extend Order Block
            if not rs.ob_mitigated
                bool isHitOB = false
                if rs.dir == 1 and low <= rs.ob_mit_level   // Bullish OB mitigation
                    isHitOB := true
                else if rs.dir == -1 and high >= rs.ob_mit_level // Bearish OB mitigation
                    isHitOB := true
                    
                if isHitOB
                    rs.ob_mitigated := true
                
                if showOB
                    rs.b_ob.set_right(time)
            
            // Check & Extend Fair Value Gap
            if not rs.fvg_mitigated
                bool isHitFVG = false
                if rs.dir == 1 and low <= rs.fvg_mit_level   // Bullish FVG mitigation
                    isHitFVG := true
                else if rs.dir == -1 and high >= rs.fvg_mit_level // Bearish FVG mitigation
                    isHitFVG := true
                    
                if isHitFVG
                    rs.fvg_mitigated := true
                
                if showFVG
                    rs.b_fvg.set_right(time)
 
// 3. Extend ONLY the latest active CHoCH line dynamically
if activeSetupIdx != -1
    RenderSetup activeRS = array.get(setupPool, activeSetupIdx)
    if showCHoCH
        activeRS.lb_ch.set_x(time)
        activeRS.l_ch.set_x2(time)
 
 
// ==============================================================================
// ━━━ DIV: CORE CALCULATIONS ━━━
// ==============================================================================
float eval_src_high = src_type == "Close" ? close : high
float eval_src_low  = src_type == "Close" ? close : low
float eval_src      = src_type == "Close" ? close : hl2
 
float div_ph = ta.pivothigh(eval_src_high, calc_prd, calc_prd)
float div_pl = ta.pivotlow(eval_src_low, calc_prd, calc_prd)
bool new_ph = not na(div_ph) and not disable_calc
bool new_pl = not na(div_pl) and not disable_calc
 
float rsi_val   = ta.rsi(close, 14)
[macd_line, sig_line, macd_hist] = ta.macd(close, 12, 26, 9)
float stoch_val = ta.sma(ta.stoch(close, high, low, 14), 3)
float cci_val   = ta.cci(close, 10)
float mom_val   = ta.mom(close, 10)
float obv_val   = ta.cum(math.sign(ta.change(close)) * volume)
float vwmacd_val= ta.vwma(close, 12) - ta.vwma(close, 26)
float cmf_val   = ta.sma(((close-low) - (high-close)) / (high - low == 0 ? 1 : high - low) * volume, 21) / ta.sma(volume, 21)
float mfi_val   = ta.mfi(close, 14)
float ext_val   = ext_src
 
// ==============================================================================
// ━━━ DIV: SIGNAL PROCESSING ━━━
// ==============================================================================
DivSignal[] current_signals = array.new<DivSignal>()
 
if (new_pl or new_ph) and not disable_calc
    current_signals.process_indicator(use_macd,  get_name("MACD", "M"), eval_src, macd_line, new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_macdh, get_name("Hist", "H"), eval_src, macd_hist, new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_rsi,   get_name("RSI",  "R"), eval_src, rsi_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_stoch, get_name("Stoch","S"), eval_src, stoch_val, new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_cci,   get_name("CCI",  "C"), eval_src, cci_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_mom,   get_name("Mom",  "M"), eval_src, mom_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_obv,   get_name("OBV",  "O"), eval_src, obv_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_vwmacd,get_name("VWM",  "V"), eval_src, vwmacd_val,new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_cmf,   get_name("CMF",  "C"), eval_src, cmf_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_mfi,   get_name("MFI",  "M"), eval_src, mfi_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    current_signals.process_indicator(use_ext,   get_name("Ext",  "X"), eval_src, ext_val,   new_ph, new_pl, ph_arr, pl_arr, calc_prd, max_bars, show_reg, show_hid)
    
    if new_ph
        ph_arr.unshift(Pivot.new(bar_index[calc_prd], div_ph))
        if ph_arr.size() > 15
            ph_arr.pop()
            
    if new_pl
        pl_arr.unshift(Pivot.new(bar_index[calc_prd], div_pl))
        if pl_arr.size() > 15
            pl_arr.pop()
 
// ==============================================================================
// ━━━ DIV: DRAWINGS & ALERTS ━━━
// ==============================================================================
if show_last and current_signals.size() > 0
    for ln in active_lines
        ln.delete()
    for lb in active_labels
        lb.delete()
    active_lines.clear()
    active_labels.clear()
 
bool a_pos_reg = false
bool a_neg_reg = false
bool a_pos_hid = false
bool a_neg_hid = false
 
for s in current_signals
    if s.count >= min_divs
        if s.type == 0
            a_pos_reg := true
        if s.type == 1
            a_neg_reg := true
        if s.type == 2
            a_pos_hid := true
        if s.type == 3
            a_neg_hid := true
        
        float y1 = src_type == "Close" ? close[s.offset] : (s.type == 0 or s.type == 2 ? low[s.offset] : high[s.offset])
        float y2 = src_type == "Close" ? close[calc_prd] : (s.type == 0 or s.type == 2 ? low[calc_prd] : high[calc_prd])
        
        line ln = show_lines ? line.new(bar_index - s.offset, y1, bar_index - calc_prd, y2, color=s.col, width=2, style= s.type <= 1 ? line.style_solid : line.style_dashed) : na
        
        string final_txt = s.txt
        if show_num
            final_txt += (final_txt == "" ? "" : "\n") + str.tostring(s.count)
            
        label lb = na
        if final_txt != ""
            if s.type == 0 or s.type == 2
                lb := label.new(bar_index - calc_prd, low[calc_prd], text=final_txt, color=s.col, style=label.style_label_up, size=size.small, textcolor=color.black)
            else
                lb := label.new(bar_index - calc_prd, high[calc_prd], text=final_txt, color=s.col, style=label.style_label_down, size=size.small, textcolor=color.white)
                
        if show_last
            if not na(ln)
                active_lines.push(ln)
            if not na(lb)
                active_labels.push(lb)
 
alertcondition(a_pos_reg, title="SC: Positive Regular Divergence", message="SC: Positive Regular Divergence Detected")
alertcondition(a_neg_reg, title="SC: Negative Regular Divergence", message="SC: Negative Regular Divergence Detected")
alertcondition(a_pos_hid, title="SC: Positive Hidden Divergence",  message="SC: Positive Hidden Divergence Detected")
alertcondition(a_neg_hid, title="SC: Negative Hidden Divergence",  message="SC: Negative Hidden Divergence Detected")
 
plot(show_mas ? ta.sma(close, 50)  : na, title="MA 50",  color=ma50_col,  linewidth=2)
plot(show_mas ? ta.sma(close, 200) : na, title="MA 200", color=ma200_col, linewidth=2)
 
// ==============================================================================
// ━━━ EOF ━━━
// ==============================================================================

← 返回列表