Indicator · Pine Script v6 · Own pane

Open Interest Stochastic Money Flow Index

by theonetrade

Calculates a Stochastic oscillator applied to an Open Interest Money Flow Index (OIMFI) and plots it in a separate chart pane.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code185
Settings5inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

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

185 lines of Pine Script v6 from assets/indicator/bit-exact/open_interest_stochastic_money_flow_index_L55eyyDh.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

open_interest_stochastic_money_flow_index_L55eyyDh.pine
//@version=6
indicator('Open Interest Stochastic Money Flow Index')
src = close
reverse = false
lights = input.string(title = 'Barcolor I / 0 ? ', options = ['ON', 'OFF'], defval = 'OFF')
adaptive = input.string(title = 'Market Type ', options = ['FUTURES', 'OTHERS'], defval = 'FUTURES')

// Importing TradingView COT Library
import TradingView/LibraryCOT/3 as cot

//***** CFTC COT TV Codes *****

var string Root_Symbol = syminfo.root
var string CFTC_Code_fixed = cot.convertRootToCOTCode("Auto")
if Root_Symbol == "HG"
    CFTC_Code_fixed := "085692"
else if Root_Symbol == "LBR"
    CFTC_Code_fixed := "058644"

// Request COT data
dataRequest(metricName, direction) =>
    tickerId = cot.COTTickerid('Legacy', CFTC_Code_fixed, false, metricName, direction, "All")
    value = request.security(tickerId, "1D", close, ignore_invalid_symbol = true)
    if barstate.islastconfirmedhistory and na(value)
        runtime.error("Could not find relevant COT data based on the current symbol.")
    value

// 1 - Futures

// Futures Open Interest 

// Gets open interest to normalise data over time
getOpenInterest() =>
    openInterest = dataRequest("Open Interest", "No direction")

openInterest = getOpenInterest()

_oi_futures = openInterest

_vol_others = volume


// Switchable Weiss Wave Open Interest (Futures) / Weiss Wave Volume (Others)

float _switchable = na

if adaptive == 'FUTURES'

    _switchable := _oi_futures
    _switchable

if adaptive == 'OTHERS'

    _switchable := volume
    _switchable


// Open Interest Money Flow Index (OIMFI)


// Essential Functions : 

f_ema(_src, _length) =>
    _length_adjusted = _length < 1 ? 1 : _length
    _multiplier = 2 / (_length_adjusted + 1)
    _return = 0.00
    _return := na(_return[1]) ? _src : (_src - _return[1]) * _multiplier + _return[1]
    _return


f_sum(_src, _length) =>

    _output = 0.00

    _length_adjusted = _length < 1 ? 1 : _length

    for i = 0 to _length_adjusted - 1 by 1
        _output := _output + _src[i]
        _output


// FUNCTION HIGHEST AND LOWEST  ( All Efforts goes to RicardoSantos )

f_highest(_src, _length) =>
    _adjusted_length = _length < 1 ? 1 : _length
    _value = _src
    for _i = 0 to _adjusted_length - 1 by 1
        _value := _src[_i] >= _value ? _src[_i] : _value
        _value
    _return = _value
    _return

f_lowest(_src, _length) =>
    _adjusted_length = _length < 1 ? 1 : _length
    _value = _src
    for _i = 0 to _adjusted_length - 1 by 1
        _value := _src[_i] <= _value ? _src[_i] : _value
        _value
    _return = _value
    _return


t_mfi = input(14, title = 'MFI Period') // You can use non integer or mutable variables too !!

OverSold = input(20, title = 'Oversold') // You can use non integer or mutable variables too !!
OverBought = input(80, title = 'Overbought') // You can use non integer or mutable variables too !!

zero = 0
hundred = 100

limit = 50


upper_s = f_sum(_switchable * (ta.change(src) <= 0 ? 0 : src), t_mfi)
lower_s = f_sum(_switchable * (ta.change(src) >= 0 ? 0 : src), t_mfi)


_mfi = 100.0 - 100.0 / (1.0 + upper_s / lower_s)

// Open Interest Stochastic Money Flow Index 

lengthMFI = 14
lengthStoch = 14

smoothK = int(lengthMFI / 3)
smoothD = int(lengthStoch / 3)


f_stoch(_src, _length) =>

    100 * (_src - f_lowest(f_lowest(_src, 1), _length)) / (f_highest(f_highest(_src, 1), _length) - f_lowest(f_lowest(_src, 1), _length))


// Definition : Variables K3 and D

k3 = f_ema(f_stoch(_mfi, lengthStoch), smoothK)
d = f_ema(k3, smoothD)

pos_moment = ta.crossover(k3, d)
neg_moment = ta.crossunder(k3, d)

col_bg = pos_moment ? color.teal : neg_moment ? color.maroon : na


// Plot data

h1 = hline(OverSold, color = #C0C0C0, title = 'Oversold Level')
h2 = hline(OverBought, color = #C0C0C0, title = 'Overbought Level')
plot(k3, color = color.new(#0070FF, 0), title = 'K-line', linewidth = 1)
plot(d, color = color.new(#FF8C00, 0), title = 'D-line', linewidth = 1)
fill(h1, h2, color = color.new(#66023C, 90), title = 'Border')
bgcolor(col_bg, title = 'Background Color')
plot(pos_moment ? zero : na, style = plot.style_cross, color = color.new(color.green, 0), linewidth = 3, title = 'Crossover')
plot(neg_moment ? zero : na, style = plot.style_cross, color = color.new(color.red, 0), linewidth = 3, title = 'Crossunder')

// Barcolor (All efforts goes to Hpotter)

pos = k3 > d ? 1 : -1
iff_1 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_1


// Switchable Barcolor Preference 

_lights = 0.00
if lights == 'ON'

    _lights := 1.00
    _lights

if lights == 'OFF'

    _lights := -1.00
    _lights


bcolor_on = _lights == 1.00
bcolor_off = _lights == -1.00

barcolor(possig == -1 and bcolor_on ? color.red : possig == 1 and bcolor_on ? color.green : na)

// Alerts 

alertcondition(possig == 1, title = 'Buy Signal', message = 'Buy Signal ')
alertcondition(possig == -1, title = 'Sell Signal', message = 'Sell Signal ')

Overview

For futures symbols, the calculation incorporates Commitment of Traders (COT) open interest data fetched via security requests, while an adaptive setting allows switching to regular bar volume for other markets. The script computes upper and lower money flow sums, scales them into a Money Flow Index, and applies Stochastic smoothing to highlight overbought and oversold conditions.

Details

Published by

theonetrade on GitHub

Draws

Separate pane below the chart

Markets

Oil & commodities, Forex

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.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
Barcolor I / 0 ? stringOFFlights
Market Type stringFUTURESadaptive
MFI Periodint14t_mfi
Oversoldint20OverSold
Overboughtint80OverBought
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

Market Pressure Scale plots two oscillator curves in a separate pane. Setup pressure combines ATR and Bollinger compression, support and resistance proximity, and drying volume. Impulse pressure combines range expansion, volume, and candle body size. A range-c

Indicator v6 Oscillators & momentumVolatility & bands
Updated 4 weeks ago · MIT GitHub repository of Market Pressure Scale [WavesUnchained]

MTF Abnormal Price Zones

by InNoobWeTrust
4 stars

The MTF Abnormal Price Zones indicator identifies potential supply and demand zones across multiple timeframes. It detects abnormal volume activity relative to a customizable moving average threshold and applies an RSI momentum filter to validate signals. High

Indicator v6 VolumeSupport & resistance Repaints
Updated 3 weeks ago · None stated GitHub repository of MTF Abnormal Price Zones
3 stars

This indicator calculates multi-source analysis signals based on The Trading Parrot methodology, combining SOPR proxy calculations, custom volume-weighted RSI, liquidity support and resistance levels, volume spike detection, and pattern recognition. It outputs

Indicator v6 Oscillators & momentumVolume
Updated 1 year ago · Custom licence GitHub repository of Trading Parrot Multi-Source Analysis

Custom Oscillator

by danielbodnar
2 stars

This reference script provides practical Pine Script v6 code examples for creating custom indicators. It includes a smoothed Relative Strength Index oscillator plotted with overbought and oversold background zones, a multi-timeframe moving average overlay with

Indicator v6 Oscillators & momentumMoving averages
Updated 12 days ago · MIT GitHub repository of Custom Oscillator
1 stars

Order Flow & Market Profile Panel is a separate-pane indicator that aggregates intraday price and volume metrics into configurable timeframe columns. It renders a dynamic grid panel displaying bar time, volume delta, cumulative volume delta (CVD), Market Profi

Indicator v6 VolumeSupport & resistance
Updated 9 days ago · None stated GitHub repository of Order Flow & Market Profile Panel

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers