OPEN-SOURCE SCRIPT

MFI + Realtime Divergences

Updated
Money Flow Index (MFI) + Realtime Divergences + Alerts

This version of the MFI indicator adds the following 5 additional features to the stock MFI:

- Optional divergence lines drawn directly onto the oscillator in realtime.
- Configurable alerts to notify you when divergences occur.
- Configurable lookback periods to fine tune the divergences drawn in order to suit different trading styles and timeframes, including the ability to enable automatic adjustment of pivot period per chart timeframe.
- Background colouring option to indicate when the MFI oscillator has crossed above or below its centerline, or optionally when both the MFI has crossed its centerline and an external oscillator, which can be linked via the settings, has also crossed its centerline.
- Alternate timeframe feature allows you to configure the oscillator to use data from a different timeframe than the chart it is loaded on.


This indicator adds additional features onto the standard MFI , whose core calculations remain unchanged. Namely the configurable option to automatically, quickly and clearly draw divergence lines onto the oscillator for you as they occur in realtime. It also has the addition of unique alerts, so you can be notified when divergences occur without spending all day watching the charts. Furthermore, this version of the TSI comes with configurable lookback periods, which can be configured in order to adjust the sensitivity of the divergences, in order to suit shorter or higher timeframe trading approaches.


What is the Money Flow Index ( MFI )?

Investopedia describes the True Strength Indicator as follows:

“The Money Flow Index ( MFI ) is a technical oscillator that uses price and volume data for identifying overbought or oversold signals in an asset. It can also be used to spot divergences which warn of a trend change in price. The oscillator moves between 0 and 100.
Unlike conventional oscillators such as the Relative Strength Index ( RSI ), the Money Flow Index incorporates both price and volume data, as opposed to just price. For this reason, some analysts call MFI the volume-weighted RSI .”


What are divergences?

Divergence is when the price of an asset is moving in the opposite direction of a technical indicator, such as an oscillator, or is moving contrary to other data. Divergence warns that the current price trend may be weakening, and in some cases may lead to the price changing direction.

There are 4 main types of divergence, which are split into 2 categories;
regular divergences and hidden divergences. Regular divergences indicate possible trend reversals, and hidden divergences indicate possible trend continuation.

Regular bullish divergence: An indication of a potential trend reversal, from the current downtrend, to an uptrend.
Regular bearish divergence: An indication of a potential trend reversal, from the current uptrend, to a downtrend.
Hidden bullish divergence: An indication of a potential uptrend continuation.
Hidden bearish divergence: An indication of a potential downtrend continuation.


Setting alerts.

With this indicator you can set alerts to notify you when any/all of the above types of divergences occur, on any chart timeframe you choose.


Configurable pivot periods.

You can adjust the default pivot periods to suit your prefered trading style and timeframe. If you like to trade a shorter time frame, lowering the default lookback values will make the divergences drawn more sensitive to short term price action.


How do traders use divergences in their trading?

A divergence is considered a leading indicator in technical analysis , meaning it has the ability to indicate a potential price move in the short term future.

Hidden bullish and hidden bearish divergences, which indicate a potential continuation of the current trend are sometimes considered a good place for traders to begin, since trend continuation occurs more frequently than reversals, or trend changes.

When trading regular bullish divergences and regular bearish divergences, which are indications of a trend reversal, the probability of it doing so may increase when these occur at a strong support or resistance level . A common mistake new traders make is to get into a regular divergence trade too early, assuming it will immediately reverse, but these can continue to form for some time before the trend eventually changes, by using forms of support or resistance as an added confluence, such as when price reaches a moving average, the success rate when trading these patterns may increase.

Typically, traders will manually draw lines across the swing highs and swing lows of both the price chart and the oscillator to see whether they appear to present a divergence, this indicator will draw them for you, quickly and clearly, and can notify you when they occur.


Disclaimer: This script includes code from the stock MFI by Tradingview as well as the Divergence for Many Indicators v4 by LonesomeTheBlue.
Release Notes
-Added full indicator name, symbol info and timeframe to chart to comply with house rules.
-Presented on a naked chart to comply with house rules
-Trimmed whitespace at end of file
Release Notes
- Updated the screenshot to use Japanese candles instead of Heikin Ashi candles to comply with Tradingview rules
Release Notes
- Disabled the range bands by default
- Set the centerline to be dotted not dashed by default
Release Notes
- Corrected MFI to use hlc3 instead of close as its source
Release Notes
- Added a 'Flip oscillator' feature into the settings for use with the Tradingview 'Flip chart' (Alt+i) feature, so both the chart and the oscillators can be flipped upside down to help see the opposite scenario for traders who have too one-sided a bias.
- Added a fade out feature into the settings for the crossover dots and the oscillator itself, which optionally fades out all but the most recent section of the oscillator to reduce visual noise on the chart.
Release Notes
- Added 2x optional Triple-timeframe MTF Stoch RSI overbought and oversold signal ribbon with ribbon positioning setting.
Release Notes
- Added a 'flipped' warning label to the oscillator panel to show when the osc is flipped.
Release Notes
- Removed the unused source input option from pivot period settings.
Release Notes
- Updated divergence alerts to allows for alerting any type of divergence in a single alert.
- Updated alerts so that they are triggered only once per instance of a given divergence, and do not trigger if the following periods reprint the same divergence.
DIVDivergenceFLOWindexMFImoneyOscillatorsVolume Indicator

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Also on:

Disclaimer