Strategy · Pine Script v5 · On the chart

Surfr 5-Minute Variant

by RobACurtis· code credited to djdrob

A strategy that trades when price closes across a 50-period moving average after the previous close was on the other side, with a Stochastic RSI direction check and a cap on the stop distance in points.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code96
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago20 Jan 2024

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

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

trippleX.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © djdrob

//@version=5
strategy('Surfr', overlay=true)
import djdrob/TrendChecker/1

_sma = input.int(50, title="SMA")
goLong = input.bool(true, title="Go Long")
goShort = input.bool(true, title="Go Short")
maxRisk = input.int(5, title="Max Risk in points")

timeframe = input.timeframe("5", title="What bigger timeframe do you want to trade with?")

sma = ta.sma(close, _sma)
sma_89 = ta.sma(close, 89)
atr = ta.atr(20)
plot(sma, color=color.orange, title = "SMA")
plot(ta.sma(close, 89), color=color.rgb(0, 98, 255), title = "SMA 89")

[middle, upper, lower] = ta.bb(close, 20, 2)
plot(upper, color=color.rgb(4, 0, 255), title="upper")
plot(middle, color=color.rgb(4, 0, 255), title="middle")
plot(lower, color=color.rgb(4, 0, 255), title="lower")

setRSI() =>
    rsi1 = ta.rsi(close, 15)
    kRed = ta.sma(ta.stoch(rsi1, rsi1, rsi1, 20), 4)
    dGreen = ta.sma(kRed, 4)
    [kRed, dGreen]

setMACD() =>
    fast_ma = ta.ema(close, 12)
    slow_ma = ta.ema(close, 26)
    macd = fast_ma - slow_ma
    signal = ta.ema(macd, 9)
    hist = macd - signal
    [macd, signal]

checkMACDCrossing() =>
    [macd, signal] = setMACD()
    result = macd > signal ? true : false
    result

[rsiRed, rsiGreen] = request.security(syminfo.tickerid, timeframe, setRSI())
[macdRed, macdGreen] = request.security(syminfo.tickerid, timeframe, setMACD())

var float entryPrice = na
stopPriceLong = ta.lowest(1) - atr
stopPriceShort = ta.highest(1) + atr
[red, green] = setRSI()
exitLong = ta.crossover(green, red) and red > 60
exitShort = ta.crossover(red, green) and red < 40

bullishWave() =>
    prevCandleBearish = close[1] < sma
    isCloseBullish = close > sma
    checkRisk = (close - stopPriceLong) <= maxRisk
    rsiCondition = red > green
    bigs = (rsiRed > rsiGreen) or (macdRed > macdGreen)
    bullishWave = prevCandleBearish and isCloseBullish and strategy.position_size == 0 and checkRisk and rsiCondition and bigs
    bullishWave

bearishWave() =>
    prevCandleBullish = close[1] > sma
    isCloseBearish = close < sma
    checkRisk = (stopPriceShort - close) <= maxRisk
    rsiCondition = red < green
    bigs = (rsiRed < rsiGreen) or (macdRed < macdGreen)
    bullishWave = prevCandleBullish and isCloseBearish and checkRisk and rsiCondition and strategy.position_size == 0 and bigs
    bullishWave

trender_ridr_strategy() =>
    [bullishWave(), bearishWave()]

[buy, sell] = trender_ridr_strategy()

if buy and goLong
    strategy.entry("Go Long", strategy.long)
    strategy.exit("Stop Loss", stop=stopPriceLong)

if sell and goShort
    strategy.entry('goshort', strategy.short)
    strategy.exit("Stop Loss", stop=stopPriceShort)

if (strategy.position_size > 0)
    if (close <= sma and close > (strategy.position_avg_price + 3))//exit !
        strategy.close_all('exit long')
    else if (exitLong)
        strategy.close_all('exit long RSI crossing')

if (strategy.position_size < 0)
    if (close >= sma and close <= strategy.position_avg_price - 3) // exit!
        strategy.close_all('exit short')
    else if (exitShort)
        strategy.close_all('exit short RSI crossing')

Overview

A confirmation timeframe, 5 minutes by default, supplies RSI and MACD agreement. The stop sits one ATR beyond the latest bar extreme. Exits use a moving average cross with a minimum point gain or a Stochastic RSI cross. Long and short can be switched off.

Details

Published by

RobACurtis on GitHub

Code credit

djdrob, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

M1-M5

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.

Topics

pinescripttradingtradingview

Settings

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

SettingTypeDefaultVariable
SMAint50_sma
Go LongbooltruegoLong
Go ShortbooltruegoShort
Max Risk in pointsint5maxRisk
What bigger timeframe do you want to trade with?timeframe5timeframe
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated yesterday · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
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
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

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