OPEN-SOURCE SCRIPT

Andra Algo

231
//version=5
indicator(title="Andra Algo V 1.2", shorttitle="Andra Algo V1.2", overlay=true)

// =====================
// INPUT
// =====================
src = input(defval=close, title="Source")
per = input.int(defval=100, minval=1, title="Sampling Period")
mult = input.float(defval=3.0, minval=0.1, title="Range Multiplier")

// =====================
// COLOR SET
// =====================
buyLineColor = color.white
sellLineColor = color.blue
midColor = #90bff9

buyBgColor = color.new(color.gray, 20)
sellBgColor = color.new(color.blue, 20)

// =====================
// SMOOTH RANGE
// =====================
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
ta.ema(avrng, wper) * m

smrng = smoothrng(src, per, mult)

// =====================
// RANGE FILTER
// =====================
rngfilt(x, r) =>
rf = x
rf := x > nz(rf[1]) ?
(x - r < nz(rf[1]) ? nz(rf[1]) : x - r) :
(x + r > nz(rf[1]) ? nz(rf[1]) : x + r)
rf

filt = rngfilt(src, smrng)

// =====================
// TREND DIRECTION
// =====================
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])

// =====================
// MID LINE COLOR
// =====================
filtColor = upward > 0 ? buyLineColor : downward > 0 ? sellLineColor : midColor
plot(filt, title="Mid Line", color=filtColor, linewidth=2)

// =====================
// BUY & SELL CONDITIONS
// =====================
longCond = src > filt and upward > 0
shortCond = src < filt and downward > 0

CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]

longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1

// =====================
// SIGNALS (FIXED BG COLOR)
// =====================
plotshape(longCondition, title="Buy Signal", text="BUY", style=shape.labelup, location=location.belowbar, size=size.small, textcolor=color.white, color=buyBgColor)
plotshape(shortCondition, title="Sell Signal", text="SELL", style=shape.labeldown, location=location.abovebar, size=size.small, textcolor=color.white, color=sellBgColor)

// =====================
// ALERTS
// =====================
alertcondition(longCondition, title="Buy Alert", message="Andra Algo V1.2 BUY")
alertcondition(shortCondition, title="Sell Alert", message="Andra Algo V1.2 SELL")

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.