SMT Divergence ICT 02 [TradingFinder] Smart Money Technique SMC

TradingFinder · study · 132 行 · 点赞 3,279 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TFlab
 
//@version=6
indicator("SMT Divergence ICT 02 [TradingFinder] Smart Money Technique SMC", "TFlab SMT" ,overlay = false, max_bars_back = 5000, max_labels_count = 500, max_lines_count = 500)
 
// Import Library
import TFlab/AlertSenderLibrary_TradingFinder/1 as AlertSender
// input
    //Logic
SymY      = input.symbol('', 'Symbol' , group = 'Logical Setting')
Period    = input.int(3, 'Pivot Period', group = 'Logical Setting')
MxPBack_b = input.bool(true, 'Activate Max Pivot Back', group = 'Logical Setting')
MxPBack_i = input.int(100, 'Max Pivot Back Length', group = 'Logical Setting') 
Threshold = input.int(2, 'Pivot Sync Threshold', group = 'Logical Setting') 
Validity  = input.int(30, 'Validity Pivot Length', group = 'Logical Setting') 
 
    //Display
Show_Line_Bull  = input.bool(false, 'Show Bullish SMT Line', inline = 'Bull' , group = 'Display Setting')
Show_Label_Bull = input.bool(true , 'Show Bullish SMT Label' , group = 'Display Setting')
Color_Bull      = input.color(#006803 , '', inline = 'Bull' , group = 'Display Setting')
 
Show_Line_Bear  = input.bool(false, 'Show Bearish SMT Line', inline = 'Bear' , group = 'Display Setting')
Show_Label_Bear = input.bool(true , 'Show Bearish SMT Label' , group = 'Display Setting')
Color_Bear      = input.color(#960303 , '', inline = 'Bear' , group = 'Display Setting')
 
    //Alert
AlertName = input.string('SMT Alerts [TradingFinder]', 'Alert Name', group = 'Alert')
Frequncy = input.string('Once Per Bar' , 'Message Frequency' , ['All', 'Once Per Bar' , 'Per Bar Close'], 'The triggering frequency. Possible values are: All'+ 
 ' (all function calls trigger the alert), Once Per Bar (the first function call during the bar triggers the alert), ' +  
 ' Per Bar Close (the function call triggers the alert only when it occurs during the last script iteration of the real-time bar,' +  
 ' when it closes). The default is alert.freq_once_per_bar.)', group = 'Alert')
UTC = input.string('UTC' , 'Show Alert time by Time Zone', group = 'Alert')
 
Alert_L = input.string('On', 'Bullish SMT Divergence', ['On', 'Off'], 'If you turn on the Alert, you can receive alerts and notifications after setting the "Alert".', group = 'Alert')
Alert_H = input.string('On', 'Bearish SMT Divergence', ['On', 'Off'], 'If you turn on the Alert, you can receive alerts and notifications after setting the "Alert".', group = 'Alert')
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pivot(PP) =>
    var float ph_P = 0.0
    var int   ph_index = 0
    var int   ph_time  = 0
    var float pl_P = 0.0
    var int   pl_index = 0
    var int   pl_time  = 0    
    ph = bool(ta.pivothigh(PP,PP))
    pl = bool(ta.pivotlow(PP,PP))
    if ph
        ph_P := high[PP]
        ph_time  := time[PP]
        ph_index := bar_index[PP]
    if pl
        pl_P := low[PP]
        pl_time  := time[PP]
        pl_index := bar_index[PP]
    [ph, ph_P, ph_index, ph_time, pl, pl_P, pl_index, pl_time]
 
 
SMT(Sym_X, Sym_Y, PP, Threshold, Validity) =>
    bool      Alert_h = false
    bool      Alert_l = false
    var label Label_hx = na ,     var label Label_hy = na
    var label Shape_hx = na ,     var label Shape_hy = na
    var line  Line_hx  = na ,     var line  Line_hy  = na
    var label Label_lx = na ,     var label Label_ly = na
    var label Shape_lx = na ,     var label Shape_ly = na        
    var line  Line_lx  = na ,     var line  Line_ly  = na
 
    var P_phX  = array.new_float()     ,var P_phY  = array.new_float()
    var I_phX  = array.new_int()       ,var I_phY  = array.new_int()
    var T_phX  = array.new_int()       ,var T_phY  = array.new_int()
 
    var P_plX  = array.new_float()     ,var P_plY  = array.new_float()
    var I_plX  = array.new_int()       ,var I_plY  = array.new_int()
    var T_plX  = array.new_int()       ,var T_plY  = array.new_int()
 
    var Pmt_ph = array.new_bool()     ,var Pmt_pl    = array.new_bool()
    
    [o_x, h_x, l_x, c_x, i_x, t_x, atr_x] = request.security(Sym_X, timeframe.period,[open, high, low, close, bar_index, time, ta.atr(200)]) 
    [o_y, h_y, l_y, c_y, i_y, t_y, atr_y] = request.security(Sym_Y, timeframe.period,[open, high, low, close, bar_index, time, ta.atr(200)]) 
    [ph_x, ph_P_x, ph_Ix, ph_Tx, pl_x, pl_P_x, pl_Ix, pl_Tx] = request.security(Sym_X, timeframe.period,pivot(PP)) 
    [ph_y, ph_P_y, ph_Iy, ph_Ty, pl_y, pl_P_y, pl_Iy, pl_Ty] = request.security(Sym_Y, timeframe.period,pivot(PP)) 
    log.info('x: ' + str.tostring(i_x)), log.info('y: ' + str.tostring(i_y))
 
    if (ph_x or ph_y) and (ph_x ? (i_y - ph_Iy - PP <= Threshold) : (i_x - ph_Ix - PP <= Threshold))
        P_phX.push(ph_P_x), I_phX.push(ph_Ix), T_phX.push(ph_Tx) 
        P_phY.push(ph_P_y), I_phY.push(ph_Iy), T_phY.push(ph_Ty) 
        Pmt_ph.push(true) 
    if (pl_x or pl_y) and (pl_x ? (i_y - pl_Iy - PP <= Threshold) : (i_x - pl_Ix - PP <= Threshold))
        P_plX.push(pl_P_x), I_plX.push(pl_Ix), T_plX.push(pl_Tx) 
        P_plY.push(pl_P_y), I_plY.push(pl_Iy), T_plY.push(pl_Ty) 
        Pmt_pl.push(true) 
    
    if barstate.isconfirmed
        if Pmt_ph.size() > 1   
            for l = 1 to (not MxPBack_b ? Pmt_ph.size()  : (Pmt_ph.size() < MxPBack_i ? Pmt_ph.size() : MxPBack_i ) ) by 1 
                if Pmt_ph.get(Pmt_ph.size() - l) and (i_x - I_phX.get(Pmt_ph.size() - l) <= Validity + Threshold)
                    if (P_phX.get(Pmt_ph.size() - l) < h_x ) != (P_phY.get(Pmt_ph.size() - l) < h_y )
                        Pmt_ph.set(Pmt_ph.size() - l, false)
                        Alert_h := true
                        Label_hx := Show_Label_Bear ? label.new(i_x, h_x + atr_x *1.15, 'SMT', color = #ffffff00, textcolor = Color_Bear, style = label.style_label_down  , size = size.small, force_overlay = true) : na
                        Shape_hx := Show_Label_Bear ? label.new(i_x, h_x + atr_x *1.05, ''   , color = Color_Bear  , textcolor = #ffffff00, style = label.style_triangledown, size = size.auto, force_overlay = true) : na
                        Line_hx  := Show_Line_Bear  ? line.new(I_phX.get(Pmt_ph.size() - l), P_phX.get(Pmt_ph.size() - l), i_x, P_phX.get(Pmt_ph.size() - l)  , color = Color_Bear, style = line.style_dotted, force_overlay = true) : na
                        Label_hy := Show_Label_Bear ? label.new(i_y + (i_x - i_y), h_y + atr_y *1.15, 'SMT', color = #ffffff00, textcolor = Color_Bear, style = label.style_label_down  , size = size.small) : na
                        Shape_hy := Show_Label_Bear ? label.new(i_y + (i_x - i_y), h_y + atr_y *1.05, ''   , color = Color_Bear  , textcolor = #ffffff00, style = label.style_triangledown, size = size.auto) : na
                        Line_hy  := Show_Line_Bear  ? line.new(I_phY.get(Pmt_ph.size() - l) + (i_x - i_y), P_phY.get(Pmt_ph.size() - l), i_y + (i_x - i_y), P_phY.get(Pmt_ph.size() - l)  , color = Color_Bear, style = line.style_dotted) : na
 
                    else if (P_phY.get(Pmt_ph.size() - l) < h_y )
                        Pmt_ph.set(Pmt_ph.size() - l, false)
 
        if Pmt_pl.size() > 1
            for l = 1 to (not MxPBack_b ? Pmt_pl.size()  : (Pmt_pl.size() < MxPBack_i ? Pmt_pl.size() : MxPBack_i ) ) by 1 
                if Pmt_pl.get(Pmt_pl.size() - l) and (i_x - I_plX.get(Pmt_pl.size() - l) <= Validity + Threshold)
                    if (P_plX.get(Pmt_pl.size() - l) > l_x ) != (P_plY.get(Pmt_pl.size() - l) > l_y )
                        Pmt_pl.set(Pmt_pl.size() - l, false)
                        Alert_l := true
                        Label_lx := Show_Label_Bull ? label.new(i_x, l_x - atr_x *1.15, 'SMT', color = #ffffff00, textcolor = Color_Bull, style = label.style_label_up  , size = size.small, force_overlay = true) : na
                        Shape_lx := Show_Label_Bull ? label.new(i_x, l_x - atr_x *1.05, ''   , color = Color_Bull  , textcolor = #ffffff00, style = label.style_triangleup, size = size.auto, force_overlay = true) : na
                        Line_lx  := Show_Line_Bull  ? line.new(I_plX.get(Pmt_pl.size() - l), P_plX.get(Pmt_pl.size() - l), i_x, P_plX.get(Pmt_pl.size() - l), color = Color_Bull, style = line.style_dotted, force_overlay = true) : na
                        Label_ly := Show_Label_Bull ? label.new(i_y + (i_x - i_y), l_y - atr_y *1.15, 'SMT', color = #ffffff00, textcolor = Color_Bull, style = label.style_label_up  , size = size.small) : na
                        Shape_ly := Show_Label_Bull ? label.new(i_y + (i_x - i_y), l_y - atr_y *1.05, ''   , color = Color_Bull  , textcolor = #ffffff00, style = label.style_triangleup, size = size.auto) : na
                        Line_ly  := Show_Line_Bull  ? line.new(I_plY.get(Pmt_pl.size() - l) + (i_x - i_y), P_plY.get(Pmt_pl.size() - l), i_y + (i_x - i_y), P_plY.get(Pmt_pl.size() - l), color = Color_Bull, style = line.style_dotted) : na
 
                    else if (P_plY.get(Pmt_pl.size() - l) > l_y )
                        Pmt_pl.set(Pmt_pl.size() - l, false)
    // log.info('Pine Bug Detection Void Function?!')
    [o_y, h_y, l_y, c_y, Alert_h, Alert_l]
 
[o_y, h_y, l_y, c_y, Alert_h, Alert_l] = SMT(syminfo.tickerid, SymY, Period, Threshold, Validity)
plotcandle(o_y, h_y, l_y, c_y, color = c_y >= o_y ? #089981 : #f23645 ,wickcolor = c_y >= o_y ? #089981 : #f23645, bordercolor = c_y >= o_y ? #089981 : #f23645)
AlertSender.AlertSender(Alert_l  , Alert_L, AlertName , 'Analysis', '', 'Basic' ,Frequncy, UTC, 'Off', 'Bullish SMT Divergence in ' + syminfo.ticker + ' & ' + (SymY != '' ? str.split(SymY,':').get(1) : ''), open, high, low, close,0,0,0,0,0)
AlertSender.AlertSender(Alert_h  , Alert_H, AlertName , 'Analysis', '', 'Basic' ,Frequncy, UTC, 'Off', 'Bearish SMT Divergence in ' + syminfo.ticker + ' & ' + (SymY != '' ? str.split(SymY,':').get(1) : ''), open, high, low, close,0,0,0,0,0)

← 返回列表