Triangle Pattern - Nabyed0003
Triangle Pattern - Nabyed0003
indicator("Triangle Patterns",overlay=true)
length = input.int(14)
k = input.float(1.,'Slope',minval=0,step=.1)
method = input.string('Atr','Slope Calculation Method',
options=['Atr','Stdev','Linreg'])
show = input(false,'Show Only Confirmed Breakouts')
upper = 0.,lower = 0.
slope_ph = 0.,slope_pl = 0.
src = close
n = bar_index
ph = ta.pivothigh(length,length)
pl = ta.pivotlow(length,length)
slope = switch method
'Atr' => ta.atr(length)/length*k
'Stdev' => ta.stdev(src,length)/length*k
'Linreg' => math.abs(ta.sma(src*bar_index,length)-
ta.sma(src,length)*ta.sma(bar_index,length))/ta.variance(n,length)/2*k
plot(upper,'Upper',color = ph ? na : #808080,offset=-length)
plot(lower,'Lower',color = pl ? na : #808080,offset=-length)
alertcondition(ta.crossover(src,upper-slope_ph*length),'Upper Breakout','Price
broke upper trendline')
alertcondition(ta.crossunder(src,lower+slope_pl*length),'Lower Breakout','Price
broke lower trendline')
devTooltip = "Deviation is a multiplier that affects how much the price should
deviate from the previous pivot in order for the bar to become a new pivot."
depthTooltip = "The minimum number of bars that will be taken into account when
calculating the indicator."
if not na(iH)
dev = calc_dev(pLast, pH)
[id, isHigh] = pivotFound(dev, true, iH, pH)
if not na(id)
if id != lineLast
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iH
pLast := pH
else
if not na(iL)
dev = calc_dev(pLast, pL)
[id, isHigh] = pivotFound(dev, false, iL, pL)
if not na(id)
if id != lineLast
line.delete(lineLast)
lineLast := id
isHighLast := isHigh
iPrev := iLast
iLast := iL
pLast := pL
_wrap(txt) =>
"(" + str.tostring(txt, format.mintick) + ")"
_label_txt(level, price) =>
l = levelsFormat == "Values" ? str.tostring(level) : str.tostring(level * 100)
+ "%"
(levels ? l : "") + (prices ? _wrap(price) : "")
_crossing_level(sr, r) =>
(r > sr and r < sr[1]) or (r < sr and r > sr[1])