Pine Script Twiggs Money Flow

Unlock advanced volume-based pine script strategies with this comprehensive guide to Twiggs Money Flow in TradingView

Subscribe now @ $99/month

Why Twiggs Money Flow Matters in Pine Script Strategies

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 pine script strategies focused on trend confirmation and reversal detection.

Basic Twiggs Money Flow Implementation in Pine Script

Here's how to code the classic Twiggs Money Flow indicator in Pine Script v5:

//@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)
Key Insight: Twiggs Money Flow oscillates above and below zero, signaling bullishness when positive and bearishness when negative. It is especially effective when combined with other pine script strategies for confirmation.

Twiggs Money Flow vs Classic Money Flow Index

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 pine script strategies, TMF can offer clearer trend signals in choppy markets.

  1. Smoother signals: TMF reduces noise compared to MFI
  2. Better for trend trading: TMF highlights persistent buying/selling pressure
  3. Improved divergence detection: TMF can reveal hidden reversals

Advanced Pine Script Strategies Using Twiggs Money Flow

1. TMF Trend Confirmation Strategy

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

2. TMF Divergence Detection

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

Optimizing TMF for Your Pine Script Strategies

To maximize the impact of Twiggs Money Flow in your pine script strategies:

Dynamic TMF Threshold Example


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

Common TMF Pitfalls to Avoid in Pine Script Strategies

Warning: TMF can produce false signals in illiquid markets or during news events. Always use TMF as part of a broader pine script strategy, not in isolation.

Conclusion

Twiggs Money Flow is a robust volume-based indicator for Pine Script strategies, offering unique insights into accumulation and distribution. By integrating TMF with price action and other indicators, traders can build more reliable and adaptive pine script strategies for TradingView.

Enhance Your Trading

Get a high-performance Pine Script 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.

Subscribe now @ $99/month