PROTECTED SOURCE SCRIPT
ที่อัปเดต:

Trend Indicator (Advanced Multi-Filter Swing)

94
//version=6
indicator("Trend Indicator (Advanced Multi-Filter Swing)", overlay=true)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS — MA ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ma_type = input.string('EMA', 'MA Type',
['ALMA','HMA','SMA','SWMA','VWMA','WMA','ZLEMA','EMA'], group='Setup')
ma_period = input.int(9, 'MA Period', minval=1, group='Setup')

alma_offset = input.float(0.85, 'ALMA Shift', 0, 1, 0.05, group='ALMA')
alma_sigma = input.int(6, 'ALMA Deviation', minval=1, group='ALMA')

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS — SIGNAL LOGIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
momentumThreshold = input.int(25, "Momentum Threshold (Confirm)", group="Signal Logic")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS — NOISE FILTERS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
useSlopeFilter = input.bool(true, "Stronger Slope Filter", group="Noise Filters")
useVolatility = input.bool(true, "ATR Volatility Filter", group="Noise Filters")
useRangeFilter = input.bool(true, "Dead-Zone Filter", group="Noise Filters")
useBarFilter = input.bool(true, "Bar Structure Filter", group="Noise Filters")
useHTFProxy = input.bool(true, "HTF Proxy Slope Filter", group="Noise Filters")

deadZone = input.int(8, "Dead-Zone Value", group="Noise Filters")
atrLen = input.int(14, "ATR Length", group="Noise Filters")
atrMaLen = input.int(20, "ATR MA Length", group="Noise Filters")
htfProxyLen = input.int(6, "HTF Proxy Slope EMA Length", group="Noise Filters")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS — ADX / DI FILTERS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
useADX = input.bool(true, "Use ADX Filter", group="ADX / DI Filter")
useDI = input.bool(true, "Use DI+/DI− Filter", group="ADX / DI Filter")

adxLen = input.int(14, "ADX Length", group="ADX / DI Filter")
adxMin = input.int(20, "Minimum ADX", group="ADX / DI Filter")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS — RSI FILTER
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
useRSI = input.bool(true, "Use RSI Filter", group="RSI Filter")
rsiLen = input.int(14, "RSI Length", group="RSI Filter")
rsiMid = input.int(50, "RSI Midline", group="RSI Filter")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FUNCTIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_ma(x) =>
switch ma_type
'ALMA' => ta.alma(x, ma_period, alma_offset, alma_sigma)
'HMA' => ta.hma(x, ma_period)
'SMA' => ta.sma(x, ma_period)
'SWMA' => ta.swma(x)
'VWMA' => ta.vwma(x, ma_period)
'WMA' => ta.wma(x, ma_period)
'ZLEMA' => ta.ema(x + x - x[math.floor((ma_period - 1) / 2)], ma_period)
=> ta.ema(x, ma_period)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HEIKIN-ASHI MA ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ha_open = f_ma(request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open))
ha_close = f_ma(request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close))
ha_high = f_ma(request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high))
ha_low = f_ma(request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low))

trend = 100 * (ha_close - ha_open) / (ha_high - ha_low)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// COLORS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bull = input.color(#26A69A, "Bullish", group="Colors")
bear = input.color(#EF5350, "Bearish", group="Colors")
neutral = input.color(#808080, "Neutral", group="Colors")

trendColor = trend > 0 ? bull : bear

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VISUALS — TREND INDICATOR A
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pOpen = plot(ha_open, display=display.none)
pClose = plot(ha_close, color=trendColor, linewidth=2)
pHigh = plot(ha_high, display=display.none)
pLow = plot(ha_low, display=display.none)

pHighBody = plot(math.max(ha_open, ha_close), display=display.none)
pLowBody = plot(math.min(ha_open, ha_close), display=display.none)

fill(pOpen, pClose, color.new(trendColor, 50))
fill(pHigh, pHighBody, color.new(neutral, 87))
fill(pLowBody, pLow, color.new(neutral, 87))

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FILTER CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
trendSlope = trend - trend[1]
slopeStrong = math.abs(trendSlope) > math.abs(trendSlope[1])

bullSlopeOK = trendSlope > 0
bearSlopeOK = trendSlope < 0

atr = ta.atr(atrLen)
atrMA = ta.sma(atr, atrMaLen)
volatilityOK = atr > atrMA

rangeOK = math.abs(trend) > deadZone

bullBar = close > open
bearBar = close < open

proxySlope = ta.ema(trendSlope, htfProxyLen)
proxyBullOK = proxySlope > 0
proxyBearOK = proxySlope < 0

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ADX / DI FILTERS (Pine v6 FINAL FIX)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[diPlus, diMinus, adxVal] = ta.dmi(adxLen, adxLen)

adxOK = adxVal > adxMin
diBullOK = diPlus > diMinus
diBearOK = diMinus > diPlus

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// RSI FILTER
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
rsiVal = ta.rsi(close, rsiLen)
rsiBullOK = rsiVal > rsiMid
rsiBearOK = rsiVal < rsiMid

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TWO-STAGE · ONE-SIGNAL-PER-SWING LOGIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
baseBull = ta.crossover(trend, 0)
baseBear = ta.crossunder(trend, 0)

earlyBull =
baseBull
and (not useSlopeFilter or (bullSlopeOK and slopeStrong))
and (not useVolatility or volatilityOK)
and (not useRangeFilter or rangeOK)
and (not useBarFilter or bullBar)
and (not useHTFProxy or proxyBullOK)
and (not useADX or adxOK)
and (not useRSI or rsiBullOK)
and (not useDI or diBullOK)

earlyBear =
baseBear
and (not useSlopeFilter or (bearSlopeOK and slopeStrong))
and (not useVolatility or volatilityOK)
and (not useRangeFilter or rangeOK)
and (not useBarFilter or bearBar)
and (not useHTFProxy or proxyBearOK)
and (not useADX or adxOK)
and (not useRSI or rsiBearOK)
and (not useDI or diBearOK)

confirmBull = trend > 0 and math.abs(trend) > momentumThreshold
confirmBear = trend < 0 and math.abs(trend) > momentumThreshold

var int swingDir = 0
var bool confirmed = false

earlyBUY = earlyBull and swingDir != 1
earlySELL = earlyBear and swingDir != -1

if earlyBUY
swingDir := 1
confirmed := false
else if earlySELL
swingDir := -1
confirmed := false

confirmedBUY = swingDir == 1 and not confirmed and confirmBull
confirmedSELL = swingDir == -1 and not confirmed and confirmBear

if confirmedBUY or confirmedSELL
confirmed := true

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL PLOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(earlyBUY, "BUY Early", shape.triangleup,
location=location.belowbar, size=size.tiny, color=bull, text="BUY")

plotshape(earlySELL, "SELL Early", shape.triangledown,
location=location.abovebar, size=size.tiny, color=bear, text="SELL")

plotshape(confirmedBUY, "BUY Confirmed", shape.labelup,
location=location.belowbar, color=bull, text="BUY✔")

plotshape(confirmedSELL, "SELL Confirmed", shape.labeldown,
location=location.abovebar, color=bear, text="SELL✔")
เอกสารเผยแพร่
This Pine Script (v6) is a sophisticated Trend-Following indicator that uses Heikin-Ashi candles processed through various moving averages to filter out "market noise." Instead of just looking at price, it looks at the momentum and quality of the trend. Here is the breakdown of the logic and how the interface works. 1. The Core Logic: The "HA Engine" The heart of the script isn't just a standard Moving Average (MA). It calculates a synthetic trend based on Heikin-Ashi (HA) data. Heikin-Ashi Smoothing: It takes the Open, High, Low, and Close of HA candles and applies your chosen Moving Average (e.g., EMA, ALMA, or ZLEMA) to them. The Trend Formula: It calculates a "Trend Score": $$100 \times \frac{HA_{Close} - HA_{Open}} {HA_{High} - HA_{Low}} $$What this does: This creates a value between -100 and +100. If the body of the smoothed HA candle is large relative to its wicks, the trend is considered strong. 2. The Multi-Filter "Gauntlet" The script is designed to be "picky." It won't show a signal unless several conditions are met simultaneously (if you have them enabled): Slope Filter: Ensures the trend is actually accelerating (getting steeper). Volatility (ATR) Filter: Only signals when the current ATR is higher than its average (ensuring there is enough "juice" in the move). Dead-Zone Filter: Ignores small, choppy movements near the zero line. HTF Proxy: Uses an EMA of the slope to act as a "higher time frame" confirmation to ensure you aren't trading against the primary momentum. ADX/DI Filter: Uses the Average Directional Index to ensure a trend exists (ADX > 20$) and that the correct Directional Index (DI+$ or DI-$) is on top. RSI Filter: Confirms the price is on the correct side of the 50-midline. 3. Two-Stage Signal System The script uses a "Swing Direction" logic to prevent signal spamming: Early Signal (BUY/SELL): Triggered when the Trend Score crosses zero and passes all the filters. This marks the start of a potential new swing. Confirmed Signal (BUY✔/SELL✔): This appears after an early signal once the trend score exceeds your momentum threshold (default 25). It's the "validation" that the move has real strength. 4. The Interface (User Inputs) When you open the settings, you'll see these sections: Setup & MA Engine Type: Change how the smoothing is calculated. ZLEMA (Zero Lag) is fast, while ALMA (Arnaud Legoux) is very smooth with less lag than a standard SMA. MA Period: The "speed" of the indicator. Lower = faster/more signals; higher = slower/more reliable. Noise Filters (The "On/Off" Switches) This is where you customize the strategy. If you find the indicator is too quiet, uncheck things like "ATR Volatility" or "Bar Structure." If you are getting whipsawed (fakeouts), enable "Stronger Slope Filter" or "Use ADX Filter." Visuals The Ribbon: The script fills the area between the smoothed HA open and close. Green Ribbon: Bullish trend. Red Ribbon: Bearish trend. Labels: "BUY/SELL": This is the aggressive entry. "BUY ✔/SELL ✔": This is the conservative, momentum-confirmed entry. How to use this effectively: Because this uses Heikin-Ashi data and multiple filters, it is a lagging indicator by design. It is best used in trending markets (Forex pairs during London/NY sessions or high-volume stocks). Pro- Tip: If the ribbon is very thin or flipping colors frequently, the "Dead-Zone Filter" or "ADX Filter" will save you from taking trades in a sideways market

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน