Strategy · Pine Script v4 · On the chart

My Script Strategy Selector

by RobACurtis· code credited to Gammapips

A course example strategy with a setting that selects one of three entry rules.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code43
Settings2inputs
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

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

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

//@version=4
strategy("My Script", overlay=true)

// Inputs
i_stratSelect = input(defval="rsi", type=input.string, title="Select Strategy", options=['rsi', 'macd', 'bb'])
i_bbsrc = input(defval=close, title="BB strat source", type=input.source)


f_strategySelector(_strat) =>
    if _strat == 'rsi'
        rsi = rsi(close, 14)
        rsibuyCondition = crossover(rsi, 30)
        rsisellCondition = crossunder(rsi, 70)
        [rsibuyCondition, rsisellCondition]
    else if _strat == 'macd'
        [macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
        macdbuyCondition = histLine > 0 and crossover(macdLine, signalLine)
        macdsellCondition = histLine < 0 and crossunder(macdLine, signalLine)
        [macdbuyCondition, macdsellCondition]
    else if _strat == 'bb'
        [middle, upper, lower] = bb(close, 10, 2)
        bbbuyCondition = i_bbsrc < lower
        bbsellCondition =  i_bbsrc > upper
        [bbbuyCondition, bbsellCondition]
    else
        [na, na]
        

[buy, sell] = f_strategySelector(i_stratSelect)



plotshape(buy ? low : na, text='buy', style=shape.arrowup, location=location.belowbar, color=color.green, textcolor=color.green, size=size.large)
plotshape(sell ? high : na, text='sell', style=shape.arrowdown, location=location.abovebar, color=color.red, textcolor=color.red, size=size.large)

if buy
    strategy.entry("golong", strategy.long)

if sell
    strategy.entry("goshort", strategy.short)

Overview

The RSI option buys when RSI crosses up through 30 and sells when it crosses down through 70. The MACD option needs a histogram sign and a line cross. The Bollinger option buys below the lower band and sells above the upper band. Signals draw arrows and open long or short entries that reverse each other. There is no stop loss or take profit.

Details

Published by

RobACurtis on GitHub

Code credit

Gammapips, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

pinescripttradingtradingview

Settings

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

SettingTypeDefaultVariable
Select Strategystringrsii_stratSelect
BB strat sourcesourceclosei_bbsrc
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

Alert BB + RSI [Alorse] is a multi-symbol mean-reversion strategy designed for cryptocurrency trading. It evaluates Bollinger Bands and the Relative Strength Index (RSI) across up to 20 user-defined ticker symbols simultaneously. The strategy enters long posit

Strategy v4 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Alert BB + RSI [Alorse]
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

This strategy draws on the price chart and combines Stochastic RSI, the Money Flow Index, and an exponential moving average to open long or short trades. Longs use the lower oscillator thresholds and shorts use the upper ones, with direction limited to longs,

Strategy v5 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Indicator Strategy (StochRSI, MFI & EMA) With Safety Orders
104 stars

This strategy combines Bollinger Bands with a short RSI to fade moves that leave the bands and then return. A long requires the prior bar below the lower band and oversold, then a close back inside the band while RSI is between 30 and 50. Shorts mirror that at

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 years ago · MIT GitHub repository of Bollinger Bands and RSI Strategy
53 stars

This strategy implements Larry Connors' 2-period RSI mean-reversion algorithm overlaid on the price chart. It filters trades using a long-term Simple Moving Average (SMA), entering long positions when the price trades above the SMA and the short-term RSI drops

Strategy v6 Oscillators & momentumMean reversion
Updated 2 months ago · MPL-2.0 GitHub repository of Larry Connors 2-Period RSI 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