Strategy · Pine Script v4 · On the chart

MC Strategy - Defensive

by Metzenas

MC Strategy - Defensive executes long trades using a WaveTrend oscillator combined with a volume-weighted money flow calculation.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code56
Settings9inputs
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 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

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

mc_strategy_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
strategy("MC Strategy - Defensive", overlay=true, pyramiding=6)

scrape = input(false, "Use Scrapping")
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)
cross_condition = cross(wt1, wt2)

////////////////
// 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)
diverge_long = abs(ema21_ - open) / open

// Intermediate
long_base = wt2 <= 0 and mf <= 40
short_base = wt2 >= 40 and mf >= 55
long_diverge = mf <= 50 and diverge_long > 0.008

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

// Base
long_signal_base = cross_condition and (wt2 - wt1 <= 0) and (long_base or long_diverge) and body_size >= 0.1
short_signal_base = cross_condition and (wt2 - wt1 > 0) and short_base and body_size >= 0.2

// Execute
strategy.entry("long_base", true, 1, when = long_signal_base)
strategy.close("long_base", when = short_signal_base)

Overview

MC Strategy - Defensive enters long positions when the WaveTrend lines cross upward under low money flow conditions or when price sufficiently diverges from a 21-period EMA, filtered by candle body size. Positions close when an opposing short signal registers. The script allows configuration of channel lengths and overbought/oversold thresholds, permits pyramiding up to six orders, and contains no stop-loss rules.

Details

Published by

Metzenas on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Use Scrappingboolfalsescrape
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

106 stars

This strategy enters long on an outside bar when the candle is bullish, the Klinger Volume Oscillator is positive, and price is above a Hull moving average. It enters short on an inside bar when the candle is bearish, the oscillator is negative, and price is b

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced OutSide Forex strategy

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8
12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend

Combined Strategy

by Dropio12
7 stars

This strategy plots buy and sell markers on the price chart by combining a fast and slow ALMA crossover with a simple close-to-close momentum check. A long marker appears when the fast ALMA crosses above the slow ALMA and momentum is positive. A short marker a

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Combined Strategy

Antigravity Superstar

by eltonaguiar
4 stars

This strategy draws on the price chart and combines a triple EMA stack, a volume spike with a minimum price move, and a MACD line-signal crossover. It enters long or short only when at least the chosen number of those three signals agree, with an optional RSI

Strategy v6 TrendMoving averages
Updated 2 days ago · None stated GitHub repository of Antigravity Superstar
3 stars

This strategy plots long and short markers on the price chart. It builds a composite index from RSI change and a short RSI average, then requires that index, a one-minute cumulative volume delta, and a relative volatility index to agree. EMA, SMA, and VWAP rel

Strategy v5 Oscillators & momentumVolume Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Composite RVI CVD Strategy

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers