Indicator · Pine Script v5 · Own pane

Directional Flow Oscillator

by jawauntb

The Directional Flow Oscillator combines momentum, cumulative volume delta, price range position, trend ratio, and relative volatility into a single bounded composite indicator.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code125
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

125 lines of Pine Script v5 from dfo-version-alpha.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

dfo-version-alpha.pine
//@version=5
indicator("Directional Flow Oscillator", 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)

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

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

Overview

Directional Flow Oscillator fetches lower-timeframe volume data to calculate cumulative volume delta and normalizes all components over a rolling 100-bar window. The oscillator is displayed in a separate pane along with its 13-period and 33-period simple moving averages for trend smoothing.

Details

Published by

jawauntb on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volume, Trend, 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

6 stars

Capital41 Fusion Oscillator v3 measures multi-condition market confluence in a separate pane with a smoothed composite score ranging from 0 to 100. It evaluates four criteria: EMA trend direction, RSI oversold or overbought turns, Williams %R thresholds, and A

Indicator v6 Oscillators & momentumTrend
Updated 8 weeks ago · MIT GitHub repository of Capital41 Fusion Oscillator v3

Faith JL

by g-moe
3 stars

This indicator evaluates market sentiment and momentum using Aroon crossovers, intra-bar buy and sell volume estimation, and an ATR-based calculation. It generates modular buy and sell conditions filtered by volume thresholds, percentage bands, and Aroon signa

Indicator v5 VolumeTrend
Updated 5 months ago · None stated GitHub repository of Faith JL

DEPV2 A8 · Onay Makinesi

by YuceSezar89
1 stars

This indicator implements a multi-metric confirmation engine that validates trading signals across four core dimensions: trend level scores based on an HLC3 SMA, momentum z-scores derived from rate of change, volatility expansion ratios comparing fast and slow

Indicator v6 TrendOscillators & momentum
Updated 11 days ago · None stated GitHub repository of DEPV2 A8 · Onay Makinesi

RSI-ADI-Combo

by DT021
1 stars

This indicator combines the Average Directional Index (ADX) for trend strength, Money Flow Index (MFI) for volume flow analysis, and Relative Strength Index (RSI) for momentum signals. The ADX is plotted as colored columns with background coloring indicating u

Indicator v4 TrendOscillators & momentum
Updated 6 years ago · GPL-3.0 GitHub repository of RSI-ADI-Combo
1 stars

The XAUUSD Scalping Confluence Engine is a separate-pane indicator that calculates a composite trading score based on multiple technical factors. It evaluates a four-period exponential moving average stack, SuperTrend trend direction, Relative Strength Index,

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · None stated GitHub repository of XAUUSD Scalping Confluence Engine

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

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