Strategy · Pine Script v5 · On the chart

Fluffy MACD Uptrend

by pvdochtend

A long-only strategy that buys when the MACD histogram turns from negative to positive while the 50 EMA is above the 200 EMA and RSI sits between a lower and an upper limit.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code65
Settings14inputs
LicenceGPL-3.0
Last update3 years ago5 Feb 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

65 lines of Pine Script v5 from ScalperV1-MACD.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

ScalperV1-MACD.pine
//@version=5
strategy(title="Fluffy Uptrend, MACD Green, RSI", shorttitle="Fluffy MACD Uptrend", overlay=true)
// Getting inputs
fast_length = input(title="Fast Length", group="MACD Settings", defval=12)
slow_length = input(title="Slow Length", group="MACD Settings", defval=26)
src = input(title="Source", group="MACD Settings", defval=close)
signal_length = input.int(title="Signal Smoothing",  group="MACD Settings", minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = #2962FF //input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = #FF6D00 // input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = #26A69A //input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = #B2DFDB //input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = #FFCDD2 //input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = #FF5252 //input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
hline(0, "Zero Line", color=color.new(#787B86, 50))
//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
//plot(macd, title="MACD", color=col_macd)
//plot(signal, title="Signal", color=col_signal)

macdcross_long = macd and signal ? ta.crossover(macd,signal) : false
macdcross_short = macd and signal > 0 ? ta.crossunder(macd,signal) : false

isBuyAlertMACD = (hist >=0 and (hist[1] < hist) and (hist[1] <= 0))
// isSellAlertMACD = 

//EMA Uptrend
EMA_Fast_Length = input(title="EMA Fast Length", group="EMA Settings", defval=50)
EMA_Slow_Length = input(title="EMA Slow Length", group="EMA Settings", defval=200)
EMA_Fast = ta.ema(close,EMA_Fast_Length)
EMA_Slow = ta.ema(close,EMA_Slow_Length)

isUptrend = EMA_Fast > EMA_Slow

//RSI
rsiUpperLimit = input(title="RSI Upper Limit", group="RSI Settings", defval=70)
rsiLowerLimit = input(title="RSI Lower Limit", group="RSI Settings", defval=50)
rsiLength = input(title="RSI Length", group="RSI Settings", defval=14)
rsiCurrent = ta.rsi(close,rsiLength)

isRSIBetweenLimits = (rsiCurrent > rsiLowerLimit) and (rsiCurrent < rsiUpperLimit)

//Trigger Alerts
if (isBuyAlertMACD and isUptrend and isRSIBetweenLimits)  
    strategy.entry("buy",strategy.long)

long_tp_inp = input(defval=0.3, title='Long Take Profit %') /100
long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
strategy.exit("Take Profit","Long", limit=long_take_level)

//if isUptrend == false 
//    strategy.close("buy")

// Backtest Range

startDate = input(timestamp("2022-09-01T00:00:00"))
finishDate = input(timestamp("2022-09-31T00:00:00"))

Overview

Its only exit is a percentage take-profit above the average entry price. No stop loss is coded, and the script has a hard-coded backtest date window in 2022 that may need editing. Settings cover the MACD lengths and average types, the EMAs, the RSI limits and the take-profit percentage.

Details

Published by

pvdochtend on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Trend

Markets

Crypto

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
Fast Lengthint12fast_length
Slow Lengthint26slow_length
Sourcesourceclosesrc
Signal Smoothingint9signal_length
Oscillator MA TypestringEMAsma_source
Signal Line MA TypestringEMAsma_signal
EMA Fast Lengthint50EMA_Fast_Length
EMA Slow Lengthint200EMA_Slow_Length
RSI Upper Limitint70rsiUpperLimit
RSI Lower Limitint50rsiLowerLimit
RSI Lengthint14rsiLength
Long Take Profit %float0.3long_tp_inp
Show all 14 settings
SettingTypeDefaultVariable
startDateinputtimestamp("2022-09-01T00:00:00")startDate
finishDateinputtimestamp("2022-09-31T00:00:00")finishDate
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