本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// 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("ICT Setup 04 [TradingFinder] SFP Sweep Liquidity Fake CHoCH/BOS", "TFlab SLF", overlay=true) // , calc_on_every_tick = true, process_orders_on_close = false
//Import Library
import TFlab/AlertSenderLibrary_TradingFinder/1 as Alert
//Input
//Logical
SwingPeriod = input.int(21, 'Swing Period' , minval = 1, group = 'Logical Setting')
MaxSwingBack_Method = input.string('All', 'Max Swing Back Method' , ['All', 'Custom'], group = 'Logical Setting')
MaxSwingBack = input.int(100, 'Max Swing Back' , minval = 1, group = 'Logical Setting')
MaxSwingSignal = input.int(50, 'Maximum Distance Between Swing and Signal' , minval = 1, group = 'Logical Setting')
//Display
AShow = input.bool(true, 'Show All SLF',group = 'Display Setting')
HShow = input.bool(true, 'Show High SLF',group = 'Display Setting', inline = 'H')
LShow = input.bool(true, 'Show Low SLF',group = 'Display Setting' , inline = 'L')
HNColor = input.color(#870505 , 'Name',group = 'Display Setting', inline = 'H')
LNColor = input.color(#014f07 , 'Name',group = 'Display Setting', inline = 'L')
HLColor = input.color(#b90000b8 , 'Line',group = 'Display Setting', inline = 'H')
LLColor = input.color(#069206a7 , 'Line',group = 'Display Setting', inline = 'L')
//Alert
Alert = input.string('On', 'Alert', ['On', 'Off'], 'If you turn on the Alert, you can receive alerts and notifications after setting the "Alert".', group = 'Alert')
AlertName = input.string('SLF [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')
MessageBull = input.text_area('Long Signal Position Based on SLF' , 'Long Position Message' , group = 'Alert')
MessageBear = input.text_area('Short Signal Position Based on SLF', 'Short Position Message',group = 'Alert')
//SLF Detector Function
SF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack, SLFType, BackToBreakPeriod, Name, AShow, HShow, LShow, HNColor, LNColor , HLColor, LLColor) => //Swing Failure
ATR = ta.atr(55)
const int Z = 100000000000000000
var MSH_P = array.new_float()
var MSH_C = array.new_float()
var MSH_O = array.new_float()
var MSH_T = array.new_int()
var MSH_I = array.new_int()
var MSL_P = array.new_float()
var MSL_C = array.new_float()
var MSL_O = array.new_float()
var MSL_T = array.new_int()
var MSL_I = array.new_int()
var line MSH_Line = na
var MSH_Permit = array.new_bool()
var AOI_MSH = array.new_int()//Another Opportunity Index
var line MSL_Line = na
var MSL_Permit = array.new_bool()
var AOI_MSL = array.new_int()//Another Opportunity Index
var label MSH_Label = na
var label MSL_Label = na
var label MSH_Shap = na
var label MSL_Shap = na
var float Last_MSH_P = 0.0
var int Last_MSH_T = 0
var float Last_MSL_P = 0.0
var int Last_MSL_T = 0
var float MSH_Distal = 0.0
var float MSH_Proximal = 0.0
var float MSL_Distal = 0.0
var float MSL_Proximal = 0.0
int HSwingBack = 0
int LSwingBack = 0
var bool RealSLF = false
var bool ConsiderableSLF = false
bool HAlert = false
bool LAlert = false
Doji = math.abs(open - close) / (high - low) <= 0.4
Type = close >= open ? 'Bull' : 'Bear'
MSH = ta.pivothigh(SwingPeriod , SwingPeriod) // Major Swing High
MSL = ta.pivotlow(SwingPeriod , SwingPeriod) // Major Swing Low
if not (not bool(MSH))
MSH_P.push(high[SwingPeriod])
MSH_C.push(close[SwingPeriod])
MSH_O.push(open[SwingPeriod])
MSH_T.push(time[SwingPeriod])
MSH_I.push(bar_index[SwingPeriod])
MSH_Permit.push(true)
AOI_MSH.push(Z)
if not (not bool( MSL))
MSL_P.push(low[SwingPeriod])
MSL_C.push(close[SwingPeriod])
MSL_O.push(open[SwingPeriod])
MSL_T.push(time[SwingPeriod])
MSL_I.push(bar_index[SwingPeriod])
MSL_Permit.push(true)
AOI_MSL.push(Z)
if MSH_P.size() > 0
Last_MSH_P := MSH_P.get(MSH_P.size() - 1)
Last_MSH_T := MSH_T.get(MSH_T.size() - 1)
if MSL_P.size() > 0
Last_MSL_P := MSL_P.get(MSL_P.size() - 1)
Last_MSL_T := MSL_T.get(MSL_T.size() - 1)
switch MaxSwingBack_Method
'All' => HSwingBack := MSH_P.size() , LSwingBack := MSL_P.size()
'Custom' => HSwingBack := MaxSwingBack , LSwingBack := MaxSwingBack
RealSLF := true , ConsiderableSLF := false
if AShow
if HShow
if MSH_P.size() > (MaxSwingBack_Method == 'All' ? 1 : HSwingBack)
if bar_index > bar_index[1]
for i = 1 to HSwingBack by 1
if MSH_Permit.get(MSH_P.size() - i)
if (bar_index <= AOI_MSH.get(AOI_MSH.size() - i) + BackToBreakPeriod) and bar_index - MSH_I.get(MSH_P.size() - i) < 50
if (MSH_P.get(MSH_P.size() - i) < high and MSH_P.get(MSH_P.size() - i) > close and (AOI_MSH.get(AOI_MSH.size() - i) == Z) and RealSLF )
or ( (MSH_P.get(MSH_P.size() - i) > close and (MSH_P.get(MSH_P.size() - i) < close[1]))
and close < open[1] and low < low[1] and ConsiderableSLF)
MSH_Permit.set(MSH_P.size() - i , false)
if Doji and barstate.isconfirmed and
(close < MSH_P.get(MSH_P.size() - i) and close > math.max(MSH_C.get(MSH_P.size() - i), MSH_O.get(MSH_P.size() - i)))
MSH_Distal := MSH_P.get(MSH_P.size() - i)
MSH_Proximal := math.max(MSH_C.get(MSH_P.size() - i), MSH_O.get(MSH_P.size() - i))
MSH_Line := line.new(MSH_T.get(MSH_P.size() - i), MSH_P.get(MSH_P.size() - i), time, MSH_P.get(MSH_P.size() - i), color = HLColor , style = line.style_dotted , xloc = xloc.bar_time)
MSH_Line := line.new(MSH_T.get(MSH_P.size() - i), math.max(MSH_C.get(MSH_P.size() - i), MSH_O.get(MSH_P.size() - i)), time, math.max(MSH_C.get(MSH_P.size() - i), MSH_O.get(MSH_P.size() - i)), color = HLColor , style = line.style_dotted , xloc = xloc.bar_time)
MSH_Label := label.new(bar_index, (high + 1.15 * ATR), Name, color = #ffffff00, textcolor = HNColor, style = label.style_label_down, size = size.small)
MSH_Shap := label.new(bar_index, (high + 1.05 * ATR), '', color = HNColor, textcolor = #ffffff00, style = label.style_triangledown, size = size.tiny)
HAlert := true
if ((MSH_P.get(MSH_P.size() - i) < close) and (AOI_MSH.get(AOI_MSH.size() - i) == Z))
AOI_MSH.set(AOI_MSH.size() - i, bar_index)
if LShow
if MSL_P.size() > (MaxSwingBack_Method == 'All' ? 1 : LSwingBack)
if bar_index > bar_index[1]
for i = 1 to LSwingBack by 1
if MSL_Permit.get(MSL_P.size() - i)
if (bar_index <= AOI_MSL.get(AOI_MSL.size() - i) + BackToBreakPeriod) and bar_index - MSL_I.get(MSL_P.size() - i) < 50
if (MSL_P.get(MSL_P.size() - i) > low and MSL_P.get(MSL_P.size() - i) < close and (AOI_MSL.get(AOI_MSL.size() - i) == Z) and RealSLF )
or ( (MSL_P.get(MSL_P.size() - i) < close and MSL_P.get(MSL_P.size() - i) > close[1])
and close > open[1] and high > high[1] and ConsiderableSLF)
MSL_Permit.set(MSL_P.size() - i , false)
if Doji and barstate.isconfirmed and
(close > MSL_P.get(MSL_P.size() - i) and close < math.min(MSL_C.get(MSL_P.size() - i), MSL_O.get(MSL_P.size() - i)))
MSL_Distal := MSL_P.get(MSL_P.size() - i)
MSL_Proximal := math.min(MSL_C.get(MSL_P.size() - i), MSL_O.get(MSL_P.size() - i))
MSL_Line := line.new(MSL_T.get(MSL_P.size() - i), MSL_P.get(MSL_P.size() - i), time, MSL_P.get(MSL_P.size() - i), color = LLColor , style = line.style_dotted , xloc = xloc.bar_time)
MSL_Line := line.new(MSL_T.get(MSL_P.size() - i), math.min(MSL_C.get(MSL_P.size() - i), MSL_O.get(MSL_P.size() - i)), time, math.min(MSL_C.get(MSL_P.size() - i), MSL_O.get(MSL_P.size() - i)), color = LLColor , style = line.style_dotted , xloc = xloc.bar_time)
MSL_Label := label.new(bar_index, (low - 1.15 * ATR), Name, color = #ffffff00, textcolor = LNColor, style = label.style_label_up, size = size.small)
MSL_Shap := label.new(bar_index, (low - 1.05 * ATR), '', color = LNColor, textcolor = #ffffff00, style = label.style_triangleup, size = size.tiny)
LAlert := true
if ((MSL_P.get(MSL_P.size() - i) > close) and (AOI_MSL.get(AOI_MSL.size() - i) == Z))
AOI_MSL.set(AOI_MSL.size() - i, bar_index)
[HAlert, LAlert]
[HAlert, LAlert] = SF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack, 'All', 0, 'Sweep', AShow, HShow, LShow, HNColor, LNColor , HLColor, LLColor)
Alert.AlertSender(LAlert , Alert, AlertName , 'Analysis', '', 'Basic' ,'Once Per Bar', 'UTC', 'Off', MessageBull, open, high, low, close,0,0,0,0,0)
Alert.AlertSender(HAlert , Alert, AlertName , 'Analysis', '', 'Basic' ,'Once Per Bar', 'UTC', 'Off', MessageBear, open, high, low, close,0,0,0,0,0)