Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Buy Sell Signal On 100 Sma Ema

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

//@version=4

// @ SpiffyRumble
study(title="EMA SMA 100 Cross", overlay=true, max_labels_count=500)

// === INPUTS ===


maExpSource = input(defval=close, title="EMA Source")
maExpLength = input(defval=100, title="EMA Period", minval=1)
maSimpSource = input(defval=close, title="SMA Source")
maSimpLength = input(defval=100, title="SMA Period", minval=1)

// === FUNCTIONS ===


maExp = ema(maExpSource, maExpLength)
maSimp = sma(maSimpSource, maSimpLength)
fastSma = sma(close, 5)
mediumSma = sma(close, 50)
slowSma = sma(close, 200)
bullishCross = crossover(maExp, maSimp)
bearishCross = crossunder(fastSma, mediumSma)
bullishCrossFast = crossover(fastSma, mediumSma)
bearishCrossFast = crossunder(fastSma, mediumSma)
fastBullCross = crossover(fastSma, slowSma)
fastBearCross = crossunder(fastSma, slowSma)

// === PLOTTING ===


ema = plot(maExp, title="EMA", color=color.green, linewidth=1,
style=plot.style_line, transp=0)
sma = plot(maSimp, title="SMA", color=color.blue, linewidth=1,
style=plot.style_line, transp=0)
slSma = plot(slowSma, title="Slow SMA", color=color.purple, linewidth=1,
style=plot.style_line, transp=0)
medSma = plot(mediumSma, title="Medium SMA", color=color.yellow, linewidth=1,
style=plot.style_line, transp=0)
faSma = plot(fastSma, title="Fast SMA", color=color.red, linewidth=1,
style=plot.style_line, transp=0)

// === LABELS ===


var longLabel = label.new(x=na, y=na, yloc=yloc.abovebar,
color=color.green, textcolor=color.new(color.white, 0),
size=size.normal, style=label.style_labeldown)

var shortLabel = label.new(x=na, y=na, yloc=yloc.belowbar,


color=color.red, textcolor=color.new(color.white, 0),
size=size.normal, style=label.style_labelup)

var profitLabelLong = label.new(x=na, y=na, yloc=yloc.abovebar,


color=color.blue, textcolor=color.new(color.white, 0),
size=size.normal, style=label.style_labeldown)

var profitLabelShort = label.new(x=na, y=na, yloc=yloc.belowbar,


color=color.blue, textcolor=color.new(color.white, 0),
size=size.normal, style=label.style_labelup)

// Make a label for Bullish signal

if bullishCross and mediumSma>slowSma and fastSma>mediumSma


// Make label
longLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,
style=label.style_labeldown, color=color.new(color.green, 0),
text="Buy", textcolor=color.white)

if bullishCrossFast and maSimp>slowSma and maExp>maSimp and mediumSma>maExp

longLabel := label.new(x=bar_index, y=na,yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.green, 0),
text="Buy", textcolor=color.white)

if bullishCrossFast

longLabel := label.new(x=bar_index, y=na,yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.green, 0),
text="Buy", textcolor=color.white)

if fastBullCross and close>fastSma

longLabel := label.new(x=bar_index, y=na,yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.green, 0),
text="Buy", textcolor=color.white)

// Make a label for Bearish signal

if bearishCross and maSimp>slowSma and maExp>slowSma and mediumSma>maSimp and


mediumSma>maExp

// Make label
shortLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,
style=label.style_labeldown, color=color.new(color.red, 0),
text="Sell", textcolor=color.white)

if fastBullCross and close<open and close<slowSma

shortLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.red, 0),
text="Sell", textcolor=color.white)

if bearishCrossFast

shortLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.red, 0),
text="Sell", textcolor=color.white)

if fastBearCross

shortLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,


style=label.style_labeldown, color=color.new(color.red, 0),
text="Sell", textcolor=color.white)

// Make a label for long and short profit


leftbars = input(10, minval=1, title='Bars to the left')
rightbars = input(2, minval=1, title='Bars to the right')

phigh = pivothigh(high, leftbars,rightbars)


plow = pivotlow(low, leftbars, rightbars)
if phigh and maExp>maSimp and open>slowSma and close>slowSma
label1 = label.new(bar_index[rightbars], high[rightbars], text="Take\nProfit",
style=label.style_labeldown, color=color.blue, textcolor=color.white)

//if plow and maExp<maSimp and open<maSimp and open< maExp and close<maExp
//label2 = label.new(bar_index[rightbars], low[rightbars], text="Take\nProfit",
style=label.style_labelup, color=color.blue, textcolor=color.white)

// === FILL ==== \\


fill(faSma, medSma, color=fastSma > mediumSma ? color.red : color.gray, transp=65)
fill(medSma, ema, color=mediumSma > maExp ? color.yellow : color.gray, transp=65)
fill(ema, sma, color=maExp > maSimp ? color.green : color.gray, transp=65)
fill(sma, slSma, color=maSimp > slowSma ? color.purple : color.gray, transp=65)

You might also like