本页源码来自 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=5
indicator("Turtle Soup ICT Strategy [TradingFinder] FVG + CHoCH/CSD", "TFlab Turtle Soup", overlay = true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)
//import Libraries
//import Order Block Refiner
import TFlab/OrderBlockRefiner_TradingFinder/2 as Refiner
//import Order Block Drawing Library
import TFlab/OrderBlockDrawing_TradingFinder/4 as Drawing
//import FVD Detector Library
import TFlab/FVGDetectorLibrary/3 as FVG
//Input
TF = input.timeframe('60', 'Higher TimeFrame Levels', group = 'Logical Setting')
SwingPeriod = input.int(50, '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')
FVG_Length = input.int(120, 'FVG Length' , minval = 1, group = 'Logical Setting')
MSS_Length = input.int(80, 'MSS Length' , minval = 1, group = 'Logical Setting')
//FVG Filter
PFVGFilter = input.bool(false, 'FVG Filter ............', group = 'FVG Logical Setting' , inline = 'FVG Filter')
PFVGFilterType = input.string('Defensive', '', ['Very Aggressive' , 'Aggressive' , 'Defensive' , 'Very Defensive'], group = 'FVG Logical Setting', inline = 'FVG Filter' ,
tooltip = 'If it is "On", this filter will filter "FVGs" based on the width of the Zone.' +
'From "Very Aggressive" to "Very Defensive" the width of the "FVG" decreases.')
MLFVG = input.string('Proximal' , 'Mitigation Level FVG', ['Proximal', '50 % OB', 'Distal'],
tooltip= 'Using this entry, you can determine which level the price reacts to in a FVG.', group = 'FVG Logical Setting')
//Display FVG
DFVGShow = input.bool(true, 'Demand FVG', inline = 'DFVG', group = 'FVG Display Setting')
DFVGColor = input.color(#2195f36c, '', inline = 'DFVG', group = 'FVG Display Setting')
SFVGShow = input.bool(true, 'Supply FVG', inline = 'SFVG', group = 'FVG Display Setting')
SFVGColor = input.color(#ff990070, '', inline = 'SFVG', group = 'FVG Display Setting')
AShow = input.bool(true, 'Show All HTF LvL',group = 'Display Setting')
HShow = input.bool(true, 'Show High HTF LvL',group = 'Display Setting', inline = 'H')
LShow = input.bool(true, 'Show Low HTF LvL',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')
AShow_MSS = input.bool(true, 'Show All MSS',group = 'Display Setting')
HShow_MSS = input.bool(true, 'Show High MSS',group = 'Display Setting', inline = 'HMSS')
LShow_MSS = input.bool(true, 'Show Low MSS',group = 'Display Setting' , inline = 'LMSS')
HNColor_MSS = input.color(#870505 , 'Name',group = 'Display Setting', inline = 'HMSS')
LNColor_MSS = input.color(#014f07 , 'Name',group = 'Display Setting', inline = 'LMSS')
HLColor_MSS = input.color(#b90000b8 , 'Line',group = 'Display Setting', inline = 'HMSS')
LLColor_MSS = input.color(#069206a7 , 'Line',group = 'Display Setting', inline = 'LMSS')
//HTF LvL Detector Function
HTF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack) => //Swing Failure
const int Z = 100000000000000000
var MSH_P = array.new_float()
var MSH_I = array.new_int()
var MSL_P = array.new_float()
var MSL_I = array.new_int()
var MSH_Permit = array.new_bool()
var AOI_MSH = array.new_int()//Another Opportunity Index
var MSL_Permit = array.new_bool()
var AOI_MSL = array.new_int()//Another Opportunity Index
var float Last_MSH_P = 0.0
var int Last_MSH_I = 0
var float Last_MSL_P = 0.0
var int Last_MSL_I = 0
int HSwingBack = 0
int LSwingBack = 0
var bool RealHTFLvL = na
var bool ConsiderableHTFLvL = na
var float H_Price_HTFLvL = 0.0
var int H_Index_HTFLvL = 0
var float L_Price_HTFLvL = 0.0
var int L_Index_HTFLvL = 0
bool HAlert = na
bool LAlert = na
MSH = ta.pivothigh(SwingPeriod , SwingPeriod) // Major Swing High
MSL = ta.pivotlow(SwingPeriod , SwingPeriod) // Major Swing Low
if not (not MSH)
MSH_P.push(high[SwingPeriod])
MSH_I.push(time[SwingPeriod])
MSH_Permit.push(true)
AOI_MSH.push(Z)
if not (not MSL)
MSL_P.push(low[SwingPeriod])
MSL_I.push(time[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_I := MSH_I.get(MSH_I.size() - 1)
if MSL_P.size() > 0
Last_MSL_P := MSL_P.get(MSL_P.size() - 1)
Last_MSL_I := MSL_I.get(MSL_I.size() - 1)
switch MaxSwingBack_Method
'All' => HSwingBack := MSH_P.size() , LSwingBack := MSL_P.size()
'Custom' => HSwingBack := MaxSwingBack , LSwingBack := MaxSwingBack
if MSH_P.size() > (MaxSwingBack_Method == 'All' ? 1 : HSwingBack)
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) )
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) )
MSH_Permit.set(MSH_P.size() - i , false)
H_Index_HTFLvL := MSH_I.get(MSH_P.size() - i)
H_Price_HTFLvL := MSH_P.get(MSH_P.size() - i)
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 MSL_P.size() > (MaxSwingBack_Method == 'All' ? 1 : LSwingBack)
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) )
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))
MSL_Permit.set(MSL_P.size() - i , false)
L_Index_HTFLvL := MSL_I.get(MSL_P.size() - i)
L_Price_HTFLvL := MSL_P.get(MSL_P.size() - i)
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)
[nz(HAlert),H_Index_HTFLvL, H_Price_HTFLvL, nz(LAlert), L_Index_HTFLvL, L_Price_HTFLvL]
[HAlert_o, H_Index_HTFLvL_o, H_Price_HTFLvL_o, LAlert_o, L_Index_HTFLvL_o, L_Price_HTFLvL_o] =
request.security(syminfo.tickerid, TF , HTF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack), gaps = barmerge.gaps_on)
var bool HAlert = na
var int H_Index_HTFLvL = na
var float H_Price_HTFLvL = na
var bool LAlert = na
var int L_Index_HTFLvL = na
var float L_Price_HTFLvL = na
if HAlert_o
HAlert := true
H_Index_HTFLvL := H_Index_HTFLvL_o
H_Price_HTFLvL := H_Price_HTFLvL_o
else
HAlert := false
if LAlert_o
LAlert := true
L_Index_HTFLvL := L_Index_HTFLvL_o
L_Price_HTFLvL := L_Price_HTFLvL_o
else
LAlert := false
Drawing(H_Cond, H_Index, H_Price, L_Cond, L_Index, L_Price) =>
var line MSH_Line = na
var label MSH_Label = na
var label MSH_Shap = na
var line MSL_Line = na
var label MSL_Label = na
var label MSL_Shap = na
var bool H_Permit = true
var bool L_Permit = true
ATR = ta.atr(200)
if H_Cond and H_Permit
H_Permit := false
if AShow
if HShow
MSH_Line := line.new(H_Index, H_Price, time, H_Price, color = HLColor , style = line.style_dashed , xloc = xloc.bar_time)
MSH_Label := label.new(bar_index, (high + 1.15 * ATR), 'HTF Liquidity Sweep', 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)
if not HAlert
H_Permit := true
if L_Cond and L_Permit
L_Permit := false
if AShow
if LShow
MSL_Line := line.new(L_Index, L_Price, time, L_Price, color = LLColor , style = line.style_dashed , xloc = xloc.bar_time)
MSL_Label := label.new(bar_index, (low - 1.15 * ATR), 'HTF Liquidity Sweep', 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)
if not LAlert
L_Permit := true
// Drawing Higher TimeFrame Hunt
Drawing(HAlert, H_Index_HTFLvL, H_Price_HTFLvL, LAlert, L_Index_HTFLvL, L_Price_HTFLvL)
//MSS Detector Function
MSSLevelDetector(CondHigh, CondLow,DConditionFVG, DDFVG, DPFVG, BarDFVG, SConditionFVG, SDFVG, SPFVG, BarSFVG, Label ) =>
ATR = ta.atr(55)
Body = close - open
var float MSSLvLP_L = 0.0
var float MSSLvLP_H = 0.0
var int MSSLvLI_L = 0
var int MSSLvLI_H = 0
var bool Permit_HSet = true
var bool Permit_LSet = true
var bool Permit_HReset = true
var bool Permit_LReset = true
var line MSS_LineL = na
var line MSS_LineH = na
var label MSS_NameH = na
var label MSS_NameL = na
var label MSS_ShapH = na
var label MSS_ShapL = na
var bool Bear_Trigger = false
var bool Bull_Trigger = false
var int Bear_FVG = 0
var float Bear_FVG_D = 0.0
var float Bear_FVG_P = 0.0
var int Bull_FVG = 0
var float Bull_FVG_D = 0.0
var float Bull_FVG_P = 0.0
var bool FVG_Bear_Trigger = false
var bool FVG_Bull_Trigger = false
var FVG_Bear_D = array.new_float()
var FVG_Bear_P = array.new_float()
var FVG_Bear_I = array.new_int()
var FVG_Bull_D = array.new_float()
var FVG_Bull_P = array.new_float()
var FVG_Bull_I = array.new_int()
var float H_P = 0.0
var int H_I = 0
var float L_P = 0.0
var int L_I = 0
// MSS Level
if bool(ta.pivothigh(2 , 1))
H_P := high[1]
H_I := bar_index[1]
if bool(ta.pivotlow(2 , 1))
L_P := low[1]
L_I := bar_index[1]
if CondHigh
Permit_HSet := true
if Permit_HSet and H_Index_HTFLvL != H_Index_HTFLvL[1]
Permit_HReset := true
MSSLvLP_H := L_P
MSSLvLI_H := L_I
if AShow_MSS and HShow_MSS
MSS_LineH := line.new(MSSLvLI_H, MSSLvLP_H, bar_index , MSSLvLP_H , color = HLColor_MSS, style = line.style_dotted)
MSS_NameH := label.new(MSSLvLI_H + 1 , low[bar_index - MSSLvLI_H] - (ATR * 0.3) , Label, color = na, style = label.style_label_upper_left , textcolor = HNColor_MSS, size = size.small)
Permit_HSet := false
if Permit_HReset[0]
if SConditionFVG[0]
FVG_Bear_I.push(BarSFVG)
FVG_Bear_D.push(SDFVG)
FVG_Bear_P.push(SPFVG)
if FVG_Bear_I.size() > 0
if high > FVG_Bear_D.get(FVG_Bear_I.size() - 1)
FVG_Bear_I.remove(FVG_Bear_I.size() - 1)
FVG_Bear_D.remove(FVG_Bear_D.size() - 1)
FVG_Bear_P.remove(FVG_Bear_P.size() - 1)
if close[1] >= MSSLvLP_H and (bar_index[1] - MSSLvLI_H) <= MSS_Length
MSS_LineH.set_x2(bar_index + 1)
if close[1] <= MSSLvLP_H and (bar_index[1] - MSSLvLI_H) <= MSS_Length
Permit_HReset := false
if AShow_MSS and HShow_MSS
MSS_ShapH := label.new(bar_index , high + (ATR * 0.6), "", color = HNColor_MSS, style = label.style_triangledown , size = size.tiny)
if CondLow
Permit_LSet := true
if Permit_LSet and L_Index_HTFLvL != L_Index_HTFLvL[1]
Permit_LReset := true
MSSLvLP_L := H_P
MSSLvLI_L := H_I
if AShow_MSS and LShow_MSS
MSS_LineL := line.new(MSSLvLI_L, MSSLvLP_L, bar_index , MSSLvLP_L, color = LLColor_MSS, style = line.style_dotted)
MSS_NameL := label.new(MSSLvLI_L + 1 , high[bar_index - MSSLvLI_L] + (ATR * 0.6) , Label, color = na, style = label.style_label_lower_right , textcolor = LNColor_MSS , size = size.small)
Permit_LSet := false
if Permit_LReset[0]
if DConditionFVG[0]
FVG_Bull_I.push(BarDFVG)
FVG_Bull_D.push(DDFVG)
FVG_Bull_P.push(DPFVG)
if FVG_Bull_I.size() > 0
if low < FVG_Bull_D.get(FVG_Bull_I.size() - 1)
FVG_Bull_I.remove(FVG_Bull_I.size() - 1)
FVG_Bull_D.remove(FVG_Bull_D.size() - 1)
FVG_Bull_P.remove(FVG_Bull_P.size() - 1)
if close[0] <= MSSLvLP_L and (bar_index[0] - MSSLvLI_L) <= MSS_Length
MSS_LineL.set_x2(bar_index + 1)
if close[0] >= MSSLvLP_L and (bar_index[0] - MSSLvLI_L) <= MSS_Length
Permit_LReset := false
if AShow_MSS and LShow_MSS
MSS_ShapL := label.new(bar_index , low - (ATR * 0.6), "", color = LNColor_MSS, style = label.style_triangleup , size = size.tiny)
//Set FVG
if FVG_Bull_I.size() > 0 or (ta.change(FVG_Bull_I.size() > 0) and FVG_Bull_I.size() > 0)
Bull_FVG := FVG_Bull_I.get(FVG_Bull_I.size() - 1)
Bull_FVG_D := FVG_Bull_D.get(FVG_Bull_D.size() - 1)
Bull_FVG_P:= FVG_Bull_P.get(FVG_Bull_P.size() - 1)
if FVG_Bear_I.size() > 0 or (ta.change(FVG_Bear_I.size() > 0) and FVG_Bear_I.size() > 0)
Bear_FVG := FVG_Bear_I.get(FVG_Bear_I.size() - 1)
Bear_FVG_D := FVG_Bear_D.get(FVG_Bear_D.size() - 1)
Bear_FVG_P := FVG_Bear_P.get(FVG_Bear_P.size() - 1)
if Permit_HReset[1] and Permit_HReset == false
Bear_Trigger := true
if FVG_Bear_I.size() > 0 and Bear_FVG != 0
FVG_Bear_Trigger := true
else
FVG_Bear_Trigger := false
else
Bear_Trigger := false
FVG_Bear_Trigger := false
if Permit_LReset[1] and Permit_LReset == false
Bull_Trigger := true
if FVG_Bull_I.size() > 0 and Bull_FVG != 0
FVG_Bull_Trigger := true
else
FVG_Bull_Trigger := false
else
Bull_Trigger := false
FVG_Bull_Trigger := false
//Reset FVG
if HAlert
Bear_FVG := 0
Bear_FVG_D := 0.0
Bear_FVG_P := 0.0
FVG_Bear_D.clear()
FVG_Bear_P.clear()
FVG_Bear_I.clear()
if LAlert
FVG_Bull_D.clear()
FVG_Bull_P.clear()
FVG_Bull_I.clear()
Bull_FVG := 0
Bull_FVG_D := 0.0
Bull_FVG_P := 0.0
[Bull_Trigger, Bear_Trigger,FVG_Bull_Trigger, FVG_Bear_Trigger, Bull_FVG, Bear_FVG, Bull_FVG_D, Bear_FVG_D,Bull_FVG_P, Bear_FVG_P]
//FVG Call Function
[DConditionFVG, DDFVG, DPFVG, BarDFVG, SConditionFVG, SDFVG, SPFVG, BarSFVG] = FVG.FVGDetector(PFVGFilter ? 'On' : 'Off', PFVGFilterType, false, false)
//Call MSS Function
[Bull_Trigger, Bear_Trigger,FVG_Bull_Trigger, FVG_Bear_Trigger, Bull_FVG, Bear_FVG, Bull_FVG_D, Bear_FVG_D,Bull_FVG_P, Bear_FVG_P ] =
MSSLevelDetector(HAlert,LAlert ,DConditionFVG, DDFVG, DPFVG, BarDFVG, SConditionFVG, SDFVG, SPFVG, BarSFVG,'MSS')
if bar_index - Bull_FVG < 500
Drawing.OBDrawing('Demand', FVG_Bull_Trigger , Bull_FVG_D , Bull_FVG_P , Bull_FVG ,true , FVG_Length ,MLFVG ,MLFVG , true ,false ,DFVGShow, false,DFVGColor, #ffffff00) //Bull_FVG
if bar_index - Bear_FVG < 500
Drawing.OBDrawing('Supply', FVG_Bear_Trigger , Bear_FVG_D , Bear_FVG_P , Bear_FVG ,true , FVG_Length ,MLFVG ,MLFVG , true ,false ,SFVGShow, false,SFVGColor, #ffffff00) // Bear_FVG