OPEN-SOURCE SCRIPT

Andra Algo

215
//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")

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.