Simple Algooo
Simple Algooo
Simple Algooo
// Setting
showsignals = input(title='Show Buy & Sell', defval=true, group = 'Buy And Sell
SIgnals [AlgoPoInt]')
sensitivity = input.int(title='Sensitivity (1-15)', defval=7, minval = 1, maxval =
15, group = 'Buy And Sell SIgnals [AlgoPoInt]') + 1
Periods = sensitivity * 10
src = hl2
Multiplier = sensitivity / 2
changeATR = true
highlighting = false
atr2 = ta.sma(ta.tr, Periods)
atr = changeATR ? ta.atr(Periods) : atr2
up = src - Multiplier * atr
up1 = nz(up[1], up)
up := close[1] > up1 ? math.max(up, up1) : up
dn = src + Multiplier * atr
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.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
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal and showsignals ? up : na, title='Buy', text='Buy Signal▲',
location=location.absolute, style=shape.labelup, size=size.normal, color=#00ff00,
textcolor=color.new(color.black, 0))
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell Signal▼',
location=location.absolute, style=shape.labeldown, size=size.normal, color=#ff0000,
textcolor=color.new(color.white, 0))
// Candle Coloring
// Input
fastLength = 25
slowLength = 55
signalLength = 9
// Data reference
[macd, signal, hist] = ta.macd(src, fastLength, slowLength, signalLength)
// 4 level of green
greenHigh = #05df09
greenMidHigh = #05df09
greenMidLow = #05df09
greenLow = #673ab7
// Yellow
yellowLow = #673ab7
// 4 level of red
redHigh = #673ab7
redMidHigh = #ea0402
redMidLow = #ea0402
redLow = #ea0402
// Default color
candleBody = yellowLow
// Ranging trend
if hist > 0
if hist > hist[1] and hist[1] > 0
candleBody := greenLow
if hist < 0
if hist < hist[1] and hist[1] < 0
candleBody := redLow
// Bullish trend
if macd > 0 and hist > 0
candleBody := greenMidLow
// Bearish trend
if macd < 0 and hist < 0
candleBody := redMidLow
// Smart Trail
// inputs //
//{
trailType = 'modified'
ATRPeriod = 13
ATRFactor = 4
smoothing = 8
Up = norm_c - loss
Dn = norm_c + loss
TrendUp = Up
TrendDown = Dn
Trend = 1
ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]
//}
fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6
// Reversal Band
//func
kama(src, len) =>
kama = 0.0
sum_1 = math.sum(math.abs(src - src[1]), len)
sum_2 = math.sum(math.abs(src - src[1]), len)
kama := nz(kama[1]) + math.pow((sum_1 != 0 ? math.abs(src - src[len]) / sum_2 :
0) * (0.288 - 0.0666) + 0.0666, 2) * (src - nz(kama[1]))
kama
//inputs
length = 2
bd1 = 2
bd2 = 3
bd3 = 4
smoothingband = 12
//logic
rg = kama(ta.tr, length)
basis = kama(close, length)
upper1 = basis + rg * bd1
upper2 = basis + rg * bd2
upper3 = basis + rg * bd3
lower1 = basis - rg * bd1
lower2 = basis - rg * bd2
lower3 = basis - rg * bd3
upper1ema = ta.dema2(upper1,smoothingband)
upper2ema = ta.dema2(upper2,smoothingband)
upper3ema = ta.dema2(upper3,smoothingband)
lower1ema = ta.dema2(lower1,smoothingband)
lower2ema = ta.dema2(lower2,smoothingband)
lower3ema = ta.dema2(lower3,smoothingband)
//ploting
p1 = plot(show_rev ? upper1ema : na, transp=100)
p2 = plot(show_rev ? upper2ema : na, transp=100)
p3 = plot(show_rev ? upper3ema : na, transp=100)
p4 = plot(show_rev ? lower1ema : na, transp=100)
p5 = plot(show_rev ? lower2ema : na, transp=100)
p6 = plot(show_rev ? lower3ema : na, transp=100)
fill(p1, p2, color=color.new(#ff0015, 85))
fill(p2, p3, color=color.new(#dc0000, 50))
fill(p4, p5, color=color.new(#21f945, 85))
fill(p5, p6, color=color.new(#30ff30, 50))
bull = buySignal
bear = sellSignal
trigger2 = bull ? 1 : 0
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
currentposition = countBull > countBear ? 'Sell' : 'Buy'
stop_y = lastTrade(atrStop)
stop = levels ? label.new(time, close, "Stop Loss: " + str.tostring(stop_y,
decimals), xloc.bar_time, yloc.price, #fe000070, label.style_label_left,
color.white, size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop[1])
// Trend Follower
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 22, 6)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(close, smrng)
//
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])