OPEN-SOURCE SCRIPT

Advanced Technical Analysis with Cumulative Delta

90
//version=5
indicator("Advanced Technical Analysis with Cumulative Delta", overlay=true)
This declares the script as a version 5 indicator.
The title is what appears in TradingView's indicator list.
overlay=true means it plots directly on the price chart (e.g., lines for moving averages) rather than in a separate pane.
2. Input Parameters
pinescript
smaLength = input.int(100, title="SMA Length")
emaLength = input.int(1000, title="EMA Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought")
rsiOversold = input.int(30, title="RSI Oversold")
vwmoLength = input.int(20, title="VWMO Length")
adxLength = input.int(14, title="ADX Length")
obvLength = input.int(20, title="OBV Length")
obvDivergenceLookback = input.int(10, title="OBV Divergence Lookback")
stochLength = input.int(14, title="Stoch Length")
stochD = input.int(3, title="Stoch D")
stochOverbought = input.int(80, title="Stoch Overbought")
stochOversold = input.int(20, title="Stoch Oversold")
cciLength = input.int(14, title="CCI Length")
cciOverbought = input.int(100, title="CCI Overbought")
cciOversold = input.int(-100, title="CCI Oversold")
atrLength = input.int(14, title="ATR Length")
moneyFlowLength = input.int(14, title="Money Flow Length")
volSmaLength = input.int(20, title="Vol SMA Length")
These are user-configurable inputs using input.int() for integer values.
They define periods (lengths) and thresholds (e.g., overbought/oversold levels) for various indicators.
Examples: rsiLength sets the RSI calculation period (default 14 bars), rsiOverbought sets the upper threshold (default 70).
3. Display Options
pinescript
showMomentumScore = input.bool(true, title="Show Momentum Score")
showAdx = input.bool(true, title="Show ADX")
showDetailedLabels = input.bool(true, title="Show Detailed Labels")
showObv = input.bool(true, title="Show OBV")
showStoch = input.bool(true, title="Show Stoch")
showCci = input.bool(true, title="Show CCI")
showAtr = input.bool(true, title="Show ATR")
showMoneyFlow = input.bool(true, title="Show Money Flow")
showVolumeAnalysis = input.bool(true, title="Show Volume Analysis")
showCumulativeDelta = input.bool(true, title="Show Cumulative Delta")
Boolean inputs (input.bool()) to toggle visibility of specific metrics in the dashboard or on the chart.
This allows users to customize the display to avoid clutter.
4. Moving Averages
pinescript
SMA100 = ta.sma(close, smaLength)
EMA1000 = ta.ema(close, emaLength)

// Daily VWAP
varip float cumVol = 0.0
varip float cumPriceVol = 0.0
if ta.change(time("D")) != 0
cumVol := 0.0
cumPriceVol := 0.0
cumVol += volume
cumPriceVol += close * volume
VWAP_Day = cumPriceVol / cumVol

plot(SMA100, color=color.new(color.gray, 0), linewidth=2)
plot(EMA1000, color=color.new(color.blue, 0), linewidth=2)
plot(VWAP_Day, color=color.new(color.yellow, 0), linewidth=2)
Calculates Simple Moving Average (SMA) and Exponential Moving Average (EMA) using TradingView's ta library.
VWAP (Volume-Weighted Average Price) is reset daily: It accumulates volume and price*volume each bar, resetting on new days (ta.change(time("D")) detects day changes).
These are plotted as lines on the chart with custom colors and widths.
5. Oscillators
This section computes various momentum and volume-based oscillators.
RSI:
pinescript
rsi = ta.rsi(close, rsiLength)
Relative Strength Index measures price momentum (0-100 scale).
VWMO (Volume-Weighted Momentum Oscillator):
pinescript
volumeWeightedPrice = close * volume
vwmaCurrent = math.sum(volumeWeightedPrice, vwmoLength) / math.sum(volume, vwmoLength)
vwmaPast = math.sum(volumeWeightedPrice[vwmoLength], vwmoLength) / math.sum(volume[vwmoLength], vwmoLength)
vwmo = (vwmaCurrent - vwmaPast) / vwmaPast * 100
Custom oscillator: Compares current vs. past Volume-Weighted Moving Average (VWMA) to gauge volume-adjusted momentum.
ADX & DMI:
pinescript
[diPlus, diMinus, adx] = ta.dmi(adxLength, adxLength)
Average Directional Index (ADX) measures trend strength; Directional Movement Index (DMI) shows direction (+DI for up, -DI for down).
OBV (On-Balance Volume):
pinescript
obvRaw = ta.obv
obv = ta.sma(obvRaw, obvLength)
obvSlope = obv - obv[5]
obvRising = obvSlope > 0
obvFalling = obvSlope < 0
OBV tracks cumulative volume based on price direction. Smoothed with SMA, and slope checks if it's rising/falling over 5 bars.
Cumulative Delta:
pinescript
cumDelta = ta.obv
cumDeltaChange = cumDelta - cumDelta[1]
cumDeltaRising = cumDelta > cumDelta[1]
cumDeltaFalling = cumDelta < cumDelta[1]
cumDeltaMA = ta.sma(cumDelta, 20)

plot(showCumulativeDelta ? cumDelta : na, color=color.new(color.orange, 0), linewidth=2)
plot(showCumulativeDelta ? cumDeltaMA : na, color=color.new(color.yellow, 0), style=plot.style_line)
Uses OBV as proxy for Cumulative Delta (net buying/selling volume). Plots the raw value and its 20-period SMA if toggled.
Stochastic:
pinescript
fastK = ta.stoch(close, high, low, stochLength)
stochFullK = ta.sma(fastK, stochD)
stochFullD = ta.sma(stochFullK, stochD)
Stochastic oscillator compares closing price to high-low range. Smoothed with SMAs for %K and %D lines.
CCI (Commodity Channel Index):
pinescript
cci = ta.cci(close, cciLength)
Measures deviation from typical price.
MFI (Money Flow Index):
pinescript
mfi = ta.mfi(hlc3, moneyFlowLength)
mfiBullish = mfi > 50
mfiBearish = mfi < 50
mfiOverbought = mfi > 80
mfiOversold = mfi < 20
Volume-weighted RSI variant using typical price (hlc3 = (high + low + close)/3).
6. ATR & Volatility
pinescript
atr = ta.atr(atrLength)
atrAvg = ta.sma(atr, 20)
highVolatility = atr > atrAvg * 1.5
lowVolatility = atr < atrAvg * 0.5
volatilityRatio = math.round((atr / atrAvg) * 100)
Average True Range (ATR) measures volatility. Compared to its 20-period SMA to classify high/low volatility.
7. Volume Analysis
pinescript
volSma = ta.sma(volume, volSmaLength)
volRatio = volume / volSma
highVolume = volume > volSma * 1.5
lowVolume = volume < volSma * 0.5
extremeVolume = volRatio > 2
normalVolume = volRatio >= 0.5 and volRatio <= 1.5
Compares current volume to its SMA to detect high/low/extreme volume.
8. Price Action Signals
pinescript
bullishCandle = close > open
bearishCandle = close < open
candleSize = math.abs(close - open)
avgCandleSize = ta.sma(candleSize, 20)
largeCandleBody = candleSize > avgCandleSize * 1.5
strongBullishCandle = bullishCandle and largeCandleBody and highVolume
strongBearishCandle = bearishCandle and largeCandleBody and highVolume
Identifies candle types (bullish/bearish) and strength based on body size and volume.
9. Trend Analysis
pinescript
priceAboveAll = close > SMA100 and close > EMA1000 and close > VWAP_Day
priceBelowAll = close < SMA100 and close < EMA1000 and close < VWAP_Day
priceVsVWAP = close > VWAP_Day
Checks if price is above/below all key averages for trend direction.
10. Enhanced Momentum Conditions
pinescript
bullishMomentum = rsi > 50 and vwmo > 0 and stochFullK > 50 and cci > 0 and mfiBullish and cumDeltaRising
bearishMomentum = rsi < 50 and vwmo < 0 and stochFullK < 50 and cci < 0 and mfiBearish and cumDeltaFalling
strongTrend = adx > 25
veryStrongTrend = adx > 40
Combines multiple oscillators (including Cumulative Delta) for overall momentum. ADX thresholds define trend strength.
11. Directional Movement
pinescript
bullishDMI = diPlus > diMinus
bearishDMI = diMinus > diPlus
Uses DMI to confirm directional bias.
12. OBV Divergence
pinescript
priceHigherHigh = high > ta.highest(high[1], obvDivergenceLookback)
priceLowerLow = low < ta.lowest(low[1], obvDivergenceLookback)
obvHigherHigh = obv > ta.highest(obv[1], obvDivergenceLookback)
obvLowerLow = obv < ta.lowest(obv[1], obvDivergenceLookback)
obvBearishDiv = priceHigherHigh and not obvHigherHigh and close > SMA100
obvBullishDiv = priceLowerLow and not obvLowerLow and close < SMA100
Detects divergences: Price making higher highs/lows but OBV not confirming, signaling potential reversals.
13. Comprehensive Trend Classification
pinescript
bullishTrend = priceAboveAll and bullishMomentum and strongTrend and bullishDMI and obvRising
bearishTrend = priceBelowAll and bearishMomentum and strongTrend and bearishDMI and obvFalling
strongBullish = bullishTrend and veryStrongTrend and rsi > rsiOverbought and vwmo > 1
strongBearish = bearishTrend and veryStrongTrend and rsi < rsiOversold and vwmo < -1
Aggregates conditions for overall trend labels (e.g., bullish if price, momentum, trend strength, DMI, and OBV align).
14. Weakness/Strength Detection
pinescript
weaknessAtHigh = obvBearishDiv or (priceAboveAll and obvFalling and rsi > 70) or mfiOverbought
strengthAtLow = obvBullishDiv or (priceBelowAll and obvRising and rsi < 30) or mfiOversold
Flags hidden weaknesses (e.g., overbought with falling OBV) or strengths (e.g., oversold with rising OBV).
15. Advanced Momentum Scoring
pinescript
priceScore = priceAboveAll ? 50 : priceBelowAll ? 0 : 25
rsiScore = rsi > rsiOverbought ? 25 : rsi < rsiOversold ? 0 : rsi > 50 ? 15 : 5
vwmoScore = vwmo > 1 ? 25 : vwmo < -1 ? 0 : vwmo > 0 ? 15 : 5
adxScore = adx > 40 ? 20 : adx > 25 ? 10 : 0
stochScore = stochFullK > stochOverbought ? 20 : stochFullK < stochOversold ? 0 : stochFullK > 50 ? 12 : 4
cciScore = cci > cciOverbought ? 20 : cci < cciOversold ? 0 : cci > 0 ? 12 : 4
mfiScore = mfi > 80 ? 15 : mfi < 20 ? 0 : mfi > 50 ? 10 : 3
volScore = highVolatility ? 10 : lowVolatility ? 0 : 5
cumDeltaScore = cumDeltaRising ? 15 : cumDeltaFalling ? 0 : 8

momentumScore = priceScore + rsiScore + vwmoScore + adxScore + stochScore + cciScore + mfiScore + volScore + cumDeltaScore

marketBias = momentumScore > 155 ? 5 : momentumScore > 115 ? 4 : momentumScore < 45 ? 1 : momentumScore < 75 ? 2 : 3
Assigns points to each indicator based on conditions (e.g., higher scores for bullish signals).
Total momentumScore (max 200) determines marketBias (1=strong bear, 5=strong bull).
16. Dashboard Table
pinescript
var table dashboard = table.new(position.top_right, columns=1, rows=30, border_width=0, frame_width=0)

if barstate.islast
row = 0

// ... (code for adding cells to the table)

Wyłączenie odpowiedzialności

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.