Indicator · Pine Script v5 · Own pane

DFO 3

by jawauntb

DFO 3 plots a directional flow oscillator in a separate pane.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code156
Settings4inputs
LicenceGPL-3.0
Last update2 years ago22 May 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

156 lines of Pine Script v5 from Best-directional-flow-oscillator-3.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Best-directional-flow-oscillator-3.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jawauntb

//@version=5
indicator("DFO 3", overlay=false)

// Inputs
rsiPeriod = input(14, "RSI Period")
emaPeriod = input(13, "EMA Period")
maPeriod = input(30, "MA Period")
vwapSource = input(hlc3, "VWAP Source")

// Composite Index
rsiSource = close
rsiDelta = ta.rsi(rsiSource, rsiPeriod) - ta.rsi(rsiSource, rsiPeriod)[9]
rsiSma = ta.sma(ta.rsi(rsiSource, 3), 3)
compIndex = rsiDelta + rsiSma

// CVD Volume
[upVolumes, dnVolumes] = request.security_lower_tf(syminfo.tickerid, "1", [volume, volume])
float totalUpVolume = nz(upVolumes.sum())
float totalDnVolume = nz(dnVolumes.sum())
float maxUpVolume = nz(upVolumes.max())
float maxDnVolume = nz(dnVolumes.min())
float totalVolume = totalUpVolume - totalDnVolume
float delta = totalUpVolume + totalDnVolume
float deltaPct = delta / totalVolume
var float cvd = 0.0
cvd := cvd + delta

// EMA and MA
ema13 = ta.ema(close, emaPeriod)
ma30 = ta.sma(close, maPeriod)

// VWAP
vwap = ta.vwap(vwapSource)

// RVI
length = 10
src = close
stdDevSrc = ta.stdev(src, length)
upperStdDev = ta.change(src) <= 0 ? 0 : stdDevSrc
lowerStdDev = ta.change(src) > 0 ? 0 : stdDevSrc
upper = ta.ema(upperStdDev, length)
lower = ta.ema(lowerStdDev, length)
rvi = upper / (upper + lower) * 100

// Momentum component
momentumLength = 100
momentumMin = ta.lowest(compIndex, momentumLength)
momentumMax = ta.highest(compIndex, momentumLength)
momentumValue = (compIndex - momentumMin) / (momentumMax - momentumMin) * 100
momentumDelta = momentumValue - momentumValue[3]
momentumComponent = momentumValue + momentumDelta

// Volume component
volumeLength = 100
volumeMin = ta.lowest(cvd, volumeLength)
volumeMax = ta.highest(cvd, volumeLength)
volumeValue = (cvd - volumeMin) / (volumeMax - volumeMin) * 100
volumeDelta = volumeValue - volumeValue[3]
volumeComponent = volumeValue + volumeDelta

// Price component
priceLength = 100
priceMin = ta.lowest(low, priceLength)
priceMax = ta.highest(high, priceLength)
priceValue = (close - priceMin) / (priceMax - priceMin) * 100
priceDelta = priceValue - priceValue[3]
priceComponent = priceValue + priceDelta

// Trend component
trendLength = 100
trendMin = ta.lowest((ema13 - ma30) / ma30, trendLength)
trendMax = ta.highest((ema13 - ma30) / ma30, trendLength)
trendValue = ((ema13 - ma30) / ma30 - trendMin) / (trendMax - trendMin) * 100
trendDelta = trendValue - trendValue[3]
trendComponent = trendValue + trendDelta

// Combine components
directionalFlowOscillator = (momentumComponent + volumeComponent + priceComponent + trendComponent + rvi) / 5

// Plot the oscillator and moving averages
plot(directionalFlowOscillator, color=color.rgb(166, 232, 247), linewidth=3)
plot(ta.sma(directionalFlowOscillator, 13), color=color.rgb(255, 225, 0), linewidth=2)
plot(ta.sma(directionalFlowOscillator, 33), color=color.rgb(186, 19, 19), linewidth=2)

// Function to plot individual condition confirmations or breaks
plotCondition(series, condition, labelTrue, labelFalse, yOffset) =>
    var label myLabel = na
    labelText = condition ? labelTrue : labelFalse
    labelColor = condition ? color.new(color.green, 0) : color.new(color.red, 0)
    
    // Detect changes in the condition value
    conditionChanged = ta.change(condition)
    
    if conditionChanged or barstate.islast
        if (na(myLabel))
            myLabel := label.new(x=time, y=series + yOffset, text=labelText, style=label.style_label_down, color=labelColor, size=size.small, textcolor=color.white, xloc=xloc.bar_time, yloc=yloc.price)
        else
            label.set_xy(myLabel, x=time, y=series + yOffset)
            label.set_text(myLabel, text=labelText)
            label.set_color(myLabel, color=labelColor)
            label.set_textcolor(myLabel, color.white)
    myLabel

atrl = ta.atr(14)

// Calculate the difference between the fast and middle moving averages
fastMA = ta.sma(directionalFlowOscillator, 13)
middleMA = ta.sma(directionalFlowOscillator, 33)
diff = fastMA - middleMA

// Normalize the difference to a value between -1 and 1
normalizedDiff = diff / (ta.highest(diff, 100) - ta.lowest(diff, 100))

// Check and plot each condition separately
// Momentum Conditions
plotCondition(directionalFlowOscillator, momentumComponent > 50, "Momentum: Bullish", "Momentum: Bearish", atrl*3.5)

// Volume Conditions
plotCondition(directionalFlowOscillator, volumeComponent > 50, "Volume: Bullish", "Volume: Bearish", atrl*3)

// Price Conditions
plotCondition(directionalFlowOscillator, priceComponent > 50, "Price: Bullish", "Price: Bearish", atrl*2.5)

// Trend Conditions
plotCondition(directionalFlowOscillator, trendComponent > 50, "Trend: Bullish", "Trend: Bearish", atrl*2)

// Define bullish or bearish conditions based on the oscillator
bullishCondition = ta.crossover(directionalFlowOscillator, ta.sma(directionalFlowOscillator, 13))
bearishCondition = ta.crossunder(directionalFlowOscillator, ta.sma(directionalFlowOscillator, 13))

// Improved Color Function based on Trend Direction and Strength
colorFromTrend(diff) =>
    normalizedIntensity = math.abs(diff) * 100 // Normalizing the difference
    // normalizedIntensity := math.min(100, math.max(0, normalizedIntensity))
    // Defining color based on trend direction
    if diff > 0
        // Bullish Trend: Increasing green intensity based on the strength
        color.new(color.green, 100 - normalizedIntensity)
    else if diff < 0
        // Bearish Trend: Increasing red intensity based on the strength
        color.new(color.red, 100 - normalizedIntensity)
    else
        // Neutral Trend: Representing with a yellow color to indicate uncertainty or weak trend
        color.yellow

// Applying the improved color function
trendColor = colorFromTrend(normalizedDiff)

bgcolor(trendColor, title="Directional Flow Background", offset=-1)

// Assuming the overlay is true and you want to color the chart background:
bgcolor(bullishCondition ? color.new(#01ff09, 90) : na, title="Bullish Background", offset=-1)
bgcolor(bearishCondition ? color.new(#ff0000, 90) : na, title="Bearish Background", offset=-1)

Overview

DFO 3 averages five normalized components: a composite RSI momentum index, a cumulative volume delta built from one-minute volume, a price position over a 100-bar range, an EMA-versus-SMA trend spread, and a relative volatility index. The RSI, EMA, and moving-average lengths and the VWAP source are adjustable, though the visible code calculates VWAP without using it in the average. The script draws the oscillator plus 13-period and 33-period simple moving averages and defines no entries, exits, or stops.

Details

Published by

jawauntb on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volume, Moving averages, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
RSI Periodint14rsiPeriod
EMA Periodint13emaPeriod
MA Periodint30maPeriod
VWAP Sourcesourcehlc3vwapSource
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

PPO ATR Bands

by cryptorife
75 stars

PPO ATR Bands plots a percentage price oscillator in a separate pane. It compares a Hull average of typical price with a volume-weighted exponential average of Parabolic SAR, then scales three true-range bands around the slow average into matching oscillator l

Indicator v4 Oscillators & momentumMoving averages
Updated 3 years ago · GPL-3.0 GitHub repository of PPO ATR Bands

NFI v6

by koradiyakaushal
12 stars

This Pine v4 study ports early NostalgiaForInfinity V6 conditions onto the price chart. It computes two Bollinger setups, several EMAs and SMAs, RSI, MFI, a percent SMA spread labeled EWO, a 14-period choppiness value, and short and longer volume medians. Fixe

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · MIT GitHub repository of NFI v6

Koncord + MACD

by Following-BTC
5 stars

This indicator combines the Koncorde oscillator with a traditional Moving Average Convergence Divergence (MACD) indicator in a separate pane. It calculates Koncorde using a mixture of the Relative Strength Index (RSI), Money Flow Index (MFI), Bollinger Bands o

Indicator v5 Oscillators & momentumVolume
Updated 2 years ago · None stated GitHub repository of Koncord + MACD
3 stars

Buy Low Sell High Composite is a pane oscillator that normalizes RSI, a short-versus-long EMA difference, the MACD histogram, and the Money Flow Index onto a shared scale, then sums them into one composite. It plots that composite as a colored area, the MACD s

Indicator v5 Oscillators & momentumMoving averages
Updated 5 months ago · None stated GitHub repository of Buy Low Sell High Composite

RedK EVEREX v2.0

by bigzhu
2 stars

The RedK EVEREX v2.0 indicator examines effort versus results by plotting normalized bands comparing price change to volume. It computes rate of flow using selectable moving averages with smoothing options, and applies lookback averaging to highlight anomalies

Indicator v5 Moving averagesVolume
Updated 3 months ago · None stated GitHub repository of RedK EVEREX v2.0

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers