Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

//@version=4

//
study("PMS_SR")
RSI_Period = input(6, title='RSI Length')
SF = input(5, title='RSI Smoothing')
QQE = input(3, title='Fast QQE Factor')
ThreshHold = input(3, title="Thresh-hold")
//
src = input(close, title="RSI Source")
Wilders_Period = RSI_Period * 2 - 1
Rsi = rsi(src, RSI_Period)
RsiMa = ema(Rsi, SF)
AtrRsi = abs(RsiMa[1] - RsiMa)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
dar = 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] ?
max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ?
min(shortband[1], newshortband) : newshortband
cross_1 = cross(longband[1], RSIndex)
trend := cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband

length = input(50, minval=1, title="Bollinger Length")


mult = input(0.35, minval=0.001, maxval=5, step=0.1, title="BB Multiplier")
basis = sma(FastAtrRsiTL - 50, length)
dev = mult * stdev(FastAtrRsiTL - 50, length)
upper = basis + dev
lower = basis - dev
color_bar = RsiMa - 50 > upper ? #00c3ff : RsiMa - 50 < lower ? #ff0062 :
color.gray

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')
SF2 = input(5, title='RSI Smoothing')
QQE2 = input(1.61, title='Fast QQE2 Factor')
ThreshHold2 = input(3, title="Thresh-hold")
src2 = input(close, title="RSI Source")
//
Wilders_Period2 = RSI_Period2 * 2 - 1
Rsi2 = rsi(src2, RSI_Period2)
RsiMa2 = ema(Rsi2, SF2)
AtrRsi2 = abs(RsiMa2[1] - RsiMa2)
MaAtrRsi2 = ema(AtrRsi2, Wilders_Period2)
dar2 = 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] ?
max(longband2[1], newlongband2) : newlongband2
shortband2 := RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] ?
min(shortband2[1], newshortband2) : newshortband2
cross_2 = cross(longband2[1], RSIndex2)
trend2 := 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.silver :
RsiMa2 - 50 < 0 - ThreshHold2 ? color.silver : na

Greenbar1 = RsiMa2 - 50 > ThreshHold2


Greenbar2 = RsiMa - 50 > upper
Redbar1 = RsiMa2 - 50 < 0 - ThreshHold2
Redbar2 = RsiMa - 50 < lower
hline (0, color=color.white, linestyle=hline.style_dotted, linewidth=1)

//rsi
lenrs = input(14, minval=1, title="Length")
srcrrs = input(close, "Source", type = input.source)
uprs = rma(max(change(srcrrs), 0), lenrs)
downrs = rma(-min(change(srcrrs), 0), lenrs)
rsirs = downrs == 0 ? 100 : uprs == 0 ? 0 : 100 - (100 / (1 + uprs / downrs))
rsich = rsirs -50

upperBand1 = input(0, "RSI U Band", minval=50, maxval=100)


lowerBand1 = input(-20, "RSI L Band", maxval=50, minval=0)
h31 = hline(upperBand1, linestyle=hline.style_dotted, color=#606060)
h32 = hline(lowerBand1, linestyle=hline.style_dotted, color=#606060)

fill(h31, h32, color=#9915FF, transp=85)


colch = rsich > upperBand1 ? color.green : rsich < upperBand1 ? #c2185b :
color.yellow
plot(rsich, "RSI", linewidth=2, color=colch)

//MACD
src1 = hlc3

fastLength = input(9, minval=1)


slowLength = input(25,minval=1)
signalLength = input(5,minval=1)
fastMA = ema(src1, fastLength)
slowMA = ema(src1, slowLength)
macd = fastMA - slowMA
signal = sma(macd, signalLength)
hist = (macd - signal) * 2

CloudPokeB = crossover(macd,signal)
CloudPokeS = crossunder(macd,signal)
plotshape(CloudPokeB and macd <0 and hist>0 , color=color.green ,
style=shape.square, size=size.tiny,
location=location.bottom,transp=0,size=size.auto)
plotshape(CloudPokeB and macd >0 and hist>0 , color=color.blue,style=shape.square,
size=size.tiny, location=location.top,transp=0,size=size.auto)
plotshape(CloudPokeS and macd <0 and hist<0, color=color.red,style=shape.circle,
size=size.tiny, location=location.bottom,transp=0,size=size.auto)
plotshape(CloudPokeS and macd >0 and hist<0, color=color.red,style=shape.circle,
size=size.tiny, location=location.top,transp=0,size=size.auto)

//hull
hull=input(title="Hull period",defval=55)
n2ma=2*wma(close,round(hull/2))
nma=wma(close,hull)
diff=n2ma-nma
sqn=round(sqrt(hull))
n2ma1=2*wma(close[1],round(hull/2))
nma1=wma(close[1],hull)
diff1=n2ma1-nma1
sqn1=round(sqrt(hull))
nhull1=wma(diff,sqn)
nhull2=wma(diff1,sqn)
chull=nhull1>nhull2?color.green:color.red

//sar1
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
out = sar(start, increment, maximum)

shortSAR = out < close


longSAR = out > close
SARColor = iff(shortSAR, color.green, iff(longSAR, color.red, color.white))

//MA
lengthma = input(20, minval=1)
srcma = input(close, title="Source")
basisma = ema(srcma, lengthma)

//LifeTime = iff(SARColor == color.green and macd > signal and close > basisma,
color.green, iff(SARColor == color.red and macd < signal and close < basisma,
color.red, color.black))
LifeTime = iff(SARColor == color.green and chull == color.green and Greenbar1 and
Greenbar2 == 1 ? RsiMa2 - 50 : na and macd > signal and close > basisma,
color.green, iff(SARColor == color.red and chull == color.red and Redbar1 and
Redbar2 == 1 ? RsiMa2 - 50 : na and macd < signal and close < basisma, color.red,
color.black))
r3y1 = plot(-30, color=na)
r3y2 = plot(-35, color=na)
fill( r3y1, r3y2, color=LifeTime, transp=20)
lapos_x = timenow + round(change(time)*3)
_text = iff(LifeTime == color.green, ". BUY", iff(LifeTime == color.red , ".
SELL", ". REVERCE"))
f_draw_label(x,y,_text,_textcolor, _size)=>
var label Label = na
label.delete(Label)
Label := label.new(x, y, _text, color=color.new(color.white, 20),
textcolor=_textcolor, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_time,
size=_size)

f_draw_label(lapos_x,-35,_text, color.black, size.normal)

// stochastic
kcolor = #0094FF
dcolor = #FF6A00
// Input
upperBand = input(30, "Upper Band", minval=50, maxval=100)
lowerBand = input(-30, "Lower Band", maxval=50, minval=0)
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
srcst = input(close, title="RSI Source")
lengthRSIst = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
k_mode = input("SMA", "K Mode", options=["SMA", "EMA", "WMA"])
// Calculation
rsist = rsi(srcst, lengthRSIst)
stoch = stoch(rsist, rsist, rsist, lengthStoch)
k =
k_mode=="EMA" ? ema(stoch, smoothK) :
k_mode=="WMA" ? wma(stoch, smoothK) :
sma(stoch, smoothK)
kk = k-50
d = sma(k, smoothD)
dd = d-50
k_c = change(k)
d_c = change(d)
kd = k - d
// Visualization
h0 = hline(upperBand, "Upper Band", color=#606060)
h1 = hline(lowerBand, "Lower Band", color=#606060)
fill(h0, h1, color=#9915FF, transp=95, title="Band Background")
signalColor = kk>lowerBand and dd<upperBand and kk>dd and k_c>0 and d_c>0 ?
kcolor :
kk<upperBand and dd>lowerBand and kk<dd and k_c<0 and d_c<0 ? dcolor : na
kp = plot(kk, "K", color=kcolor, linewidth=1)
dp = plot(dd, "D", color=dcolor, linewidth=1)

You might also like