SSL Hybrid Advanced
SSL Hybrid Advanced
//ATR
atrlen = input(14, 'ATR Period', group='Settings: ATR')
mult = input.float(1.5, 'ATR Multi', step=0.1, group='Settings: ATR')
smoothing = input.string(title='ATR Smoothing', defval='WMA', options=['RMA',
'SMA', 'EMA', 'WMA'], group='Settings: ATR')
//
tema(src, len) =>
ema1 = ta.ema(src, len)
ema2 = ta.ema(ema1, len)
ema3 = ta.ema(ema2, len)
3 * ema1 - 3 * ema2 + ema3
kidiv = input.int(defval=1, maxval=4, title='Kijun MOD Divider', group='Settings:
SSL')
//----
//EDSMA
get2PoleSSF(src, length) =>
PI = 2 * math.asin(1)
arg = math.sqrt(2) * PI / length
a1 = math.exp(-arg)
b1 = 2 * a1 * math.cos(arg)
c2 = b1
c3 = -math.pow(a1, 2)
c1 = 1 - c2 - c3
ssf = 0.0
ssf := c1 * src + c2 * nz(ssf[1]) + c3 * nz(ssf[2])
ssf
arg = PI / length
a1 = math.exp(-arg)
b1 = 2 * a1 * math.cos(1.738 * arg)
c1 = math.pow(a1, 2)
coef2 = b1 + c1
coef3 = -(c1 + b1 * c1)
coef4 = math.pow(c1, 2)
coef1 = 1 - coef2 - coef3 - coef4
ssf = 0.0
ssf := coef1 * src + coef2 * nz(ssf[1]) + coef3 * nz(ssf[2]) + coef4 *
nz(ssf[3])
ssf
edsma = 0.0
edsma := alpha * src + (1 - alpha) * nz(edsma[1])
result := edsma
result
if type == 'ZLSMA'
lsma = ta.linreg(src, len, 0)
lsma2 = ta.linreg(lsma, len, 0)
eq= lsma-lsma2
result := lsma+eq
result
result
///EXIT
ExitHigh = ma(SSL3Type, high, len3)
ExitLow = ma(SSL3Type, low, len3)
//SSL1 VALUES
Hlv = int(na)
Hlv := close > emaHigh ? 1 : close < emaLow ? -1 : Hlv[1]
sslDown = Hlv < 0 ? emaHigh : emaLow
//SSL2 VALUES
Hlv2 = int(na)
Hlv2 := close > maHigh ? 1 : close < maLow ? -1 : Hlv2[1]
sslDown2 = Hlv2 < 0 ? maHigh : maLow
//EXIT VALUES
Hlv3 = int(na)
Hlv3 := close > ExitHigh ? 1 : close < ExitLow ? -1 : Hlv3[1]
sslExit = Hlv3 < 0 ? ExitHigh : ExitLow
base_cross_Long = ta.crossover(close, sslExit)
base_cross_Short = ta.crossover(sslExit, close)
codiff = base_cross_Long ? 1 : base_cross_Short ? -1 : na
//COLORS
show_color_bar = input(title='Color Bars', defval=true, group='Candles')
color_bar = close > upperk ?color.new( #00c3ff,0) : close < lowerk ?
color.new(#ff0062,0) : color.new(color.gray,0)
color_ssl1 = close > sslDown ?color.new( #00c3ff,0) : close < sslDown ?
color.new(#ff0062,0) :na
color_bar2=close > upperk ? color.new(#0000ff,0) : close < lowerk ?
color.new(#ff0000,0) : color.new(color.gray,0)
//PLOTS
plotarrow(codiff, colorup=color.new(#00c3ff, 20), colordown=color.new(#ff0062, 20),
title='Exit Arrows', maxheight=20, offset=0)
///QQE MOD
RSI_Period = input(6, title='RSI Length',group='Settings:QQE-MOD')
SF = input(5, title='RSI Smoothing',group='Settings:QQE-MOD')
QQE = input.float(3, title='Fast QQE Factor',group='Settings:QQE-MOD',step=0.1)
ThreshHold = input(3, title='Thresh-hold',group='Settings:QQE-MOD')
qqsrc = input(close, title='RSI Source',group='Settings:QQE-MOD')
Wilders_Period = RSI_Period * 2 - 1
Rsi = ta.rsi(qqsrc, RSI_Period)
RsiMa = ta.ema(Rsi, SF)
AtrRsi = math.abs(RsiMa[1] - RsiMa)
MaAtrRsi = ta.ema(AtrRsi, Wilders_Period)
dar = ta.ema(MaAtrRsi, Wilders_Period) * QQE
longband = 0.0
shortband = 0.0
trend = 0
DeltaFastAtrRsi = dar
RSIndex = RsiMa
newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi
longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ?
math.max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ?
math.min(shortband[1], newshortband) : newshortband
cross_1 = ta.cross(longband[1], RSIndex)
trend := ta.cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband
////////////////////
length = input.int(50, minval=1, title='Bollinger Length',group='Settings:QQE-MOD')
qqmult = input.float(0.35, minval=0.001, maxval=5, step=0.1, title='BB
Multiplier',group='Settings:QQE-MOD')
basis = ta.sma(FastAtrRsiTL - 50, length)
dev = qqmult * ta.stdev(FastAtrRsiTL - 50, length)
upper = basis + dev
lower = basis - dev
qqcolor_bar = RsiMa - 50 > upper ?color.new( #00c3ff,0) : RsiMa - 50 < lower ?
color.new(#ff0062,0) : color.new(color.gray,0)
// Zero cross
QQEzlong = 0
QQEzlong := nz(QQEzlong[1])
QQEzshort = 0
QQEzshort := nz(QQEzshort[1])
QQEzlong := RSIndex >= 50 ? QQEzlong + 1 : 0
QQEzshort := RSIndex < 50 ? QQEzshort + 1 : 0
//Zero = hline(0, color=color.white, linestyle=hline.style_dotted, linewidth=1)
////////////////////////////////////////////////////////////////
RSI_Period2 = input(6, title='RSI Length',group='Settings:QQE-MOD')
SF2 = input(5, title='RSI Smoothing',group='Settings:QQE-MOD')
QQE2 = input.float(1.61, title='Fast QQE2 Factor',group='Settings:QQE-
MOD',step=0.1)
ThreshHold2 = input(3, title='Threshold',group='Settings:QQE-MOD')
src2 = input(close, title='RSI Source',group='Settings:QQE-MOD')
Wilders_Period2 = RSI_Period2 * 2 - 1
Rsi2 = ta.rsi(src2, RSI_Period2)
RsiMa2 = ta.ema(Rsi2, SF2)
AtrRsi2 = math.abs(RsiMa2[1] - RsiMa2)
MaAtrRsi2 = ta.ema(AtrRsi2, Wilders_Period2)
dar2 = ta.ema(MaAtrRsi2, Wilders_Period2) * QQE2
longband2 = 0.0
shortband2 = 0.0
trend2 = 0
DeltaFastAtrRsi2 = dar2
RSIndex2 = RsiMa2
newshortband2 = RSIndex2 + DeltaFastAtrRsi2
newlongband2 = RSIndex2 - DeltaFastAtrRsi2
longband2 := RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] ?
math.max(longband2[1], newlongband2) : newlongband2
shortband2 := RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] ?
math.min(shortband2[1], newshortband2) : newshortband2
cross_2 = ta.cross(longband2[1], RSIndex2)
trend2 := ta.cross(RSIndex2, shortband2[1]) ? 1 : cross_2 ? -1 : nz(trend2[1], 1)
FastAtrRsi2TL = trend2 == 1 ? longband2 : shortband2
// Zero cross
QQE2zlong = 0
QQE2zlong := nz(QQE2zlong[1])
QQE2zshort = 0
QQE2zshort := nz(QQE2zshort[1])
QQE2zlong := RSIndex2 >= 50 ? QQE2zlong + 1 : 0
QQE2zshort := RSIndex2 < 50 ? QQE2zshort + 1 : 0
hcolor2 = RsiMa2 - 50 > ThreshHold2 ? color.new(#161b25,0): RsiMa2 - 50 < 0 -
ThreshHold2 ? color.new(#161b25,0): color.new(#161b25,0)
//plot(ta.ema( close+(FastAtrRsi2TL-50)/10000,5), title='QQE Line',
color=color.new(color.gray, 0), linewidth=2)
//plot(RsiMa2 - 50, color=hcolor2, title='Histo2', style=plot.style_columns,
transp=50)
Greenbar1 = RsiMa2 - 50 > ThreshHold2
Greenbar2 = RsiMa - 50 > upper
Redbar1 = RsiMa2 - 50 < 0 - ThreshHold2
Redbar2 = RsiMa - 50 < lower
//plot(Greenbar1 and Greenbar2 == 1 ? RsiMa2 - 50 : na, title='QQE Up',
style=plot.style_columns, color=color.new(#00c3ff, 0))
//plot(Redbar1 and Redbar2 == 1 ? RsiMa2 - 50 : na, title='QQE Down',
style=plot.style_columns, color=color.new(#ff0062, 0))
//bgcolor(showbg and RsiMa2 - 50?hcolor2:na,title='QQE Bg GREY')
qqcolr=FastAtrRsiTL-50<RsiMa-50? color.new(#002734, 0):FastAtrRsiTL-50>RsiMa-50?
color.new(#3a0016, 0): na
bgcolor(showbg ?qqcolr:na,title='QQE Bg')
//--->plotshape(showqqedot?Greenbar1 and Greenbar2:na,color=color.new(#00c3ff,
20),title='QQE
Up',style=shape.triangleup,size=size.auto,location=location.belowbar)
//--->plotshape(showqqedot?Redbar1 and Redbar2:na,color=color.new(#ff0062,
20),title='QQE
Dn',style=shape.triangledown,size=size.auto,location=location.abovebar)
qqxcolor=FastAtrRsiTL-50<RsiMa-50?color.new(color.green,0):FastAtrRsiTL-50>RsiMa-
50?color.new(color.red,0):na
//p2=plot(FastAtrRsiTL-50,color=color.red,transp=0,linewidth=2)
//p1=plot(RsiMa-50,color=color.green,transp=0,linewidth=2)
///////////ADX
adxl=input(14, title='ADX/DMI length', group='Settings: ADX')
adxs=input(14, title='ADX/DMI smooth length', group='Settings: ADX')
[plus,minus,adx]=request.security(syminfo.tickerid,'',ta.dmi(adxl,adxs))
adxtreshold=input.int(20,'ADX Treshold', group='Settings: ADX')
em200=ta.ema(open,200)
adxem200color=adx>adxtreshold and plus>minus?color.new(color.lime,
0):adx>adxtreshold and plus<minus?color.new(color.maroon,
0):color.new(color.yellow, 0)
plot(show_ema200 ? em200 : na, 'EMA200', color=adxem200color,linewidth=3,title='ADX
Cross')
adxcross=ta.crossover(plus,minus)?color.new(color.blue,
0):ta.crossunder(plus,minus)?color.new(color.red, 0):na
plotshape(ta.cross(plus,minus)?em200:na, color=adxcross,
size=size.tiny,location=location.absolute, style=shape.diamond, title='ADX Cross')
///////////////////HULL+SUPRTREND
showhulltrend=input.bool(false,'Show HULL MTF', group='Settings:
Filters',inline='HULL')
showtrend=input.bool(false,'Show Supertrend', group='Settings:
Filters',inline='Supertrend')
showstc=input.bool(true,title='SuperTrend Color/Hull Color', group='Settings:
Filters',inline='Supertrend')
mtf4 = input.timeframe(title="HULL TIME FRAME", defval="", group='Settings:
Filters',inline='HULL')
stf4 = input.timeframe(title="SUPER TREND TIME FRAME", defval="",
group='Settings: Filters',inline='Supertrend')
ma_length4 = input(110, title = "Hull TREND Length\n[Scalping:55,Floating S/R:100-
300,]", group='Settings: Filters',inline='HULL')
[supertrend,direction]=request.security(syminfo.tickerid,
stf4,ta.supertrend(input.float(3,title='Supertrend ATR Multiplier',step=0.1,
group='Settings: Filters',inline='Supertrend'),input.int(10,title='Supertrend
Length', group='Settings: Filters',inline='Supertrend')),barmerge.gaps_off)
supertrendup=direction<0?supertrend:na
supertrenddn=direction>0?supertrend:na
stc=supertrendup?color.new(#00c3ff,50):color.new(#ff0062,50)
trendcolor=showstc?stc:qqxcolor
plot(showtrend?supertrendup:na,title='Supertrend
Up',color=trendcolor,linewidth=4,style=plot.style_linebr)
plot(showtrend?supertrenddn:na,title='Supertrend
Down',color=trendcolor,linewidth=4,style=plot.style_linebr)
///////////////MACD///////////
[macd,signal,hist]=ta.macd(close,input.int(5,title='FAST MACD',group='Settings:
MACD'),input.int(50,title='SLOW MACD',group='Settings:
MACD'),input.int(30,title='Signal',group='Settings: MACD'))
plotshape(ta.crossover(macd,signal)?close:na, title='MACD Crossover Buy', text='',
location=location.belowbar, style=shape.xcross, size=size.tiny,
color=color.new(#00FF00, 20), textcolor=color.new(color.white, 0))
plotshape(ta.crossunder(macd,signal)?close:na, title='MACD Crossover Sell',
text='', location=location.abovebar, style=shape.xcross, size=size.tiny,
color=color.new(#ff0000, 0), textcolor=color.new(color.white, 0))
color_bars=showadxbg and adx<adxtreshold?color.new(color.purple,90):na
bgcolor(adx<adxtreshold ? color_bars : na)
/////////////
/////////////////////////Bollinger Bands
matype=input.string('SMA',title='Bollinger MA type',options=['EMA','HMA','SMA'])
kLength = input(20, title='Keltner Length')
kN = input(2, title='Keltner Deviation')
bbLength = input(20, title='Bollinger Length')
bbN = input(2, title='Bollinger Deviation')
//--- Keltner
kma=matype=='EMA'?ta.ema(close, kLength):matype=='HMA'?ta.hma(close,
kLength):ta.sma(close, kLength)
kUpper = kma + kN * ta.atr(kLength)
kLower = kma - kN * ta.atr(kLength)
//--- Bollinger
bma=matype=='EMA'?ta.ema(close, bbLength):matype=='HMA'?ta.hma(close,
bbLength):ta.sma(close, bbLength)
bbUpper = bma + bbN * ta.stdev(close, bbLength)
bbLower = bma - bbN * ta.stdev(close, bbLength)
bbMiddle=matype=='EMA'?ta.ema(close, bbLength):matype=='HMA'?ta.hma(close,
bbLength):ta.sma(close, bbLength)
//--- Bollinger Band Squeeze
squeeze = bbUpper <= kUpper and bbLower >= kLower
//--- Plots
//plot(bbUpper, title='Upper Band')
//plot(bbLower, title='Lower Band')
//--- Fill
plot(showbb=='BB'?bbUpper:showbb=='Keltner'?kUpper:na, style=plot.style_linebr,
color=color.new(color.purple, 0), title=' Upper Band')
plot(showbb=='BB'?bbLower:showbb=='Keltner'?kLower:na, style=plot.style_linebr,
color=color.new(color.purple, 0), title=' Lower Band')
//plot(showbb=='BB'?ta.sma(close,20):showbb=='Keltner'?ta.sma(close,20):na,
style=plot.style_linebr, color=color.new(color.purple, 0), title=' Middle Band')
a = plot(squeeze and showbbsqueeze? bbUpper : na, style=plot.style_linebr,
color=bar_index ? na : color.new(color.white, 0), title='Squeezed Upper Band')
b = plot(squeeze and showbbsqueeze? bbLower : na, style=plot.style_linebr,
color=bar_index ? na : color.new(color.white, 0), title='Squeezed Lower Band')
fill(a, b, color=color.new(color.purple, 90), title='Bollinger Squeezed Area')
//////////
///////////////Multi Time Frame EMA
mtf1 = input.timeframe(title="EMA MTF1", defval="", group='Settings: EMA')
mtf2 = input.timeframe(title="EMA MTF2", defval="", group='Settings: EMA')
ma_length1 = input(20, title = "EMA Period-1", group='Settings: EMA')
ma_length2 = input(50, title = "EMA Period-2", group='Settings: EMA')
ma1 = request.security(syminfo.tickerid, mtf1, ta.ema(close,
ma_length1),barmerge.gaps_on)
color1=open>ma1?color.new(#00FF00,60):open<ma1?
color.new(#00FF00,60):color.new(color.gray,0)
pl1 = plot(showmtfma?ma1:showbb=='BB'?bbMiddle:showbb=='Keltner'?bbMiddle:na,
title="MTF EMA-1", color=showmtfma and ma1?color1:color.purple , linewidth=1,
offset=0)
cci()=>
ccilength = input.int(40, minval=1,title='CCI Length',group='CCI')
ccisrc = input(hlc3, title="CCI Source",group='CCI')
ccima = ta.sma(ccisrc, ccilength)
cci = (ccisrc - ccima) / (0.015 * ta.dev(ccisrc, ccilength))
ccibg= cci>100?1:cci<-100?-1:0
[ccibg]
sto()=>
OverBought = input(80,title='Stochastic OverBought Level',group='stochastic')
OverSold = input(20,title='Stochastic OverBought Level',group='stochastic')
k = ta.sma(ta.stoch(close, high, low, input.int(14, minval=1,title='Stochastic
Length',group='stochastic')), input.int(3, minval=1,title='Stochastic Smooth Length
K',group='stochastic'))
d = ta.sma(k, input.int(3, minval=1,title='Stochastic Deviation Length
D',group='stochastic'))
co = ta.crossover(k,d)
cu = ta.crossunder(k,d)
sup=k > OverBought or cu and k > OverBought
sdn=k < OverSold or co and k < OverSold
stobg=sup?1:sdn?-1:co?2:cu?-2:0
[stobg]
start = input.float(title="PSAR Start", step=0.001, defval=0.02, group="PSAR")
increment = input.float(title="PSAR Increment", step=0.001, defval=0.02,
group="PSAR")
maximum = input.float(title="PSAR Maximum", step=0.01, defval=0.2, group="PSAR")
psar = ta.sar(start, increment, maximum)
psarDir = psar < close ? 1 : -1
colorPSAR = psarDir == 1 ? color.new(#00c3ff,0) : color.new(#ff0062,0) //color_bar
exitsig = close > upperk and close > BBMC ? color.new(#00c3ff,0) : close < lowerk
and close < BBMC? color.new(#ff0062,0) :color.new(color.gray,0)
qqedot=Greenbar1 and Greenbar2 and waeBuy? color.new(#00c3ff,0) : Redbar1 and
Redbar2 and waeSell?color.new(#ff0062,0):color.new(color.gray,0)
table.cell(ssltable, 0, 6, text='Supertrend',
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
table.cell(ssltable, 1, 6, text='Above/Below',
text_color=color.new(color.white, 0), text_size=size.small,bgcolor=sttrend)
///TABLE STRENGTH
sslstrength=psarn + exitsign + qqedotn +waen+ adxcoln + emacoln + sto + rs+
cc+stval
strengthcol=sslstrength>strengthtreshold?color.new(#00c3ff,0) :sslstrength<-
1*strengthtreshold ?color.new(#ff0062,0):color.new(color.gray,0)
var strengthtable = table.new(position.top_center, 2, 15, border_width = 3,bgcolor
= color.new(color.black,0), border_color=color.new(#333333,0))
if barstate.islast
if showtable2
table.cell(strengthtable, 0, 0, text='Strength',
text_color=color.new(color.white, 0), text_size=size.normal)
table.cell(strengthtable, 1, 0, text='Up/Down',
text_color=color.new(color.white, 0), text_size=size.normal)
table.cell(strengthtable, 0, 1, text='10',
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
table.cell(strengthtable, 1, 1, text=str.tostring(sslstrength),
text_color=color.new(color.white, 0), text_size=size.small,bgcolor=strengthcol)
table.cell(strengthtable, 0, 2, text='Signals',
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
table.cell(strengthtable, 1, 2, text=str.tostring(sslsignals),
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
table.cell(strengthtable, 0, 3, text='Filter',
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
table.cell(strengthtable, 1, 3, text=str.tostring(strend),
text_color=color.new(color.white, 0),
text_size=size.small,bgcolor=color.new(color.gray,0))
alertcondition(signalup or signaldn,title='FILTER:Buy/Sell
Alert',message='FILTER:TREND FILTER Buy/Sell Alert')
alertcondition(signalup ,title='FILTER:Buy Alert',message='FILTER:TREND FILTER- Buy
Alert')
alertcondition(signaldn,title='FILTER:Sell Alert',message='FILTER:TREND FILTER-
Sell Alert')
///////////////////SUPPORT RESISTANCE//////////////////////////
prd = input.int(defval=10, title='Pivot Period', minval=4, maxval=30, group='S/R
Settings')
ppsrc = input.string(defval='High/Low', title='Source', options=['High/Low',
'Close/Open'], group='S/R Settings')
maxnumpp = input.int(defval=20, title=' Maximum Number of Pivot', minval=5,
maxval=100, group='S/R Settings')
ChannelW = input.int(defval=10, title='Maximum Channel Width %', minval=1,
group='S/R Settings')
maxnumsr = input.int(defval=5, title=' Maximum Number of S/R', minval=1, maxval=10,
group='S/R Settings')
min_strength = input.int(defval=2, title=' Minimum Strength', minval=1, maxval=10,
group='S/R Settings')
labelloc = input.int(defval=20, title='Label Location', group='S/R Settings',
tooltip='Positive numbers reference future bars, negative numbers reference
histical bars')
linestyle = input.string(defval='Solid', title='Line Style', options=['Solid',
'Dotted', 'Dashed'], group='S/R Settings')
linewidth = input.int(defval=1, title='Line Width', minval=1, maxval=4, group='S/R
Settings')
resistancecolor = input.color(defval=color.new(color.red,0), title='Resistance
Color', group='S/R Settings')
supportcolor = input.color(defval=color.new(color.lime,0), title='Support Color',
group='S/R Settings')
if ph or pl
array.unshift(pivotvals, ph ? ph : pl)
if array.size(pivotvals) > maxnumpp // limit the array size
array.pop(pivotvals)
get_sr_vals(ind) =>
if showsr==true
float lo = array.get(pivotvals, ind)
float hi = lo
int numpp = 0
for y = 0 to array.size(pivotvals) - 1 by 1
float cpp = array.get(pivotvals, y)
float wdth = cpp <= lo ? hi - cpp : cpp - lo
if wdth <= cwidth // fits the max channel width?
lo := cpp <= lo ? cpp : lo
hi := cpp > lo ? cpp : hi
numpp += 1
numpp
[hi, lo, numpp]
find_loc(strength) =>
ret = array.size(sr_strength)
for i = ret > 0 ? array.size(sr_strength) - 1 : na to 0 by 1
if strength <= array.get(sr_strength, i)
break
ret := i
ret
ret
for x = 1 to 10 by 1
rate = 100 * (label.get_y(array.get(sr_labels, x)) - close) / close
label.set_text(array.get(sr_labels, x),
text=str.tostring(label.get_y(array.get(sr_labels, x))) + '(' + str.tostring(rate,
'#.##') + '%)')
label.set_x(array.get(sr_labels, x), x=bar_index + labelloc)
label.set_color(array.get(sr_labels, x), color=label.get_y(array.get(sr_labels,
x)) >= close ? color.new(color.red,0) : color.new(color.lime,0))
label.set_textcolor(array.get(sr_labels, x),
textcolor=label.get_y(array.get(sr_labels, x)) >= close ?
color.new(color.white,0) : color.new(color.black,0))
label.set_style(array.get(sr_labels, x), style=label.get_y(array.get(sr_labels,
x)) >= close ? label.style_label_down : label.style_label_up)
line.set_color(array.get(sr_lines, x), color=line.get_y1(array.get(sr_lines,
x)) >= close ? resistancecolor : supportcolor)
if ph or pl
//because of new calculation, remove old S/R levels
array.clear(sr_up_level)
array.clear(sr_dn_level)
array.clear(sr_strength)
//find S/R zones
for x = 0 to array.size(pivotvals) - 1 by 1
[hi, lo, strength] = get_sr_vals(x)
if check_sr(hi, lo, strength)
loc = find_loc(strength)
// if strength is in first maxnumsr sr then insert it to the arrays
if loc < maxnumsr and strength >= min_strength
array.insert(sr_strength, loc, strength)
array.insert(sr_up_level, loc, hi)
array.insert(sr_dn_level, loc, lo)
// keep size of the arrays = 5
if array.size(sr_strength) > maxnumsr
array.pop(sr_strength)
array.pop(sr_up_level)
array.pop(sr_dn_level)
for x = 1 to 10 by 1
line.delete(array.get(sr_lines, x))
label.delete(array.get(sr_labels, x))
f_crossed_over() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] <= mid and close > mid
ret := true
ret
ret
f_crossed_under() =>
ret = false
for x = 0 to array.size(sr_up_level) > 0 ? array.size(sr_up_level) - 1 : na by
1
float mid = math.round_to_mintick((array.get(sr_up_level, x) +
array.get(sr_dn_level, x)) / 2)
if close[1] >= mid and close < mid
ret := true
ret
ret
alertcondition(f_crossed_over(), title='S/R:Resistance Broken', message='Resistance
Broken')
alertcondition(f_crossed_under(), title='S/R:Support Broken', message='Support
Broken')