Best Buy-Sell Indicator

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

//@version=3

study(shorttitle="Best Buy and Sell", title="Best_Buy and Sell",


overlay=true)

// === INPUTS ===

// Bollinger Bands Inputs


bb_use_ema = input(false, title="Use EMA for Bollinger Band")
bb_length = input(42, minval=1, title="Bollinger Length")
bb_source = input(close, title="Bollinger Source")
bb_mult = input(2.0, title="Base Multiplier", minval=0.5, maxval=10)
// EMA inputs
fast_ma_len = input(10, title="Fast EMA length", minval=2)
// Awesome Inputs
nLengthSlow = input(77, minval=1, title="Awesome Length Slow")
nLengthFast = input(10, minval=1, title="Awesome Length Fast")

// === /INPUTS ===

// Breakout Indicator Inputs


bb_basis = bb_use_ema ? ema(bb_source, bb_length) : sma(bb_source,
bb_length)
fast_ma = ema(bb_source, fast_ma_len)

// Deviation
// * I'm sure there's a way I could write some of this cleaner, but meh.
dev = stdev(bb_source, bb_length)
bb_dev_inner = bb_mult * dev

// Upper bands
inner_high = bb_basis + bb_dev_inner
// Lower Bands
inner_low = bb_basis - bb_dev_inner

// Calculate Awesome Oscillator


xSMA1_hl2 = sma(hl2, nLengthFast)
xSMA2_hl2 = sma(hl2, nLengthSlow)
xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
// Calculate direction of AO
AO = xSMA1_SMA2>=0? xSMA1_SMA2 > xSMA1_SMA2[1] ? 1 : 2 : xSMA1_SMA2 >
xSMA1_SMA2[1] ? -1 : -2

// Deternine if we are currently LONG


isLong = false
isLong := nz(isLong[1], false)

// Determine if we are currently SHORT


isShort = false
isShort := nz(isShort[1], false)
// Buy only if the buy signal is triggered and we are not already long
LONG = not isLong and (crossover(fast_ma, bb_basis) and close > bb_basis
and abs(AO)==1)
c_green = (fast_ma > bb_basis)

// Sell only if the sell signal is triggered and we are not already short
SHORT= not isShort and (crossunder(fast_ma, bb_basis) and close <
bb_basis and abs(AO)==2)
c_red = (fast_ma < bb_basis)

if (LONG)
isLong := true
isShort := false

barcolor(LONG? green: na)

if (SHORT)
isLong := false
isShort := true

barcolor(c_green ? green : na)


barcolor(c_red ? red : na)

// Show Break Alerts


plotshape(SHORT, title="Sell", style=shape.labeldown,
location=location.abovebar, size=size.normal, text="Sell", transp=0,
textcolor = white, color=red, transp=0)
plotshape(LONG, title="Buy", style=shape.labelup,
location=location.belowbar, size=size.normal, text="Buy", textcolor =
white, color=green, transp=0)

// === /PLOTTING ===

// Send alert to TV alarm sub-system


alertcondition(LONG,title="Buy",message="Buy")
alertcondition(LONG,title="Buy",message="Buy")
alertcondition(LONG,title="Buy",message="Buy")
alertcondition(SHORT,title="Sell",message="Sell")

// eof

You might also like