Unlock advanced volume-based Pinescript strategies with this comprehensive guide to Twiggs Money Flow in TradingView
Twiggs Money Flow (TMF) is a powerful volume-based indicator that helps traders gauge the strength of buying and selling pressure over time. By combining price and volume, TMF provides more nuanced signals than traditional oscillators, making it a valuable tool for Pinescript strategies focused on trend confirmation and reversal detection.
//@version=5
indicator("Twiggs Money Flow", shorttitle="TMF", overlay=false)
// User inputs
length = input.int(21, title="TMF Length")
// Calculate the Money Flow Multiplier
mf_multiplier = ((close - low) - (high - close)) / (high - low)
mf_multiplier := na(mf_multiplier) ? 0 : mf_multiplier
// Money Flow Volume
mf_volume = mf_multiplier * volume
// Sum over the chosen period
sum_mf_volume = ta.sma(mf_volume, length)
sum_volume = ta.sma(volume, length)
// Twiggs Money Flow calculation
tmf = sum_mf_volume / sum_volume
plot(tmf, "Twiggs Money Flow", color=color.teal, style=plot.style_line)
hline(0, "Zero Line", color=color.gray)
Twiggs Money Flow oscillates above and below zero, signaling bullishness when positive and bearishness when negative. It is especially effective when combined with other Pinescript strategies for confirmation.
While both TMF and MFI are volume-based, TMF uses a unique multiplier and smoothing, making it less sensitive to price spikes and better at highlighting sustained accumulation or distribution. For Pinescript strategies, TMF can offer clearer trend signals in choppy markets.
//@version=5
strategy("TMF Trend Confirmation", overlay=true)
tmfLength = input.int(21, "TMF Length")
priceMA = input.int(50, "Price MA Length")
// Calculate TMF
mf_multiplier = ((close - low) - (high - close)) / (high - low)
mf_multiplier := na(mf_multiplier) ? 0 : mf_multiplier
mf_volume = mf_multiplier * volume
sum_mf_volume = ta.sma(mf_volume, tmfLength)
sum_volume = ta.sma(volume, tmfLength)
tmf = sum_mf_volume / sum_volume
// Price MA
ma = ta.sma(close, priceMA)
// Strategy logic
longCondition = close > ma and tmf > 0
shortCondition = close < ma and tmf < 0
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
//@version=5
indicator("TMF Divergence Detector", overlay=true)
tmfLength = input.int(21, "TMF Length")
tmf = ta.sma(((close - low) - (high - close)) / (high - low) * volume, tmfLength) / ta.sma(volume, tmfLength)
// Detect price and TMF divergence
priceHigh = ta.highest(high, 14)
tmfHigh = ta.highest(tmf, 14)
bearDiv = high > high[1] and tmf < tmf[1] and tmf < 0
bullDiv = low < low[1] and tmf > tmf[1] and tmf > 0
plotshape(bearDiv, "Bearish Div", shape.triangledown, location.top, color.red)
plotshape(bullDiv, "Bullish Div", shape.triangleup, location.bottom, color.green)
To maximize the impact of Twiggs Money Flow in your Pinescript strategies:
//@version=5
indicator("Dynamic TMF Thresholds", overlay=false)
length = input.int(21, "TMF Length")
lookback = input.int(50, "Threshold Lookback")
mf_multiplier = ((close - low) - (high - close)) / (high - low)
mf_multiplier := na(mf_multiplier) ? 0 : mf_multiplier
mf_volume = mf_multiplier * volume
tmf = ta.sma(mf_volume, length) / ta.sma(volume, length)
upperBand = ta.percentile(tmf, lookback, 75)
lowerBand = ta.percentile(tmf, lookback, 25)
plot(tmf, "TMF", color=color.teal)
hline(upperBand, "Upper Band", color=color.red)
hline(lowerBand, "Lower Band", color=color.green)
hline(0, "Zero Line", color=color.gray)
Twiggs Money Flow is a robust volume-based indicator for Pinescript strategies, offering unique insights into accumulation and distribution. By integrating TMF with price action and other indicators, traders can build more reliable and adaptive Pinescript strategies for TradingView.
Get a high-performance Pinescript analysis tool for actionable market insights, designed for traders on the move.
This strategy runs in live mode on TradingView, helping you identify potential opportunities.
Get Pinescript Strategy