0% found this document useful (1 vote)
378 views26 pages

Simple System by LEO 2@free - FX - Pro

Pinescript

Uploaded by

warumonokisou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
378 views26 pages

Simple System by LEO 2@free - FX - Pro

Pinescript

Uploaded by

warumonokisou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
  • Overview and Setup
  • Inputs and Basic Functions
  • Algorithm Details and Implementation
  • Additional Features and Configurations
  • Advanced Error Handling and Cleanup

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at [Link]
// © leandrolopezf1920

//@version=5
indicator("Simple System by LEO 2", overlay = true, max_lines_count = 500,
max_labels_count = 500, max_boxes_count = 500, max_bars_back = 1000)
//------------------------------------------------------------------------------
// === Range Detector ===
//------------------------------------------------------------------------------

length3 = [Link](20, 'Minimum Range Length', minval = 2)


mult = [Link](1., 'Range Width', minval = 0, step = 0.1)
atrLen = [Link](500, 'ATR Length', minval = 1)

//Style
upCss = input(#089981, 'Broken Upward', group = 'Style')
dnCss = input(#f23645, 'Broken Downward', group = 'Style')
unbrokenCss = input(#2157f3, 'Unbroken', group = 'Style')

//-----------------------------------------------------------------------------}
//Detect and highlight ranges
//-----------------------------------------------------------------------------{
//Ranges drawings
var box bx = na
var line lvl = na

//Extensions
var float max2 = na
var float min2 = na

var os = 0
color detect_css = na

atr = [Link](atrLen) * mult


ma = [Link](close, length3)
n = bar_index
count = 0
for i = 0 to length3-1
count += [Link](close[i] - ma) > atr ? 1 : 0

if count == 0 and count[1] != count


//Test for overlap and change coordinates
if n[length3] <= bx.get_right()
max2 := [Link](ma + atr, bx.get_top())
min2 := [Link](ma - atr, bx.get_bottom())

//Box new coordinates


bx.set_top(max2)
bx.set_rightbottom(n, min2)
bx.set_bgcolor([Link](unbrokenCss, 80))

//Line new coordinates


avg = [Link](max2, min2)
lvl.set_y1(avg)
lvl.set_xy2(n, avg)
lvl.set_color(unbrokenCss)
else
max2 := ma + atr
min2 := ma - atr

//Set new box and level


bx := [Link](n[length3], ma + atr, n, ma - atr, na
, bgcolor = [Link](unbrokenCss, 100))

lvl := [Link](n[length3], ma, n, ma


, color = unbrokenCss
, style = line.style_dotted)

detect_css := [Link](#787b86, 80)


os := 0

else if count == 0
bx.set_right(n)
lvl.set_x2(n)

//Set color
if close > bx.get_top()
bx.set_bgcolor([Link](#ff5252, 100))
lvl.set_color(upCss)
os := 1
else if close < bx.get_bottom()
bx.set_bgcolor([Link](#ff5252, 100))
lvl.set_color(dnCss)
os := -1

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Range detection bgcolor
bgcolor(detect_css)

plot(max2, 'Range Top'


, max2 != max2[1] ? na : os == 0 ? unbrokenCss : os == 1 ? upCss : dnCss)

plot(min2, 'Range Bottom'


, min2 != min2[1] ? na : os == 0 ? unbrokenCss : os == 1 ? upCss : dnCss)

//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}

//INPUTS
cooldownPeriod = [Link](10,title="Cooldown Period", minval=0, group =
"Settings")

lbLeft = 20
lbRight = 20

showSwing = [Link](true,title="Show Swings?", inline="s_1", group = 'Swing


Detaction')
swingClr = [Link]([Link]([Link], 0), title='', inline="s_1", group =
'Swing Detaction')

bullWidth = [Link](1, title='Line Width:', group='Bullish Sweep')


bullStyle = [Link]('Dashed', title='Line Style:', options=['Solid', 'Dotted',
'Dashed'], group='Bullish Sweep')
bullColor = [Link]([Link]([Link], 0), title='Bullish Color:',
group='Bullish Sweep')
bearWidth = [Link](1, title='Line Width:', group='Bearish Sweep')
bearStyle = [Link]('Dashed', title='Line Style:', options=['Solid', 'Dotted',
'Dashed'], group='Bearish Sweep')
bearColor = [Link]([Link]([Link], 0), title='Bearish Color:',
group='Bearish Sweep')

//FUNCTIONS
lineStyle(s) =>
if s == 'Solid'
line.style_solid
else if s == 'Dotted'
line.style_dotted
else
line.style_dashed

//VARS
var int bullSignalIndex = 0
var int bearSignalIndex = 0

var line bullLine = na


var line bearLine = na

var line highLine = na


var line lowLine = na

var label swingHighLbl = na


var label swingLowLbl = na
var label swingHighLblTxt = na
var label swingLowLblTxt = na

var float swingLowVal = na


var float swingHighVal = na

//CALCULATIONS
pLow = [Link](low, lbLeft, lbRight)
pHigh = [Link](high, lbLeft, lbRight)

pLowVal = [Link](not na(pLow), low[lbRight], 0)


pHighVal = [Link](not na(pHigh), high[lbRight], 0)

prevLowIndex = [Link](not na(pLow), bar_index[lbRight], 0)


prevHighIndex = [Link](not na(pHigh), bar_index[lbRight], 0)

lp = [Link](low, lbLeft)
hp = [Link](high, lbLeft)

highestClose = [Link](close, lbLeft)


lowestClose = [Link](close, lbLeft)

bullishSFP = low < pLowVal and close > pLowVal and open > pLowVal and low == lp and
lowestClose >= pLowVal
bearishSFP = high > pHighVal and close < pHighVal and open < pHighVal and high ==
hp and highestClose <= pHighVal

bullCond = bullishSFP[3] and (close > pLowVal) and (close[1] > pLowVal[1]) and
(close[2] > pLowVal[2]) and bar_index >= bullSignalIndex + cooldownPeriod
bearCond = bearishSFP[3] and (close < pHighVal) and (close[1] < pHighVal[1]) and
(close[2] < pHighVal[2]) and bar_index >= bearSignalIndex + cooldownPeriod
//Check Swing H/L Stopper
var int swingLowCounter = 0
var int swingHighCounter = 0
var bool isSwingLowCheck = false
var bool isSwingHighCheck = false
var bool stopPrintingLow = false
var bool stopPrintingHigh = false

if high < swingLowVal and isSwingLowCheck


swingLowCounter := swingLowCounter+1

if low > swingHighVal and isSwingHighCheck


swingHighCounter := swingHighCounter+1

if [Link](close, swingLowVal) and isSwingLowCheck == false


isSwingLowCheck := true
swingLowCounter := 1

if [Link](close, swingHighVal) and isSwingHighCheck == false


isSwingHighCheck := true
swingHighCounter := 1

if swingLowCounter == 5 and isSwingLowCheck


stopPrintingLow := true
isSwingLowCheck := false
line.set_x2(lowLine,bar_index[4])

if swingHighCounter == 5 and isSwingHighCheck


stopPrintingHigh := true
isSwingHighCheck := false
line.set_x2(highLine,bar_index[4])

//Draw sweep lines


if bullCond
bullSignalIndex := bar_index
bullLine := [Link](prevLowIndex, pLowVal, bar_index-3, pLowVal,
color=bullColor, width=bullWidth, style=lineStyle(bullStyle))

if bearCond
bearSignalIndex := bar_index
bearLine := [Link](prevHighIndex, pHighVal, bar_index-3, pHighVal,
color=bearColor, width=bearWidth, style=lineStyle(bearStyle))

var swingHighArr = array.new_label(0)


var swingHighTextArr = array.new_label(0)

var swingLowArr = array.new_label(0)


var swingLowTextArr = array.new_label(0)

if [Link](swingHighArr) >= 3
[Link]([Link](swingHighArr))
[Link]([Link](swingHighTextArr))

if [Link](swingLowArr) >= 3
[Link]([Link](swingLowArr))
[Link]([Link](swingLowTextArr))

//Draw range lines


if showSwing
if stopPrintingHigh == false
line.set_x2(highLine,bar_index+5)
if stopPrintingLow == false
line.set_x2(lowLine,bar_index+5)

if showSwing and not na(pHigh) and bearishSFP[lbRight] == false


stopPrintingHigh := false
swingHighVal := high[lbRight]
[Link](highLine)
highLine := [Link](bar_index[lbRight], high[lbRight], bar_index+10,
high[lbRight], color = swingClr, width = 2)

swingHighLbl := [Link](bar_index[lbRight], high[lbRight], text="",


yloc=[Link], color = swingClr, textcolor = swingClr, style =
label.style_triangledown, size = [Link])
swingHighLblTxt := [Link](bar_index[lbRight], high[lbRight], text="Swing\
nH", yloc=[Link], color = swingClr, textcolor = swingClr, style =
label.style_none, size = [Link])
[Link](swingHighArr, swingHighLbl)
[Link](swingHighTextArr, swingHighLblTxt)

if showSwing and not na(pLow) and bullishSFP[lbRight] == false


stopPrintingLow := false
swingLowVal := low[lbRight]
[Link](lowLine)
lowLine := [Link](bar_index[lbRight], low[lbRight], bar_index+10,
low[lbRight], color = swingClr, width = 2)

swingLowLbl := [Link](bar_index[lbRight], low[lbRight], text="",


yloc=[Link], color = swingClr, textcolor = swingClr, style =
label.style_triangleup, size = [Link])
swingLowLblTxt := [Link](bar_index[lbRight], low[lbRight], text="Swing\nL",
yloc=[Link], color = swingClr, textcolor = swingClr, style =
label.style_none, size = [Link])
[Link](swingLowArr, swingLowLbl)
[Link](swingLowTextArr, swingLowLblTxt)

//PLOTS
plotshape(bullCond, text='Sweep', color=bullColor, textcolor=bullColor,
location=[Link], offset = -3)
plotshape(bearCond, text='Sweep', color=bearColor, textcolor=bearColor,
location=[Link], offset = -3)

//ALERTS
alertcondition(bullishSFP, title='Bullish Sweep', message='{{ticker}} Bullish
Sweep, Price:{{close}}')
alertcondition(bearishSFP, title='Bearish Sweep', message='{{ticker}} Bearish
Sweep, Price:{{close}}')

//------------------------------------------------------------------------------
// === Zig Zag Channels ===
//------------------------------------------------------------------------------

length1 = input(100)
extend = input(true,'Extend To Last Bar')
show_ext = input(true,'Show Extremities')
show_labels = input(true,'Show Labels')
//Style

upcol = input(#ff1100,'Upper Extremity Color',group='Style')


midcol = input(#ff5d00,'Zig Zag Color',group='Style')
dncol = input(#2157f3,'Lower Extremity Color',group='Style')
//------------------------------------------------------------------------------
os1 = 0
src1 = close
var float valtop = na
var float valbtm = na

//------------------------------------------------------------------------------
upper = [Link](src1,length1)
lower = [Link](src1,length1)
os1 := src1[length1] > upper ? 0 : src1[length1] < lower ? 1 : os1[1]

btm = os1 == 1 and os1[1] != 1


top = os1 == 0 and os1[1] != 0

//------------------------------------------------------------------------------
btm_n = [Link](btm,n,0)
top_n = [Link](top,n,0)
len = [Link](btm_n - top_n)

if btm
max_diff_up = 0.
max_diff_dn = 0.
valbtm := low[length1]

for i = 0 to len-1
point = low[length1] + i/(len-1)*(valtop - low[length1])
max_diff_up := [Link]([Link](src1[length1+i],open[length1+i]) -
point,max_diff_up)
max_diff_dn := [Link](point -
[Link](src1[length1+i],open[length1+i]),max_diff_dn)

[Link](n[len+length1],valtop,n[length1],low[length1],color=midcol)

if show_ext

[Link](n[len+length1],valtop+max_diff_up,n[length1],low[length1]+max_diff_up
,color=upcol,style=line.style_dotted)
[Link](n[len+length1],valtop-max_diff_dn,n[length1],low[length1]-
max_diff_dn
,color=dncol,style=line.style_dotted)
if show_labels

[Link](n[length1],low[length1],[Link](low[length1],'#.####'),color=#000000
00
,style=label.style_label_up,textcolor=dncol,textalign=text.align_left,siz
e=[Link])

if top
max_diff_up = 0.
max_diff_dn = 0.
valtop := high[length1]

for i = 0 to len-1
point = high[length1] + i/(len-1)*(valbtm - high[length1])
max_diff_up := [Link]([Link](src1[length1+i],open[length1+i]) -
point,max_diff_up)
max_diff_dn := [Link](point -
[Link](src1[length1+i],open[length1+i]),max_diff_dn)

[Link](n[len+length1],valbtm,n[length1],high[length1],color=midcol)

if show_ext

[Link](n[len+length1],valbtm+max_diff_up,n[length1],high[length1]+max_diff_up
,color=upcol,style=line.style_dotted)
[Link](n[len+length1],valbtm-max_diff_dn,n[length1],high[length1]-
max_diff_dn
,color=dncol,style=line.style_dotted)
if show_labels

[Link](n[length1],high[length1],[Link](high[length1],'#.####'),color=#0000
0000
,style=label.style_label_down,textcolor=upcol,textalign=text.align_left,s
ize=[Link])

if [Link] and extend


max_diff_up = 0.
max_diff_dn = 0.
x1 = 0
y1 = 0.

if os1 == 1
x1 := btm_n-length1
y1 := valbtm

for i = 0 to n-btm_n+length1-1
point = src1 + i/(n-btm_n+length1-1)*(valbtm - src1)
max_diff_up := [Link]([Link](src1[i],open[i]) - point,max_diff_up)
max_diff_dn := [Link](point - [Link](src1[i],open[i]),max_diff_dn)

else
x1 := top_n-length1
y1 := valtop

for i = 0 to n-top_n+length1-1
point = src1 + i/(n-top_n+length1-1)*(valtop - src1)
max_diff_up := [Link]([Link](src1[i],open[i]) - point,max_diff_up)
max_diff_dn := [Link](point - [Link](src1[i],open[i]),max_diff_dn)

[Link]([Link](x1,y1,n,src1,color=midcol,extend=[Link])[1])

if show_ext
[Link]([Link](x1,y1+max_diff_up,n,src1+max_diff_up
,color=upcol,style=line.style_dotted,extend=[Link])[1])
[Link]([Link](x1,y1-max_diff_dn,n,src1-max_diff_dn
,color=dncol,style=line.style_dotted,extend=[Link])[1])

//------------------------------------------------------------------------------
plot(btm ? low[length1] : top ? high[length1] : na,'Circles'
,color = btm ? dncol : upcol
,style=plot.style_circles
,offset=-length1)
//-----------------------------------------------------------------------------}

C_Len = 14 // [Link] depth for bodyAvg


C_ShadowPercent = 5.0 // size of shadows
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick
body

C_BodyHi = [Link](close, open)


C_BodyLo = [Link](close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = [Link](C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or ([Link](C_UpShadow - C_DnShadow) /
C_DnShadow * 100) < C_ShadowEqualsPercent and ([Link](C_DnShadow - C_UpShadow) /
C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals

patternLabelPosLow = low - ([Link](30) * 0.6)


patternLabelPosHigh = high + ([Link](30) * 0.6)

label_color_bearish = input([Link](255, 82, 82, 90), "Label Color Bearish")


label_color_bullish = input([Link](33, 149, 243, 90), "Label Color Bullish")

//--------------//

C_DownTrend = true
C_UpTrend = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = [Link](trendRule1, "Detect Trend Based On",
options=[trendRule1, trendRule2, "No detection"])

if trendRule == trendRule1
priceAvg = [Link](close, 50)
C_DownTrend := close < priceAvg
C_UpTrend := close > priceAvg

if trendRule == trendRule2
sma200 = [Link](close, 200)
sma50 = [Link](close, 50)
C_DownTrend := close < sma50 and sma50 < sma200
C_UpTrend := close > sma50 and sma50 > sma200

C_EngulfingBullishNumberOfCandles = 2
C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1]
and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1]
or open < close[1] )
alertcondition(C_EngulfingBullish, title = "New pattern detected", message = "New
Engulfing – Bullish pattern detected")
if C_EngulfingBullish
var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend,
there will most likely be a reversal pattern. To distinguish the first day, this
candlestick pattern uses a small body, followed by a day where the candle body
fully overtakes the body from the day before, and closes in the trend’s opposite
direction. Although similar to the outside reversal chart pattern, it is not
essential for this pattern to completely overtake the range (high to low), rather
only the open and the close."
[Link](bar_index, patternLabelPosLow, text="BE", style=label.style_label_up,
color = label_color_bullish, textcolor=[Link], tooltip = ttBullishEngulfing)

C_EngulfingBearishNumberOfCandles = 2
C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1]
and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1]
or open > close[1] )
alertcondition(C_EngulfingBearish, title = "New pattern detected", message = "New
Engulfing – Bearish pattern detected")
if C_EngulfingBearish
var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal
pattern will most likely appear. During the first day, this candlestick pattern
uses a small body. It is then followed by a day where the candle body fully
overtakes the body from the day before it and closes in the trend’s opposite
direction. Although similar to the outside reversal chart pattern, it is not
essential for this pattern to fully overtake the range (high to low), rather only
the open and the close."
[Link](bar_index, patternLabelPosHigh, text="BE",
style=label.style_label_down, color = label_color_bearish, textcolor=[Link],
tooltip = ttBearishEngulfing)

//-----------------------------------------------------------------------------}
//SUPPORT AND RESISTANCE MTF
//-----------------------------------------------------------------------------{
const bool DEBUG = false
const int timeframeCount = 3
const float touchATR = 1.0 / 30.0
const float retestATR = 1.0 / 30.0
const float labelOffsetY = 1.5
const int labelOffsetsXIndex = 30
const int maxPivotsBackSR = 15
const int retestLabelEveryXBars = 3
const int maxTraverse = 250 // Affects bar history limit. Default value 250.
const int maxRetestLabels = 100
const int maxSupports = 3
const int maxResistances = 3
const int debug_maxPivotLabels = 25

// _____ INPUTS _____


resistanceSupportCount = [Link](3, "Support & Resistance Count", options = [1,
2, 3], group = "General Configuration", display = [Link])
pivotRange = [Link](15, "Pivot Range", options = [5, 15, 30], tooltip =
"Increase for more general pivots, decrease for more private pivots.", group =
"General Configuration", display = [Link])
strength = [Link](1, "Strength", options = [1, 2, 3, 4], tooltip = "X many times
price touched relative price area in order to be considered a support/resistance
zone.", group = "General Configuration", display = [Link])
expandLines = [Link](true,"Expand Lines & Zones", group = "General
Configuration", display = [Link])

enableZones = [Link](false, "Enable Zones", group = "Support & Resistance


Zones", display = [Link])
zoneWidthType = [Link]("Dynamic", "Zone Width Type", options = ["Fixed",
"Dynamic"], group = "Support & Resistance Zones", display = [Link])
zoneWidth = [Link](1, "Fixed Zone Width", options = [1,2,3], group = "Support &
Resistance Zones", display = [Link])

timeframe1Enabled = [Link](true, title = "", group = "Timeframes", inline =


"timeframe1", display = [Link])
timeframe1 = [Link]("", title = "", group = "Timeframes", inline =
"timeframe1", display = [Link])
timeframe2Enabled = [Link](true, title = "", group = "Timeframes", inline =
"timeframe2", display = [Link])
timeframe2 = [Link]("240", title = "", group = "Timeframes", inline =
"timeframe2", display = [Link])
timeframe3Enabled = [Link](false, title = "", group = "Timeframes", inline =
"timeframe3", display = [Link])
timeframe3 = [Link]("30", title = "", group = "Timeframes", inline =
"timeframe3", display = [Link])

showBreaks = [Link](true,"Show Breaks", group = "Breaks & Retests", inline =


"ShowBR", display = [Link])
showRetests = [Link](true,"Show Retests", group = "Breaks & Retests", inline =
"ShowBR", display = [Link])
avoidFalseBreaks = [Link](true, "Avoid False Breaks", group = "Breaks &
Retests", display = [Link])
falseBreakoutVolumeThresholdOpt = [Link](0.3, "Break Volume Threshold",
minval=0.1, maxval=1.0, step=0.1, group = "Breaks & Retests", tooltip = "Only taken
into account if Avoid False Breakouts is enabled.\nHigher values mean it's less
likely to be a break.", display = [Link])
inverseBrokenLineColor = [Link](true, "Inverse Color After Broken", tooltip =
"Needs Show Breaks & Expand Lines option enabled.", group = "Breaks & Retests",
display = [Link])

falseBreakoutVolumeThreshold = falseBreakoutVolumeThresholdOpt * 100.0

lineStyle = [Link]("....", "Line Style", ["____", "----", "...."], group =


"Style", display = [Link])
lineWidth = [Link](1, "Line Width", minval = 1, group = "Style", display =
[Link])
supportColor = [Link](#08998180, "Support Color", group = "Style", inline =
"RScolors", display = [Link])
resistanceColor = [Link](#f2364580, "Resistance Color", group = "Style",
inline = "RScolors", display = [Link])
textColor = [Link](#11101051, "Text Color", group = "Style", inline =
"RScolors", display = [Link])
labelsAlign = [Link]("Right", "Align Labels", options = ["Right", "Center"],
group = "Style", tooltip = "Will only work when zones are disabled.", display =
[Link])

enableRetestAlerts = [Link](true, "Enable Retest Alerts", tooltip = "Needs Show


Retests option enabled.", group = "Alerts", display = [Link])
enableBreakAlerts = [Link](true, "Enable Break Alerts", group = "Alerts",
display = [Link])
memoryOptimizatonEnabled = [Link](true, "Enable Memory Optimization", tooltip =
"Enable this option if you encounter memory errors.", group = "Advanced", display =
[Link])
// _____ INPUTS END _____

// _____ DEBUG OPTIONS _____


debug_labelPivots = not DEBUG ? "None" : [Link]("None", title = "[DBG] Label
Pivots", group = "DEBUG", options = ["All", "RS", "None"], tooltip = "All -> Debugs
all pivot labels.\nRS -> Debugs RS pivot labels.\nNone -> Debugs none of the last
R&S pivots.")
debug_pivotLabelText = not DEBUG ? false : [Link](false, title = "[DBG] Pivot
Label Text", group = "DEBUG")
debug_showBrokenOnLabel = not DEBUG ? false : [Link](false, "[DBG] Show Broken
Text On Label", group = "DEBUG")
debug_removeDuplicateRS = not DEBUG ? true : [Link](true, "[DBG] Remove
Duplicate RS", group = "DEBUG")
debug_lastXResistances = not DEBUG ? 3 : [Link](3, "[DBG] Show Last X
Resistances", minval = 0, maxval = maxResistances, group = "DEBUG")
debug_lastXSupports = not DEBUG ? 3 : [Link](3, "[DBG] Show Last X Supports",
minval = 0, maxval = maxSupports, group = "DEBUG")
debug_enabledHistory = not DEBUG ? true : [Link](true, "[DBG] Enable History",
group = "DEBUG")
debug_maxHistoryRecords = not DEBUG ? 10 : [Link](10, "[DBG] Max History
Records", options = [1, 2, 5, 10, 25], group = "DEBUG")
// _____ DEBUG OPTIONS END _____

atr1 = [Link](30)

createRSLine (color) =>


[Link](na, na, na, na, extend = expandLines ? [Link] : [Link],
xloc=xloc.bar_time, color = color, width = lineWidth, style = lineStyle == "----" ?
line.style_dashed : lineStyle == "...." ? line.style_dotted : line.style_solid)

createRSBox (color, xlocType) =>


[Link](na, na, na, na, text_size = [Link], xloc = xlocType, extend =
[Link], bgcolor = color, text_color = textColor, text_halign = expandLines ?
text.align_right : text.align_center, border_color = #00000000)

createRSLabel () =>
[Link](na, na, "", style = label.style_none, textcolor = textColor)

createBreakLabel (RSType) =>


var ttBreakResistance = "Breakout\nA breakout of Support or Resistance."
[Link](na,na,"B",style = RSType == "Resistance" ? label.style_label_up :
label.style_label_down, color=[Link](33, 149, 243, 50), textcolor = [Link],
xloc = xloc.bar_time, size = [Link],tooltip = ttBreakResistance)

createRetestLabel (RSType) =>


[Link](na,na,"R",style = RSType == "Resistance" ? label.style_label_down :
label.style_label_up, color = RSType == "Resistance" ? resistanceColor :
supportColor, textcolor = [Link], xloc = xloc.bar_time, size = [Link])

moveLine(_line, _x, _y, _x2) =>


line.set_xy1(_line, _x, _y)
line.set_xy2(_line, _x2, _y)

moveBox (_box, _topLeftX, _topLeftY, _bottomRightX, _bottomRightY) =>


box.set_lefttop(_box, _topLeftX, _topLeftY)
box.set_rightbottom(_box, _bottomRightX, _bottomRightY)
moveRSInfoBox (_box, _startPointX, _price, _endPointX) =>
zoneWidthPercent = zoneWidth == 1 ? 0.05 : zoneWidth == 2 ? 0.06 : 0.075
if zoneWidthType == "Dynamic"
zoneWidthPercent := ((atr1) / _price) * 100 / 3.0
topY = _price * (1.0 + (zoneWidthPercent / 2.0 / 100.0))
bottomY = _price * (1.0 - (zoneWidthPercent / 2.0 / 100.0))
moveBox(_box, _startPointX, topY, _endPointX, bottomY)

// _____ TYPES _____

type customPoint
int t
float price

type RSInfo
bool isBroken = na
int brokenTime = na
string RSType = na
float price = na
line line = na
box box = na
label priceLabel = na
customPoint[] points = na
label[] debugPoints = na
label breakLabel = na
label[] retestLabels = na
line breakLine = na
box breakBox = na

curTR = [Link](true)
lowPivot = [Link](low, pivotRange, pivotRange)
highPivot = [Link](high, pivotRange, pivotRange)
pivotTime = time[pivotRange]

newRSInfo (RSType) =>


newRSInfoF = [Link]()
[Link] := RSType
[Link] := na
[Link] := false
[Link] := na

[Link] := enableZones ? na : createRSLine(RSType == "Resistance" ?


resistanceColor : supportColor)
[Link] := enableZones ? createRSBox(RSType == "Resistance" ?
resistanceColor : supportColor, xloc.bar_time) : na
[Link] := enableZones ? na : createRSLabel()
[Link] := [Link]<customPoint>(0)
[Link] := [Link]<label>(0)
[Link] := [Link]<label>(0)
[Link] := na
[Link] := na
[Link] := na

newRSInfoF

histRSInfo (RSInfo RSInfoF) =>


RSType = [Link]
newRS = [Link]()
[Link] := RSType
[Link] := [Link]

[Link] := [Link]<label>(0)
[Link] := [Link]<label>(0)
[Link] := [Link]<customPoint>(0)

histText = "History | " + [Link]([Link], [Link])

startTime = [Link](time, [Link]([Link]() - 1).t)


endTime = [Link] ? [Link] : time

if enableZones
[Link] := createRSBox(RSType == "Resistance" ? resistanceColor :
supportColor, xloc.bar_time)
moveRSInfoBox([Link], startTime, [Link], endTime)
box.set_extend([Link], expandLines ? [Link] : [Link])
box.set_text([Link], histText)
else
[Link] := [Link]([Link])
moveLine([Link], startTime, [Link], endTime)
line.set_extend([Link], expandLines ? [Link] : [Link])

[Link] := [Link]([Link])
label.set_text([Link], histText)
label.set_xloc([Link], (startTime + endTime) / 2, xloc.bar_time)

if not na([Link])
[Link] := [Link]([Link])

newRS

derenderRSInfo (RSInfo RSInfoF) =>


if not na(RSInfoF)
[Link]([Link])
[Link]([Link])
[Link]([Link])

if [Link]() > 0
for i = 0 to [Link]() - 1
[Link]([Link](i))

if [Link]() > 0
for i = 0 to [Link]() - 1
[Link]([Link](i))

[Link]([Link])
[Link]([Link])
[Link]([Link])

safeDeleteRSInfo (RSInfo RSInfoF) =>


if not na(RSInfoF)
derenderRSInfo(RSInfoF)
[Link]()
[Link]()
[Link]()

type timeframeInfo
int index = na
string timeframeStr = na
bool isEnabled = false

RSInfo[] resistances = na
RSInfo[] supports = na

float[] highPivots = na
float[] highTRs = na
int[] highTimes = na

float[] lowPivots = na
float[] lowTRs = na
int[] lowTimes = na

newTimeframeInfo (index, timeframeStr, isEnabled) =>


newTFInfo = [Link]()
[Link] := index
[Link] := isEnabled
[Link] := timeframeStr

[Link] := [Link]<RSInfo>(debug_lastXResistances)
[Link] := [Link]<RSInfo>(debug_lastXSupports)

[Link] := [Link]<float>()
[Link] := [Link]<float>()
[Link] := [Link]<int>()

[Link] := [Link]<float>()
[Link] := [Link]<float>()
[Link] := [Link]<int>()

newTFInfo

// _____ TYPES END _____

// _____ VARS _____

var timeframeInfo[] timeframeInfos = [Link](newTimeframeInfo(1, timeframe1,


timeframe1Enabled), newTimeframeInfo(2, timeframe2, timeframe2Enabled),
newTimeframeInfo(3, timeframe3, timeframe3Enabled))
var bool initRun = true

var float[] allLowPivots = [Link]<float>(0)


var float[] allHighPivots = [Link]<float>(0)

var int[] allLowTimes = [Link]<int>(0)


var int[] allHighTimes = [Link]<int>(0)

var float[] allHighTR = [Link]<float>(0)


var float[] allLowTR = [Link]<float>(0)

var RSInfo[] history = [Link]<RSInfo>(0)

RSInfo[] curRSList = [Link]<RSInfo>(0)


RSInfo[] oldRSList = [Link]<RSInfo>(0)

int maxPivotsAllowed = memoryOptimizatonEnabled ? 7 : 15 // Affects memory limit.


Default value 15.
// _____ VARS END _____

doValuesTouch (float value1, float value2, float tr) =>


if [Link](value1 - value2) <= tr * touchATR
true
else
false

doValuesTouch (float value1, float value2, float tr, float customATRRatio) =>
if [Link](value1 - value2) <= tr * customATRRatio
true
else
false

findLatestRS (timeframeInfo timeframeInfoF, string RSType, pivots, times, trs,


bannedValues) =>
RSInfo latestRSF = na
pivotsCount = [Link]()
if pivotsCount > 0
for i = 0 to pivotsCount - 1
if i >= maxTraverse
break

index = pivotsCount - i - 1
occurances = 0
invalidValue = false
pivotValue1 = [Link](index)
if [Link]() > 0
for a = 0 to [Link]() - 1
if doValuesTouch(pivotValue1, [Link](a),
[Link](index))
invalidValue := true
break

if invalidValue
continue

for j = 0 to pivotsCount - 1
if j >= maxTraverse
break

index2 = pivotsCount - j - 1
pivotValue2 = [Link](index2)
if doValuesTouch(pivotValue1, pivotValue2, [Link](index))
occurances += 1

if occurances >= strength


latestRSF := newRSInfo(RSType)
[Link] := pivotValue1
break

if [Link](index - index2) > maxPivotsBackSR * strength


break

if not na(latestRSF)
break

if not na(latestRSF)
cnt = 0
if pivotsCount > 0
for i = 0 to pivotsCount - 1
if i >= maxTraverse
break

index = pivotsCount - i - 1
pivotValue = [Link](index)
if doValuesTouch(pivotValue, [Link], [Link](index))
labelTime = [Link](index)
[Link]([Link](labelTime, pivotValue))
cnt += 1
if cnt == strength
break

if not (debug_labelPivots == "None")


if not (debug_labelPivots == "All")
if not na(latestRSF)
cnt = 0
if pivotsCount > 0
for i = 0 to pivotsCount - 1
index = pivotsCount - i - 1
pivotValue = [Link](index)
if doValuesTouch(pivotValue, [Link],
[Link](index))
labelTime = [Link](index)
[Link](RSType == "Resistance" ?
[Link](labelTime,pivotValue,text=debug_pivotLabelText ? [Link](pivotValue)
: "",xloc=xloc.bar_time, color=resistanceColor, textcolor=[Link]) :
[Link](labelTime,pivotValue,text=debug_pivotLabelText ? [Link](pivotValue)
: "",xloc=xloc.bar_time, color=supportColor,style = label.style_label_up,
textcolor=[Link]))
cnt += 1
if cnt == strength
break
else
if not na(latestRSF)
if pivotsCount > 0
for i = 0 to pivotsCount - 1
index = pivotsCount - i - 1
pivotValue = [Link](index)
labelTime = [Link](index)
[Link](RSType == "Resistance" ?
[Link](labelTime,pivotValue,text=debug_pivotLabelText ? [Link](pivotValue)
: "",xloc=xloc.bar_time, color=resistanceColor, textcolor=[Link]) :
[Link](labelTime,pivotValue,text=debug_pivotLabelText ? [Link](pivotValue)
: "",xloc=xloc.bar_time, color=supportColor,style = label.style_label_up,
textcolor=[Link]))
if [Link]() > debug_maxPivotLabels
break
latestRSF

findLatestNthRS (timeframeInfo timeframeInfoF, string RSType, pivots, times, trs,


n) =>
float[] bannedValues = [Link]<float>()
foundRS = 0
RSInfo foundLatestRS = na
while foundRS < n
foundLatestRS := findLatestRS(timeframeInfoF, RSType, pivots, times, trs,
bannedValues)
if not na(foundLatestRS)
foundRS += 1
[Link]([Link])
else
break
foundLatestRS

isTimeframeLower (timeframe1F, timeframe2F) =>


timeframe.in_seconds(timeframe1F) < timeframe.in_seconds(timeframe2F)

getMinTimeframe (timeframe1F, timeframe2F) =>


if isTimeframeLower(timeframe1F, timeframe2F)
timeframe1F
else
timeframe2F

getMaxTimeframe (timeframe1F, timeframe2F) =>


if isTimeframeLower(timeframe1F, timeframe2F)
timeframe2F
else
timeframe1F

getFirstBreak (RSInfo rsInfo) =>


if na(rsInfo)
[na, na]

curIndex = 0
float foundBreakLevel = na
int foundBreakTime = na
float foundBreakTR = na

while true
if curIndex >= maxTraverse
break
isBarBreak = [Link] == "Resistance" ? (close[curIndex + 1] <=
[Link] and close[curIndex] > [Link]) : (close[curIndex + 1] >=
[Link] and close[curIndex] < [Link])
if isBarBreak
isTrueBreakout = true
if avoidFalseBreaks
shortTerm = 2
longTerm = 15

shortSum = 0.0
longSum = 0.0

for i = 0 to shortTerm
shortSum += volume[curIndex + i]

for i = 0 to longTerm
longSum += volume[curIndex + i]

shortVolumeAvg = shortSum / shortTerm


longVolumeAvg = longSum / longTerm

volumeRatio = ((shortVolumeAvg - longVolumeAvg) / longVolumeAvg) *


100.0
isTrueBreakout := (volumeRatio >= falseBreakoutVolumeThreshold)
if isTrueBreakout
foundBreakLevel := [Link] == "Resistance" ? low[curIndex] :
high[curIndex]
foundBreakTime := time[curIndex]
foundBreakTR := high[curIndex] - low[curIndex]

curIndex += 1
if time[curIndex] <= [Link]([Link]() - 1).t
break
[foundBreakLevel, foundBreakTime, foundBreakTR]

getRetests (RSInfo rsInfo) =>


if na(rsInfo)
[na,na]

curIndex = 0
lastRetestIndex = -999
int[] retestTimes = [Link]<int>()
float[] retestLevels = [Link]<float>()
float[] retestTRs = [Link]<float>()

while true
if curIndex >= maxTraverse
break
if [Link]() == maxRetestLabels
break
if [Link] and time[curIndex] >= [Link]
curIndex += 1
continue

tr = high[curIndex] - low[curIndex]
isRetest = ([Link] == "Resistance" ? (doValuesTouch([Link],
close[curIndex], tr, retestATR) or doValuesTouch([Link], high[curIndex], tr,
retestATR)) : (doValuesTouch([Link], close[curIndex], tr, retestATR) or
doValuesTouch([Link], low[curIndex], tr, retestATR)))
if isRetest and curIndex - lastRetestIndex >= retestLabelEveryXBars
[Link]([Link] == "Resistance" ? high[curIndex] :
low[curIndex])
[Link](time[curIndex])
[Link](high[curIndex] - low[curIndex])
lastRetestIndex := curIndex
curIndex += 1
if time[curIndex] <= [Link]([Link]() - 1).t
break
[retestLevels, retestTimes, retestTRs]

formatTimeframeString (formatTimeframe) =>


timeframeF = formatTimeframe == "" ? [Link] : formatTimeframe

if [Link](timeframeF, "D") or [Link](timeframeF, "W") or


[Link](timeframeF, "S") or [Link](timeframeF, "M")
timeframeF
else
seconds = timeframe.in_seconds(timeframeF)
if seconds >= 3600
hourCount = int(seconds / 3600)
[Link](hourCount) + " Hour" + (hourCount > 1 ? "s" : "")
else
timeframeF + " Min"

handleRSInfo (timeframeInfo timeframeInfoF, RSInfo RSInfoF, int index, string


RSType) =>
if not na(RSInfoF)
if not na(timeframeInfoF)
[Link](RSInfoF)

[foundBreakLevel, foundBreakTime, foundBreakTR] = getFirstBreak(RSInfoF)

[Link] := na(foundBreakLevel) ? false : true


[Link] := na(foundBreakLevel) ? na : foundBreakTime

if not na(foundBreakLevel)
if showBreaks
if na([Link])
[Link] := createBreakLabel([Link])
label.set_xy([Link], foundBreakTime, foundBreakLevel +
([Link] == "Resistance" ? (-foundBreakTR / labelOffsetY) : foundBreakTR /
labelOffsetY))

if expandLines
if na([Link]) and enableZones == false
[Link] := createRSLine([Link])

if na([Link]) and enableZones == true


[Link] := createRSBox([Link], xloc.bar_time)

if not enableZones
line.set_extend([Link], [Link])
else
box.set_extend([Link], [Link])

if inverseBrokenLineColor and showBreaks


if not enableZones
line.set_color([Link], [Link] ==
"Resistance" ? supportColor : resistanceColor)
else
box.set_bgcolor([Link], [Link] ==
"Resistance" ? supportColor : resistanceColor)
else
if not enableZones
line.set_color([Link], [Link] ==
"Resistance" ? resistanceColor : supportColor)
else
box.set_bgcolor([Link], [Link] ==
"Resistance" ? resistanceColor : supportColor)

if showRetests
[retestLevels, retestTimes, retestTRs] = getRetests(RSInfoF)

if not na(retestLevels) and [Link]() > 0


for i = 0 to [Link]() - 1
newRetestLabel = createRetestLabel([Link])
label.set_xy(newRetestLabel, [Link](i),
[Link](i) + ([Link] == "Support" ? (-[Link](i) /
labelOffsetY) : [Link](i) / labelOffsetY))
[Link](newRetestLabel)
timeSkipOffset = 0
if enableZones
zoneEndX = time + timeSkipOffset +
timeframe.in_seconds([Link]) * 1000 * labelOffsetsXIndex
startTime = [Link](time, [Link]([Link]() -
1).t)
moveRSInfoBox([Link], startTime, [Link], na(foundBreakTime)
? zoneEndX : foundBreakTime)
moveRSInfoBox([Link], foundBreakTime, [Link],
zoneEndX)
else
endTime = time + timeSkipOffset +
timeframe.in_seconds([Link]) * 1000
startTime = [Link](time, [Link]([Link]() -
1).t)
moveLine([Link], startTime, [Link], na(foundBreakTime) ?
endTime : foundBreakTime)
moveLine([Link], foundBreakTime, [Link], endTime)
//[Link]([Link]([Link]) + " | " +
[Link]([Link](strength - 1).time) + " = " +
[Link](line.get_x1([Link])) + " | " + [Link](endTime) + " = " +
[Link](line.get_x2([Link])))

if expandLines
if not enableZones
line.set_extend([Link], (na(foundBreakTime)) ? [Link] :
[Link])
else
box.set_extend([Link], (na(foundBreakTime)) ? [Link] :
[Link])
else
if not enableZones
line.set_extend([Link], na(foundBreakTime) ? [Link] :
[Link])
else
box.set_extend([Link], na(foundBreakTime) ? [Link] :
[Link])

//labelTitleOld = formatTimeframeString([Link]) + " "


+ [Link] + " " + [Link](index + 1) + " (" +
[Link]([Link],[Link]) + ")" + ([Link] ? "
[Broken]" : "")
labelTitle = formatTimeframeString([Link]) + " | " +
[Link]([Link],[Link]) + ((debug_showBrokenOnLabel and
[Link]) ? " [B]" : "")

if not enableZones
label.set_text([Link], enableZones ? "" : labelTitle)
label.set_y([Link], [Link])
else
box.set_text([Link], ([Link] and expandLines) ? "" :
labelTitle)
box.set_text([Link], labelTitle)

if expandLines or not [Link]


if not enableZones
if labelsAlign == "Right"
label.set_xloc([Link], bar_index +
labelOffsetsXIndex, xloc.bar_index)
else
label.set_xloc([Link], labelsAlign == "Center" ?
((chart.right_visible_bar_time + chart.left_visible_bar_time) / 2) : na,
xloc.bar_time)
else
box.set_text_halign([Link], text.align_right)
box.set_text_halign([Link], text.align_right)
else
if not enableZones
label.set_xloc([Link],
([Link]([Link]() - 1).t + [Link]) / 2,
xloc.bar_time)
else
box.set_text_halign([Link], text.align_center)
box.set_text_halign([Link], text.align_center)
else
[Link]("Couldn't find timeframe " + [Link]([Link]) +
" " + [Link](index + 1) + "th " + RSType + " . Try decreasing pivot range in
the settings.")

handleTimeframe (timeframeIndex, lowPivots, highPivots, lowTimes, highTimes,


lowTRs, highTRs) =>
timeframeInfoF = [Link](timeframeIndex - 1)

[Link]()
[Link]()

[Link]()
[Link]()

[Link]()
[Link]()

[Link] := lowPivots
[Link] := highPivots

[Link] := lowTimes
[Link] := highTimes

[Link] := lowTRs
[Link] := highTRs

getHigherTFData (timeframeStr) =>


[Link]([Link], getMaxTimeframe([Link],
timeframeStr), [allLowPivots, allHighPivots, allLowTimes, allHighTimes, allLowTR,
allHighTR])

pushHighPivots (timeframeInfoF, highPivotF, timeF, trF) =>


if not na(highPivotF)
[Link](highPivotF)
[Link](timeF)
[Link](trF)

pushLowPivots (timeframeInfoF, lowPivotF, timeF, trF) =>


if not na(lowPivotF)
[Link](lowPivotF)
[Link](timeF)
[Link](trF)
handleTimeframeIfLower (timeframeInfo timeframeInfoF, highs, lows, int[] timesF,
float[] trsF) =>
if [Link] and isTimeframeLower([Link],
[Link])
if [Link]() > 0
for i = 0 to [Link]() - 1
timeF = [Link](i)
pushHighPivots(timeframeInfoF, [Link](i), timeF, [Link](i))
if [Link]() > 0
for i = 0 to [Link]() - 1
timeF = [Link](i)
pushLowPivots(timeframeInfoF, [Link](i), timeF, [Link](i))

getLowerTFData (timeframeStr) =>


lowPivots = isTimeframeLower(timeframeStr, [Link]) ?
request.security_lower_tf([Link], getMinTimeframe(timeframeStr,
[Link]), [Link](low, pivotRange, pivotRange)) : na
highPivots = isTimeframeLower(timeframeStr, [Link]) ?
request.security_lower_tf([Link], getMinTimeframe(timeframeStr,
[Link]), [Link](high, pivotRange, pivotRange)) : na
times = isTimeframeLower(timeframeStr, [Link]) ?
request.security_lower_tf([Link], getMinTimeframe(timeframeStr,
[Link]), pivotTime) : na
trs = isTimeframeLower(timeframeStr, [Link]) ?
request.security_lower_tf([Link], getMinTimeframe(timeframeStr,
[Link]), curTR[pivotRange]) : na
[lowPivots, highPivots, times, times, trs, trs]

getTFData (timeframeStr) =>


if isTimeframeLower(timeframeStr, [Link])
getLowerTFData(timeframeStr)
else
getHigherTFData(timeframeStr)

checkIfRSAreSame (RSInfo rsInfo1, RSInfo rsInfo2) =>


if na(rsInfo1) or na(rsInfo2)
false
else if [Link] != [Link]
false
else if [Link] != [Link]
false
else
true

checkIfArrHasRS (RSInfo[] arr, RSInfo rsInfoF) =>


if na(arr) or na(rsInfoF)
true
else if [Link]() == 0
false
else
foundRS = false
for i = 0 to [Link]() - 1
arrRS = [Link](i)
if checkIfRSAreSame(arrRS, rsInfoF)
foundRS := true
break
if foundRS
true
else
false

clearTimeframeRS (timeframeInfoF) =>


oldRetestsCount = 0
oldBreaksCount = 0

if [Link]() > 0
for j = 0 to [Link]() - 1
RSInfo RSInfoF = [Link](j)
if not na(RSInfoF)
if debug_enabledHistory
if checkIfArrHasRS(oldRSList, RSInfoF) == false
[Link](RSInfoF)

oldRetestsCount += [Link]()
oldBreaksCount += [Link] ? 1 : 0
derenderRSInfo(RSInfoF)

if [Link]() > 0
for j = 0 to [Link]() - 1
RSInfo RSInfoF = [Link](j)
if not na(RSInfoF)
if debug_enabledHistory
if checkIfArrHasRS(history, RSInfoF) == false
[Link](RSInfoF)

oldRetestsCount += [Link]()
oldBreaksCount += [Link] ? 1 : 0
derenderRSInfo(RSInfoF)

[Link]()
[Link]()
[oldRetestsCount, oldBreaksCount]

findTimeframeRS (timeframeInfoF, RSType, arr, count, pivots, times, trs) =>


curRetestsCount = 0
curBreaksCount = 0

if count > 0
for j = 0 to count - 1
foundRS = findLatestNthRS(timeframeInfoF, RSType, pivots, times, trs, j
+ 1)
if not na(foundRS)
notDuplicate = true
for a = 0 to [Link]() - 1
aInfo = [Link](a)
if na(aInfo) or [Link] == false
continue
otherTimeframeArray = (RSType == "Resistance" ?
[Link] : [Link])
if [Link]() > 0
for b = 0 to [Link]() - 1
if checkIfRSAreSame(foundRS,
[Link](b))
notDuplicate := false
break
if notDuplicate == false
break
if notDuplicate or not debug_removeDuplicateRS
[Link](foundRS)

if [Link]() > 0
for j = 0 to [Link]() - 1
curRS = [Link](j)
if not na(curRS)
handleRSInfo(timeframeInfoF, curRS, j, RSType)
curRetestsCount += [Link]()
curBreaksCount += [Link] ? 1 : 0
[curRetestsCount, curBreaksCount]

if not na(lowPivot)
[Link](lowPivot)
[Link](pivotTime)
[Link](curTR[pivotRange])
if [Link]() > maxPivotsAllowed
[Link](0)
[Link](0)
[Link](0)

if not na(highPivot)
[Link](highPivot)
[Link](pivotTime)
[Link](curTR[pivotRange])
if [Link]() > maxPivotsAllowed
[Link](0)
[Link](0)
[Link](0)

[lowPivotsTF1, highPivotsTF1, lowTimesTF1, highTimesTF1, lowTRsTF1, highTRsTF1] =


getTFData(timeframe1)
handleTimeframeIfLower([Link](0), highPivotsTF1, lowPivotsTF1,
highTimesTF1, highTRsTF1)

[lowPivotsTF2, highPivotsTF2, lowTimesTF2, highTimesTF2, lowTRsTF2, highTRsTF2] =


getTFData(timeframe2)
handleTimeframeIfLower([Link](1), highPivotsTF2, lowPivotsTF2,
highTimesTF2, highTRsTF2)

[lowPivotsTF3, highPivotsTF3, lowTimesTF3, highTimesTF3, lowTRsTF3, highTRsTF3] =


getTFData(timeframe3)
handleTimeframeIfLower([Link](2), highPivotsTF3, lowPivotsTF3,
highTimesTF3, highTRsTF3)

//plot(nz(na,[Link](0).[Link]() > 0 ?
[Link](0).[Link]([Link](0).[Link]() - 1) :
0), color = [Link], title = "High Pivots")
//plot(nz(na,[Link](0).[Link]() > 0 ?
[Link](0).[Link]([Link](0).[Link]() - 1) :
0), color = [Link], title = "Low Pivots")

if [Link] or ([Link] and [Link])


if timeframe1Enabled and not isTimeframeLower(timeframe1, [Link])
handleTimeframe(1, lowPivotsTF1, highPivotsTF1, lowTimesTF1, highTimesTF1,
lowTRsTF1, highTRsTF1)

if timeframe2Enabled and not isTimeframeLower(timeframe2, [Link])


handleTimeframe(2, lowPivotsTF2, highPivotsTF2, lowTimesTF2, highTimesTF2,
lowTRsTF2, highTRsTF2)

if timeframe3Enabled and not isTimeframeLower(timeframe3, [Link])


handleTimeframe(3, lowPivotsTF3, highPivotsTF3, lowTimesTF3, highTimesTF3,
lowTRsTF3, highTRsTF3)

int enabledTimeframeCount = 0
for i = 0 to timeframeCount - 1
timeframeInfo curInfo = [Link](i)
if [Link]
enabledTimeframeCount += 1

int oldRetestsCount = 0
int curRetestsCount = 0

int oldBreaksCount = 0
int curBreaksCount = 0

for i = 0 to timeframeCount - 1
timeframeInfo curInfo = [Link](i)
if not [Link]
continue

[oldRetests, oldBreaks] = clearTimeframeRS(curInfo)


oldRetestsCount += oldRetests
oldBreaksCount += oldBreaks

resistanceCount = [Link](DEBUG ? debug_lastXResistances :


resistanceSupportCount, maxResistances - (enabledTimeframeCount > 1 ? 1 : 0))
resistanceCount := [Link](resistanceCount, 0)

supportCount = [Link](DEBUG ? debug_lastXSupports :


resistanceSupportCount, maxSupports - (enabledTimeframeCount > 1 ? 1 : 0))
supportCount := [Link](supportCount, 0)

[curRetests1, curBreaks1] = findTimeframeRS(curInfo, "Resistance",


[Link], resistanceCount, [Link], [Link],
[Link])
[curRetests2, curBreaks2] = findTimeframeRS(curInfo, "Support",
[Link], supportCount, [Link], [Link],
[Link])
curRetestsCount += curRetests1 + curRetests2
curBreaksCount += curBreaks1 + curBreaks2

if debug_enabledHistory
historyIndexesToDelete = [Link]<int>(0)
if [Link]() > 0
for i = 0 to [Link]() - 1
if checkIfArrHasRS(curRSList, [Link](i))
[Link](i)

if [Link]() > 0
for i = 0 to [Link]() - 1
deleteIndex =
[Link]([Link]() - i - 1)
safeDeleteRSInfo([Link](deleteIndex))
[Link](deleteIndex)

if [Link]() > 0
for i = 0 to [Link]() - 1
curRS = [Link](i)
if checkIfArrHasRS(curRSList, curRS) == false
[Link](histRSInfo(curRS))
if [Link]() > debug_maxHistoryRecords
safeDeleteRSInfo([Link](0))
[Link](0)

if [Link]() > 0
for i = 0 to [Link]() - 1
safeDeleteRSInfo([Link](i))

[Link]()
[Link]()

if DEBUG
[Link]("History Size : " + [Link]([Link]()))
[Link]("Label Count : " + [Link]([Link]()))
[Link]("Line Count : " + [Link]([Link]()))
[Link]("Box Count : " + [Link]([Link]()))

if enableRetestAlerts and curRetestsCount > oldRetestsCount and initRun ==


false
alert("New Retests Occured.")

if enableBreakAlerts and curBreaksCount > oldBreaksCount and initRun == false


alert("New Breaks Occured.")

initRun := false

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
at https://mozilla.org/MPL/2.0/
// © lean
min2 := ma - atr
        //Set new box and level
        bx := box.new(n[length3], ma + atr, n, ma - atr, na
bearWidth = input.int(1, title='Line Width:', group='Bearish Sweep')
bearStyle = input.string('Dashed', title='Line Style:',
//Check Swing H/L Stopper
var int swingLowCounter = 0
var int swingHighCounter = 0
var bool isSwingLowCheck = false
var bool
if showSwing
    if stopPrintingHigh == false 
        line.set_x2(highLine,bar_index+5)
    if stopPrintingLow == false
//Style
upcol = input(#ff1100,'Upper Extremity Color',group='Style')
midcol = input(#ff5d00,'Zig Zag Color',group='Style')
dn
max_diff_up := math.max(math.max(src1[length1+i],open[length1+i]) - 
point,max_diff_up)
        max_diff_dn := math.m
//-----------------------------------------------------------------------------}
C_Len = 14 // ta.ema depth for bodyAvg
C_Sha
and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] 
or open < close[1] )
alertcondition(C_Eng
zone.", group = "General Configuration", display = display.none)
expandLines = input.bool(true,"Expand Lines & Zones", group

You might also like