本页源码来自 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("True Breakout Pattern [TradingFinder] Breakout Signal Indicator", "TBO TFlab", overlay=true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)
// indicator("Fake Breakout Fibo", "Fake Breakout Fibo", overlay = true, max_bars_back = 5000, max_lines_count = 500, max_labels_count = 500)
//Import Library
import TFlab/AlertSenderLibrary_TradingFinder/1 as Alert
//Input
SwingPeriod = input.int(50, 'Swing Period' , minval = 1, group = 'Logical Setting')
ValidAfterTriggerBars = input.int(5, 'Valid After Trigger Bars' , minval = 1, maxval = 10, 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')
BackToBreakPeriod = input.int(4, 'Back to Break-Even Period' , minval = 1, maxval = 5, group = 'Logical Setting')
AShow = input.bool(true, 'Show All TBO',group = 'Display Setting')
HShow = input.bool(true, 'Show High TBO',group = 'Display Setting', inline = 'H')
LShow = input.bool(true, 'Show Low TBO',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 Input
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('TBO [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 TBO' , 'Long Position Message' , group = 'Alert')
MessageBear = input.text_area('Short Signal Position Based on TBO', 'Short Position Message',group = 'Alert')
//SFP Detector Function
SF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack, BackToBreakPeriod, Name, AShow, HShow, LShow, HNColor, LNColor , HLColor, LLColor) => //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 float H_Price_SFP = 0.0
var int H_Index_SFP = 0
var float L_Price_SFP = 0.0
var int L_Index_SFP = 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)
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)
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)
else if ( (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] )
MSH_Permit.set(MSH_P.size() - i , false)
H_Index_SFP := MSH_I.get(MSH_P.size() - i)
H_Price_SFP := 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)
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)
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)
else if ( (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])
MSL_Permit.set(MSL_P.size() - i , false)
L_Index_SFP := MSL_I.get(MSL_P.size() - i)
L_Price_SFP := 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_SFP, H_Price_SFP, nz(LAlert), L_Index_SFP, L_Price_SFP]
[HAlert, H_Index_SFP, H_Price_SFP, LAlert, L_Index_SFP, L_Price_SF] = SF_Detector(SwingPeriod, MaxSwingBack_Method, MaxSwingBack, BackToBreakPeriod, 'M TBO', AShow, HShow, LShow, HNColor, LNColor , HLColor, LLColor)
Fibo(X0, X1) =>
Y_236 = X0 + ((X1 - X0) * 0.236)
Y_382 = X0 + ((X1 - X0) * 0.382)
Y_500 = X0 + ((X1 - X0) * 0.500)
Y_618 = X0 + ((X1 - X0) * 0.618)
Y_786 = X0 + ((X1 - X0) * 0.786)
[Y_236,Y_382,Y_500,Y_618,Y_786]
Drawing(H_Cond, H_Index, H_Price, L_Cond, L_Index, L_Price) =>
var line Bu_0 = na, var line Bu_236 = na, var line Bu_382 = na ,var line Bu_500 = na ,var line Bu_618 = na ,var line Bu_786 = na, var line Bu_1 = na
var line Be_0 = na, var line Be_236 = na, var line Be_382 = na ,var line Be_500 = na ,var line Be_618 = na ,var line Be_786 = na, var line Be_1 = na
var label Bu_L0 = na, var label Bu_L236 = na, var label Bu_L382 = na ,var label Bu_L500 = na ,var label Bu_L618 = na ,var label Bu_L786 = na, var label Bu_L1 = na
var label Be_L0 = na, var label Be_L236 = na, var label Be_L382 = na ,var label Be_L500 = na ,var label Be_L618 = na ,var label Be_L786 = na, var label Be_L1 = na
var float Bull_High = 0.0, var float Bull_Low = 0.0, var float Bear_High = 0.0, var float Bear_Low = 0.0, var int Bull_Bar = 0, var int Bear_Bar = 0
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
var bool Cor_H_Permit = true
var bool Cor_L_Permit = true
var label Bull_Label = na
var label Bear_Label = na
bool Bull_Alert = na
bool Bear_Alert = na
ATR = ta.atr(200)
if H_Cond and H_Permit
H_Permit := false
Bear_High := math.max(high, high[1], high[2], high[3], high[4])
Bear_Low := low
Bear_Bar := time
Bear_High := high > Bear_High ? high : Bear_High
Bear_Bar := high >= Bear_High ? time : Bear_Bar
Bear_Low := low < Bear_Low ? low : Bear_Low
[Bear_236,Bear_382,Bear_500,Bear_618,Bear_786] = Fibo(Bear_Low , Bear_High)
H_Permit := false
Be_0 := line.new(Bear_Bar, Bear_High,time + 4*(time - time[1]) , Bear_High, xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_236 := line.new(Bear_Bar, Bear_236 ,time + 4*(time - time[1]) , Bear_236 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_382 := line.new(Bear_Bar, Bear_382 ,time + 4*(time - time[1]) , Bear_382 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_500 := line.new(Bear_Bar, Bear_500 ,time + 4*(time - time[1]) , Bear_500 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_618 := line.new(Bear_Bar, Bear_618 ,time + 4*(time - time[1]) , Bear_618 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_786 := line.new(Bear_Bar, Bear_786 ,time + 4*(time - time[1]) , Bear_786 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_1 := line.new(Bear_Bar, Bear_Low ,time + 4*(time - time[1]) , Bear_Low , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Be_L0 := label.new(time + 4*(time - time[1]) , Bear_High, '1' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L236 := label.new(time + 4*(time - time[1]) , Bear_236 , '0.236', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L382 := label.new(time + 4*(time - time[1]) , Bear_382 , '0.382', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L500 := label.new(time + 4*(time - time[1]) , Bear_500 , '0.5' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L618 := label.new(time + 4*(time - time[1]) , Bear_618 , '0.618', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L786 := label.new(time + 4*(time - time[1]) , Bear_786 , '0.786', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Be_L1 := label.new(time + 4*(time - time[1]) , Bear_Low , '0' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
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), 'FBO', 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_xcross, size = size.tiny)
if Bear_Bar + (ValidAfterTriggerBars*(time - time[1])) > time and high < Bear_High and Cor_H_Permit
if low < Bear_Low
Bear_Low := low
[Bear_236,Bear_382,Bear_500,Bear_618,Bear_786] = Fibo(Bear_Low , Bear_High)
Be_0.set_y2(Bear_High) , Be_0.set_y1(Bear_High) , Be_L0.set_y(Bear_High)
Be_236.set_y2(Bear_236) , Be_236.set_y1(Bear_236) , Be_L236.set_y(Bear_236)
Be_382.set_y2(Bear_382) , Be_382.set_y1(Bear_382) , Be_L382.set_y(Bear_382)
Be_500.set_y2(Bear_500) , Be_500.set_y1(Bear_500) , Be_L500.set_y(Bear_500)
Be_618.set_y2(Bear_618) , Be_618.set_y1(Bear_618) , Be_L618.set_y(Bear_618)
Be_786.set_y2(Bear_786) , Be_786.set_y1(Bear_786) , Be_L786.set_y(Bear_786)
Be_1.set_y2(Bear_Low) , Be_1.set_y1(Bear_Low) , Be_L1.set_y(Bear_Low)
if high > Bear_618 and high < Bear_High
Cor_H_Permit := false
Bear_Alert := true
Bear_Label := label.new(bar_index, (high + 1.05 * ATR), '', color = HNColor, textcolor = #ffffff00, style = label.style_triangledown, size = size.tiny)
else
Cor_H_Permit := false
Bear_Alert := false
if Bear_Bar[1] != Bear_Bar
Cor_H_Permit := true
if not HAlert
H_Permit := true
if L_Cond and L_Permit
L_Permit := false
Bull_High := high
Bull_Low := math.min(low , low[1] , low[2], low[3], low[4] )
Bull_Bar := time
Bull_High := high > Bull_High ? high : Bull_High
Bull_Low := low < Bull_Low ? low : Bull_Low
Bull_Bar := low <= Bull_Low ? time : Bull_Bar
[Bull_236,Bull_382,Bull_500,Bull_618,Bull_786] = Fibo(Bull_High, Bull_Low)
L_Permit := false
Bu_0 := line.new(Bull_Bar, Bull_High,time+ 3*(time - time[1]) , Bull_High, xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_236 := line.new(Bull_Bar, Bull_236 ,time+ 3*(time - time[1]) , Bull_236 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_382 := line.new(Bull_Bar, Bull_382 ,time+ 3*(time - time[1]) , Bull_382 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_500 := line.new(Bull_Bar, Bull_500 ,time+ 3*(time - time[1]) , Bull_500 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_618 := line.new(Bull_Bar, Bull_618 ,time+ 3*(time - time[1]) , Bull_618 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_786 := line.new(Bull_Bar, Bull_786 ,time+ 3*(time - time[1]) , Bull_786 , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_1 := line.new(Bull_Bar, Bull_Low ,time+ 3*(time - time[1]) , Bull_Low , xloc = xloc.bar_time, style = line.style_dashed, color = color.black)
Bu_L0 := label.new(time+ 3*(time - time[1]) , Bull_High, '0' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L236 := label.new(time+ 3*(time - time[1]) , Bull_236 , '0.236', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L382 := label.new(time+ 3*(time - time[1]) , Bull_382 , '0.382', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L500 := label.new(time+ 3*(time - time[1]) , Bull_500 , '0.5' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L618 := label.new(time+ 3*(time - time[1]) , Bull_618 , '0.618', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L786 := label.new(time+ 3*(time - time[1]) , Bull_786 , '0.786', xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
Bu_L1 := label.new(time+ 3*(time - time[1]) , Bull_Low , '1' , xloc = xloc.bar_time,style = label.style_label_left, color = #ffffff00)
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), 'FBO', 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_xcross, size = size.tiny)
if Bull_Bar + (ValidAfterTriggerBars*(time - time[1])) > time and (low > Bull_Low) and Cor_L_Permit
if high > Bull_High
Bull_High := high
[Bull_236,Bull_382,Bull_500,Bull_618,Bull_786] = Fibo(Bull_High, Bull_Low)
Bu_0.set_y2(Bull_High) , Bu_0.set_y1(Bull_High) , Bu_L0.set_y(Bull_High)
Bu_236.set_y2(Bull_236) , Bu_236.set_y1(Bull_236) , Bu_L236.set_y(Bull_236)
Bu_382.set_y2(Bull_382) , Bu_382.set_y1(Bull_382) , Bu_L382.set_y(Bull_382)
Bu_500.set_y2(Bull_500) , Bu_500.set_y1(Bull_500) , Bu_L500.set_y(Bull_500)
Bu_618.set_y2(Bull_618) , Bu_618.set_y1(Bull_618) , Bu_L618.set_y(Bull_618)
Bu_786.set_y2(Bull_786) , Bu_786.set_y1(Bull_786) , Bu_L786.set_y(Bull_786)
Bu_1.set_y2(Bull_Low) , Bu_1.set_y1(Bull_Low) , Bu_L1.set_y(Bull_Low)
if low < Bull_618 and low > Bull_Low
Cor_L_Permit := false
Bull_Alert := true
Bull_Label := label.new(bar_index, (low - 1.05 * ATR), '', color = LNColor, textcolor = #ffffff00, style = label.style_triangleup, size = size.tiny)
else
Cor_L_Permit := false
Bull_Alert := false
if Bull_Bar[1] != Bull_Bar
Cor_L_Permit := true
if not LAlert
L_Permit := true
[Bull_Alert, Bear_Alert]
[Bull_Alert, Bear_Alert] = Drawing(HAlert, H_Index_SFP, H_Price_SFP, LAlert, L_Index_SFP, L_Price_SF)
Alert.AlertSender(Bull_Alert , Alert, AlertName , 'Analysis', '', 'Basic' ,'Once Per Bar', 'UTC', 'Off', MessageBull, open, high, low, close,0,0,0,0,0)
Alert.AlertSender(Bear_Alert , Alert, AlertName , 'Analysis', '', 'Basic' ,'Once Per Bar', 'UTC', 'Off', MessageBear, open, high, low, close,0,0,0,0,0)