You are on page 1of 3

//@version=4

// srflip2011

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

study(title="Cryptonite's Ema Field", resolution="", overlay=true)


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)

Periods = input(title="ATR Period", type=input.integer, defval=10)


src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool,
defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr,
linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute,
style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy",
location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green,
textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.red,
transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell",
location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red,
textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) :
color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) :
color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend
has changed direction!")

You might also like