Indicator · Pine Script v4 · On the chart

MC - Defensive

by Metzenas

MC - Defensive calculates a WaveTrend oscillator combined with a volume-weighted money flow index to generate buy and sell signals directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code68
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago8 Apr 2021

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

68 lines of Pine Script v4 from studies/mc_defensive.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mc_defensive.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Metzenas

//@version=4
study("MC - Defensive", overlay=true)

n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
ema21 = input(21, "EMA 21")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")

ap = hlc3 
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
ema21_ = ema(hlc3, ema21)
 
wt1 = tci
wt2 = sma(wt1,3)
crossCondition = cross(wt1, wt2)
long_condition = (wt2 - wt1 <= 0)
short_condition = (wt2 - wt1 > 0)


// Money Flow
length = input(title="Length", type=input.integer, defval=60, minval=1, maxval=2000)
src = hlc3
upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
_rsi(upper, lower) =>
    if lower == 0
        100
    if upper == 0
        0
    100.0 - (100.0 / (1.0 + upper / lower))
mf = _rsi(upper, lower)

// Filters
body_size = abs(close - open) / (high - low)

// Base conditions
long_0 = wt2 <= 0 and mf <= 40
short_0 = wt2 >= 40 and mf >= 55

// Base
long_signal_base = crossCondition and (wt2 - wt1 <= 0) and long_0
short_signal_base = crossCondition and (wt2 - wt1 > 0) and short_0 and body_size >= 0.2

alertcondition(long_signal_base, "MC open", "MC - Buy")
alertcondition(short_signal_base, "MC close", "MC - Sell")

if (long_signal_base)
    l = label.new(bar_index, high)
    label.set_text(l, "buy_base@\n"+tostring(close))
    label.set_color(l, color.green)
    label.set_yloc(l, yloc.price)
    label.set_style(l, label.style_labelup)
    
if (short_signal_base)
    l = label.new(bar_index, high)
    label.set_text(l, "sell_base@\n"+tostring(close))
    label.set_color(l, color.red)
    label.set_yloc(l, yloc.price)
    label.set_style(l, label.style_labeldown)

Overview

Buy signals trigger when WaveTrend crosses up in oversold conditions with low money flow values, while sell signals trigger when WaveTrend crosses down in overbought territory with high money flow and candle body size requirements. The script draws visual text labels above or below price bars and provides alert conditions for entry and exit signals.

Details

Published by

Metzenas on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum, Volume

Markets

Any symbol

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.

Settings

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

SettingTypeDefaultVariable
Channel Lengthint10n1
Average Lengthint21n2
EMA 21int21ema21
Over Bought Level 1int60obLevel1
Over Bought Level 2int53obLevel2
Over Sold Level 1int-60osLevel1
Over Sold Level 2int-53osLevel2
Lengthint60length
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

This overlay indicator screens a pasted list of up to forty symbols and draws a table on the price chart. It classifies bullish or bearish setups from the percent change between the current candle and the candle 250 bars back, then shows RSI with a simple movi

Indicator v5 Oscillators & momentumVolume
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

Aroon-based Strategy

by capissimo
114 stars

This indicator overlay generates buy and sell signals based on Aroon extreme levels combined with optional volume or volatility filters. It calculates Aroon Up and Aroon Down lines using localized high and low lookbacks, generating trade entries when Aroon rea

Indicator v4 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Aroon-based Strategy
92 stars

This indicator plots a volume-weighted average price of the typical price on the chart and colors that line by ADX strength. It draws a standard-deviation envelope around VWAP and tints the fill green when plus DI leads and red when minus DI leads. Triangle ma

Indicator v5 TrendOscillators & momentum
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev VWAP x ADX Explosion

RSI Div at dVWAP StDev

by cryptorife
75 stars

This indicator marks RSI divergences only when price trades beyond daily VWAP standard-deviation bands. It compares recent RSI extremes with price highs and lows over a lookback window, and it treats a divergence as valid only while RSI stays beyond overbought

Indicator v4 DivergenceOscillators & momentum Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of RSI Div at dVWAP StDev

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers