You are on page 1of 4

//@version=4

// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © colinmck

study("QQEMAMOYA signals", overlay=true)

RSI_Period = input(14, title='RSI Length')


SF = input(5, title='RSI Smoothing')
QQE = input(4.238, title='Fast QQE Factor')
ThreshHold = input(10, title="Thresh-hold")

src = close
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

// Find all the QQE Crosses

QQExlong = 0
QQExlong := nz(QQExlong[1])
QQExshort = 0
QQExshort := nz(QQExshort[1])
QQExlong := FastAtrRsiTL < RSIndex ? QQExlong + 1 : 0
QQExshort := FastAtrRsiTL > RSIndex ? QQExshort + 1 : 0

//Conditions

qqeLong = QQExlong == 1 ? FastAtrRsiTL[1] - 50 : na


qqeShort = QQExshort == 1 ? FastAtrRsiTL[1] - 50 : na

// Plotting

plotshape(qqeLong, title="QQE long", text="Long", textcolor=color.white,


style=shape.labelup, location=location.belowbar, color=color.green, transp=0,
size=size.tiny)
plotshape(qqeShort, title="QQE short", text="Short", textcolor=color.white,
style=shape.labeldown, location=location.abovebar, color=color.red, transp=0,
size=size.tiny)
// Alerts

alertcondition(qqeLong, title="Long", message="Long")


alertcondition(qqeShort, title="Short", message="Short")

//@version=4
// srflip2011

// Ema Crossover Alerts are setup with Ema 1 & Ema 2

source = close
TITLE = input(false, title="Turn on Alerts & Enable Background Color options are
based on EMA1 & EMA2 Crossovers, (This button does nothing)")
turnon2 = input(true, title="Turn on Alerts?")
turnon = input(true, title="Turn on Ema 1 & 2?")
backgroundcolor = input(false, title="Enable Background Color?")

//Ema 1 & 2
len1 = input(10, minval=1, title="EMA1")
len2 = input(21, minval=1, title="EMA2")
ema1 = ema(source, len1)
ema2 = ema(source,len2)
//Ema 3
turnon3 = input(false, title="Turn on EMA3?")
len3 = input(5, minval=1, title="EMA3")
ema3 = ema(source, len3)
plot(turnon3 ? ema3 : na, "Ema 3", style=plot.style_line, linewidth=2,
color=color.blue)

//Ema 4
turnon4 = input(false, title="Turn on EMA4")
len4 = input(8, minval=1, title="EMA4")
ema4 = ema(source, len4)
plot(turnon4 ? ema4 : na, "Ema 4", style=plot.style_line, linewidth=2,
color=color.orange)

//Ema 5
turnon5 = input(false, title="Turn on EMA5?")
len5 = input(34, minval=1, title="EMA5")
ema5 = ema(source, len5)
plot(turnon5 ? ema5 : na, "Ema 5", style=plot.style_line, linewidth=2,
color=color.yellow)

//Ema 6
turnon6 = input(false, title="Turn on EMA6?")
len6 = input(55, minval=1, title="EMA6")
ema6 = ema(source, len6)
plot(turnon6 ? ema6 : na, "Ema 6", style=plot.style_line, linewidth=2,
color=color.purple)

//Ema 7
turnon7 = input(false, title="Turn on EMA7?")
len7 = input(89, minval=1, title="EMA7")
ema7 = ema(source, len7)
plot(turnon7 ? ema7 : na, "Ema 7", style=plot.style_line, linewidth=2,
color=color.fuchsia)
//Ema 8
turnon8 = input(false, title="Turn on EMA8?")
len8 = input(144, minval=1, title="EMA8")
ema8 = ema(source, len8)
plot(turnon8 ? ema8 : na, "Ema 8", style=plot.style_line, linewidth=2,
color=color.teal)

// Ema 9
turnon9 = input(false, title="Turn on EMA9?")
len9 = input(200, minval=1, title="EMA9")
ema9 = ema(source, len9)
plot(turnon9 ? ema9 : na, "Ema 9", style=plot.style_line, linewidth=2,
color=color.aqua)

// Ema Cross
mylong = crossover(ema1, ema2)
myshort = crossunder(ema1, ema2)

first = ema(close, len1)


sec = ema(close, len2)

// Calculations
last_long = float(na)
last_short = float(na)
last_long := mylong ? time : nz(last_long[1])
last_short := myshort ? time : nz(last_short[1])

in_long = last_long > last_short ? 2 : 0


in_short = last_short > last_long ? 2 : 0

condlongx = in_long
condlong = crossover(condlongx, 1.9)
condlongclose = crossunder(condlongx, 1.9)

condshortx = in_short
condshort = crossover(condshortx, 1.9)
condshortclose = crossover(condshortx, 1.9)

// Color Fill
fcolor = first > sec ? #0aff68 : first < sec ? #ff0a5a : #cccccc

// Ema Output
F1 = plot(turnon ? first : na, color=fcolor ,linewidth=2)
S2 = plot(turnon ? sec : na, color=fcolor, linewidth=2)
fill(F1, S2, title="Channel Fill", color=fcolor, transp=60)

// Plots
plotshape(turnon2 ? condlong : na, title="Breakout", color=#112f16,
location=location.belowbar, style=shape.labelup, text="Breakout",
textcolor=color.white, transp=0, size=size.small, offset=1)
plotshape(turnon2 ? condshort : na, title="Breakdown", color=#9d0d0d,
style=shape.labeldown, text="Breakdown", textcolor=color.white, transp=0,
size=size.small, offset=1)

// Alerts Ema 1 & 2 Crossover & Crossunder


alertcondition(condlong, "Breakout")
alertcondition(condshort, "Breakdown")

// Background Color
bgcolor(backgroundcolor ? fcolor : na, transp=67)

You might also like