Strategy · Pine Script v5 · On the chart

Money Printer Go BRRRRRR Backtest

by sourdiesel1202

A strategy that scores MACD, on-balance volume, ADX and DMI conditions into a single value and trades on that value.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code191
Settings18inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago16 Jul 2023

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

191 lines of Pine Script v5 from money_printer_go_brrrr_backtest.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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


//@version=5
strategy("Money Printer Go BRRRRRR Backtest", overlay=true, margin_long=100, margin_short=100)
//@version=5
// indicator("Money Printer Go BRRRRRR")
// drawVerticalLine(offset,color) =>
    // line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)
// adx_lookback=input(4, "ADX Lookback")
//@version=5
// indicator("Money Printer Go BRRRRRR")
// drawVerticalLine(offset,color) =>
    // line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)
// adx_lookback=input(4, "ADX Lookback")
// obv_percent = input(5, "OBV Percent")
trend_lookback=input(1,"Trend Lookback")

// obv_percent = input(5, "OBV Percent")
_adx = input(14,"ADX Value")

// [prior_dmilpus, prior_dmineg, prior_adx] = ta.dmi(14, 14)

//[macdLine, signalLine, histLine] = ta.macd(close, fastInput, slowInput, 9)
// obv = ta.obv
// prior_obv = ta.obv[1]
_dmiplus = input(17, "DMI+ Signal")
_dmineg = input(17, "DMI- Signal")
dmi_delta = input(15, "DMI Delta")
dmi_rapid=input(5, "DMI Rapid Change", "The delta between DMI[1] and DMI. If this value is exceeded, flag reversal")
// is_sinking(_indicator, _lookback)=>
calculate_macd_value(prior=0) =>
    slowlength = 26
    fastLength = 12
    MACDLength = 9
    fast_ma = ta.ema(close, fastLength)
    slow_ma = ta.ema(close, slowlength)
    macd = fast_ma - slow_ma
    signal = ta.ema(macd, MACDLength)
    // MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
    // aMACD = ta.ema(MACD[1], MACDLength)
    // delta = MACD - aMACD
    // signal=ta.ema(aMACD, MACDLength)
    // ema20 = ta.ema(close,20)
    // ok so the idea here is- is the macd over  the ema (signal) line
    _value =0.0
    hist = macd -signal
    if macd > signal
        if macd > macd[1]
            if hist[1] > hist
                _value :=0.125
            else
                _value :=0.25
        else
            _value :=0.125

    else
        if macd < macd[1]
            if hist[1] < hist
                _value :=-0.125
            else
                _value :=-0.25
        else
            _value := -0.125


    [_value,macd, signal]
calculate_obv_value(prior=0)=>
    obv = ta.obv

    obv_avg= (obv+obv[1]+obv[2])/3
    _value = 0.0
    if obv_avg <= obv
        if obv < obv[1]
            _value := 0.125
        else
            _value := 0.25
    else
        if obv > obv[1]
            _value := -0.125
        else
            _value := -0.25
    // else if obv_avg  <= obv[1]
        // _value := -0.25
    // else if obv_avg  < obv[1] and obv_avg > obv[2]
        // _value :=0.125
    // else if obv_avg  > obv[1] and obv_avg < obv[2]
        // _value :=-0.125

    [_value ]


//change obv to calculate trend
    // _value=0.0
    // if obv > prior_obv or (obv < prior_obv and prior_obv/obv*100 < obv_percent)
        // _value:=0.25

    // else if obv < prior_obv or (obv > prior_obv and obv/prior_obv*100 < obv_percent)
        // _value := -0.25
    // else
        // _value := 0
    // _value
calculate_adx_value(prior=0)=>
// [dmilpus, dmineg, adx] = ta.dmi(input(14,"DMI Length"), input(14, "ADX Smoothing"))
    [dmilpus, dmineg, adx] = ta.dmi(input(14,"DMI Length"), input(14, "ADX Smoothing"))
    _value=0.0
    if adx > adx[1]
        _value:=0.25
    else
        sinking=true
        for i =0 to trend_lookback
            if sinking
                if adx[i+prior] > adx[i+1]
                    sinking:=false
        // _sinking = sinking

        if sinking
            _value:=0.0
        else
            _value :=0.125
    _value :=  dmilpus > dmineg ? 1*_value : -1*_value
    // plotchar(_value, "MPB ADX Value", "", location = location.top)
    [_value]
calculate_dmi_value()=>
    _value=0.0
    [dmilpus, dmineg, adx] = ta.dmi(input(14,"DMI Length"), input(14, "ADX Smoothing"))
    if dmilpus >= dmineg and dmilpus >= _dmiplus and dmilpus-dmineg > dmi_delta
    //# check to see if dmi+ is trending down and dmi- is trending up
    // if dmilpus < dmilpus[1] and dmineg > dmineg[1]
    //plot(1,color = color.green)
        _value:=0.25
        // if  prior_obv> obv and prior_obv/obv*100 < obv_percent
            // value:=0.5


    //case for rapid changes pointing to reversal
        if dmilpus[1]-dmilpus > dmi_rapid
            _value:=0
    // if dmilpus
    // if dmilpus-dmineg <= dmi_delta
        // value:=0
    // if dmilpus-dmineg < input(15, "DMI Delta")
    //     value:=0.5
    // else
    //     value := 0.5
    // []
    if dmineg >= dmilpus and dmineg >= _dmineg and dmineg-dmilpus > dmi_delta
        // if adx > prior_adx
        _value:=-0.25
            // if  rsi >= input(60, "RSI High")
                // line.new(bar_index, close, bar_index, close + 1, xloc.bar_index, extend.both, color.red)
            // else
            //     value := -0.5
        if dmineg[1]-dmineg > dmi_rapid
            _value:=0
    [_value]
// old_value = 0.0
[mpb_dmi] = calculate_dmi_value()
[mpb_adx] = calculate_adx_value()
[mpb_macd, macd, ema20]=calculate_macd_value()
[mpb_obv]= calculate_obv_value()
plotchar(mpb_macd, "MPB MACD Value", "", location = location.top)
plotchar(mpb_obv, "MPB OBV Value", "", location = location.top)
plotchar(mpb_adx, "MPB ADX Value", "", location = location.top)
plotchar(mpb_dmi, "MPB DMI Value", "", location = location.top)
plotchar(macd, "MACD Value", "", location = location.top)
plotchar(ema20, "MACD Signal Value", "", location = location.top)


value = mpb_adx+mpb_dmi+mpb_macd+mpb_obv
old_value = value[1]//mpb_adx[1]+mpb_dmi[1]+mpb_macd[1]+mpb_obv[1]

// longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
// mpb = input.source("Money Printer Go BRRRRRR (Strategy)","MPB Historical")
plotchar(value, "MPB Value", "", location = location.top)
plotchar(old_value, "Old MPB value", "", location = location.top)
if (value >= input(0.38, "Long Entry Value Over", "Ensure MPB value exceeds this value before entrying a long position") and old_value <= input(0.0, "Long Entry Prior Value Under", "Ensure prior MPB value is under this value before entering a long position") )// and previous_value < 0.25)
    strategy.entry("Long", strategy.long, 10, comment = "Enter Long Position")

if value <= input(0.38, "Long Exit Value Under", "Ensure MPB value is under this value before exiting a long position") and old_value >= input(0.38, "Long Exit Prior Value Over", "Ensure prior MPB value is under this value before exiting a long position")
    strategy.close("Long", qty_percent = 100,immediately = true , comment = "Exit Long Position")
// if (current_value < 0.1 and previous_value > 0.1)
    // st rategy.exit("Calls", profit = 0)
// shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (value <= input(-0.12, "Short Entry Value Under", "Ensure MPB value is under this value before entering a short position") and old_value >= input(-0.13, "Short Entry Prior Value Over", "Ensure prior MPB value is over this value before entering a short position") )//and previous_value > -0.25)
    strategy.entry("Short", strategy.short,10, comment = "Enter Short Position")
if value >= input(-0.38, "Short Exit Value Over", "Ensure MPB value is over this value before exiting a short position") and old_value  <=input(-0.38, "Short Entry Prior Value Under", "Ensure prior MPB value is under this value before exiting a short position")
    strategy.close("Short",qty_percent = 100,immediately = true, comment = "Exit Short Position")
// if (current_value > -0.1 and previous_value < -0.1)
    // strategy.exit("Puts", profit = 0)

Overview

Inputs set long entry and exit thresholds and short entry and exit thresholds, along with DMI and ADX lengths and signal levels. Long and short entries and exits are triggered when the combined value crosses those configured levels. The code defines no stop loss, so exits depend only on the threshold rules. The supplied source is cut off partway, so sizing details are not visible. It draws on the price chart.

Details

Published by

sourdiesel1202 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • 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
Trend Lookbackint1trend_lookback
ADX Valueint14_adx
DMI+ Signalint17_dmiplus
DMI- Signalint17_dmineg
DMI Deltaint15dmi_delta
DMI Rapid Changeint5dmi_rapid
DMI Lengthint14DMI Length
ADX Smoothingint14ADX Smoothing
DMI Lengthint14DMI Length
ADX Smoothingint14ADX Smoothing
Long Entry Value Overfloat0.38Long Entry Value Over
Long Entry Prior Value Underfloat0.0Long Entry Prior Value Under
Show all 18 settings
SettingTypeDefaultVariable
Long Exit Value Underfloat0.38Long Exit Value Under
Long Exit Prior Value Overfloat0.38Long Exit Prior Value Over
Short Entry Value Underfloat-0.12Short Entry Value Under
Short Entry Prior Value Overfloat-0.13Short Entry Prior Value Over
Short Exit Value Overfloat-0.38Short Exit Value Over
Short Entry Prior Value Underfloat-0.38Short Entry Prior Value Under
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

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

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