Strategy · Pine Script v5 · Own pane

MFI Strategy - Eterna MCP

by EternaHybridExchange

This strategy calculates the Money Flow Index (MFI) to identify momentum shifts, overbought or oversold states, and price divergences.

View on GitHub

GitHub stars9on the repository
Pine versionv5runs as is
Lines of code90
Settings6inputs
LicenceMIT
Last update7 months ago12 Mar 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

90 lines of Pine Script v5 from strategies/momentum/mfi_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

mfi_strategy.pine
//@version=5
strategy("MFI Strategy - Eterna MCP", 
         shorttitle="MFI",
         overlay=false,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=100,
         initial_capital=1000)

// ============================================
// PARAMETERS
// ============================================
mfiLength = input.int(14, "MFI Length", minval=1)
overboughtLevel = input.int(80, "Overbought", minval=50, maxval=100)
oversoldLevel = input.int(20, "Oversold", minval=0, maxval=50)
divergenceLookback = input.int(5, "Divergence Lookback", minval=3)
leverageSize = input.float(5.0, "Leverage", minval=1, maxval=100)
positionSize = input.float(0.01, "Position Size", minval=0.001, maxval=1)

// ============================================
// MFI CALCULATION
// ============================================
mfi = ta.mfi(close, mfiLength)

// ============================================
// SIGNAL GENERATION
// ============================================
// Standard overbought/oversold
bullishOB = ta.crossover(mfi, oversoldLevel)
bearishOS = ta.crossunder(mfi, overboughtLevel)

// Divergence detection
priceLow = ta.lowest(low, divergenceLookback)
priceHigh = ta.highest(high, divergenceLookback)
mfiLow = ta.lowest(mfi, divergenceLookback)
mfiHigh = ta.highest(mfi, divergenceLookback)

// Bullish divergence: price lower low, MFI higher low
bullishDiv = low == priceLow and mfi > mfiLow and mfi < oversoldLevel
// Bearish divergence: price higher high, MFI lower high
bearishDiv = high == priceHigh and mfi < mfiHigh and mfi > overboughtLevel

// Volume confirmation
avgVolume = ta.sma(volume, 20)
highVolume = volume > avgVolume * 1.5

// Combined signals
buySignal = (bullishOB or bullishDiv) and mfi < 50
sellSignal = (bearishOS or bearishDiv) and mfi > 50

// ============================================
// STRATEGY LOGIC
// ============================================
if buySignal and strategy.position_size == 0
    strategy.entry("Long", strategy.long)
    alert('{"action":"buy","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

if sellSignal and strategy.position_size == 0
    strategy.entry("Short", strategy.short)
    alert('{"action":"sell","symbol":"' + syminfo.ticker + '","size":' + str.tostring(positionSize) + ',"leverage":' + str.tostring(leverageSize) + '}', alert.freq_once_per_bar_close)

// Exit on opposite signal
if sellSignal and strategy.position_size > 0
    strategy.close("Long")

if buySignal and strategy.position_size < 0
    strategy.close("Short")

// ============================================
// PLOTTING
// ============================================
plot(mfi, "MFI", color=color.blue, linewidth=2)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)

// Color gradient based on MFI value
mfiColor = mfi > overboughtLevel ? color.new(color.red, 80) : 
           mfi < oversoldLevel ? color.new(color.green, 80) : 
           color.new(color.gray, 90)
bgcolor(mfiColor)

plotshape(buySignal, "Buy", shape.triangleup, location.bottom, color.green, size=size.normal)
plotshape(sellSignal, "Sell", shape.triangledown, location.top, color.red, size=size.normal)

// Divergence markers
plotshape(bullishDiv, "Bullish Div", shape.diamond, location.bottom, color.lime, size=size.tiny)
plotshape(bearishDiv, "Bearish Div", shape.diamond, location.top, color.orange, size=size.tiny)

// Volume indicator
plot(highVolume ? 90 : na, "High Volume", color=color.yellow, style=plot.style_circles, linewidth=1)

Overview

MFI Strategy - Eterna MCP opens long entries when MFI crosses above the oversold level or displays bullish divergence while under the midline. It enters short positions on overbought crossunder signals or bearish divergences above the midline. Positions are closed upon receiving an opposite trade signal. User parameters control MFI length, overbought and oversold thresholds, divergence lookback, position sizing, and leverage settings. The indicator plots in a separate pane with signal shapes. There is no built-in stop loss.

Details

Published by

EternaHybridExchange on GitHub

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Divergence, Volume

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingautomated-tradingbacktestingbybitcrypto-tradingeternamcppine-scripttrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
MFI Lengthint14mfiLength
Overboughtint80overboughtLevel
Oversoldint20oversoldLevel
Divergence Lookbackint5divergenceLookback
Leveragefloat5.0leverageSize
Position Sizefloat0.01positionSize
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

330 stars

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

Q-Trend + KVO Strategy

by TradersPost
218 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

BBPBΔ(OBV-PVT)BB

by hasnocool
106 stars

This strategy calculates the normalized rate of change between On-Balance Volume (OBV) and Price Volume Trend (PVT) indicators. It applies Bollinger Bands to this volume metric along with a Hodrick-Prescott filter array for time series decomposition. Displayed

Strategy v4 VolumeVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of BBPBΔ(OBV-PVT)BB

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD

RSI-VWAP Indicator

by oguzhandilber
47 stars

This strategy calculates a Relative Strength Index (RSI) applied to the Volume Weighted Average Price (VWAP) rather than standard close values. It plots dedicated long and short RSI-VWAP lines with customizable overbought and oversold thresholds, alongside an

Strategy v4 Oscillators & momentumVolume
Updated 5 years ago · None stated GitHub repository of RSI-VWAP Indicator

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers