Strategy · Pine Script v4 · On the chart

7-RSI strategy

by hasnocool· code credited to rrolik66

This strategy overlays the price chart and compares seven RSI readings, each calculated on its own timeframe from one minute through one day.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code181
Settings36inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 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

181 lines of Pine Script v4 from 7-RSI strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

7-RSI strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rrolik66
//@version=4
strategy(title="7-RSI strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=5, currency=currency.USD)
// inputs
src = input(close, "Source RSI", type = input.source)
bot_res = input(title="Bot period", type=input.resolution, defval="1")
srcin_bot = input(ohlc4, "Source Bot", type = input.source)
src_bot = security(syminfo.tickerid, bot_res, srcin_bot)
tradeDirection = input(title="Trade Direction", type=input.string,
     options=["Long Bot", "Short Bot"], defval="Long Bot")
rsi1_res = input(title="RSI-1 period", type=input.resolution, defval="1", group="indicators")
rsi1_Len = input(14, minval=1, title="RSI-1 Length", group="indicators")
rsi2_res = input(title="RSI-2 period", type=input.resolution, defval="5", group="indicators")
rsi2_Len = input(14, minval=1, title="RSI-2 Length", group="indicators")
rsi3_res = input(title="RSI-3 period", type=input.resolution, defval="15", group="indicators")
rsi3_Len = input(14, minval=1, title="RSI-3 Length", group="indicators")
rsi4_res = input(title="RSI-4 period", type=input.resolution, defval="30", group="indicators")
rsi4_Len = input(14, minval=1, title="RSI-4 Length", group="indicators")
rsi5_res = input(title="RSI-5 period", type=input.resolution, defval="60", group="indicators")
rsi5_Len = input(14, minval=1, title="RSI-5 Length", group="indicators")
rsi6_res = input(title="RSI-6 period", type=input.resolution, defval="120", group="indicators")
rsi6_Len = input(14, minval=1, title="RSI-6 Length", group="indicators")
rsi7_res = input(title="RSI-7 period", type=input.resolution, defval="1D", group="indicators")
rsi7_Len = input(14, minval=1, title="RSI-7 Length", group="indicators")
longProfitPerc = input(title="Long Bot Take Profit (%)",
     type=input.float, minval=0.0, step=0.05, defval=0.5, group="Long Bot") * 0.01
st_long_orders = input(title="Long Bot Step orders (%)",
     type=input.float, minval=0.0, step=0.1, defval=2.0, group="Long Bot") * 0.01
rsi1_low = input(100, title="RSI-1 <", group="Long Bot")
rsi2_low = input(100, title="RSI-2 <", group="Long Bot")
rsi3_low = input(100, title="RSI-3 <", group="Long Bot")
rsi4_low = input(100, title="RSI-4 <", group="Long Bot")
rsi5_low = input(100, title="RSI-5 <", group="Long Bot")
rsi6_low = input(100, title="RSI-6 <", group="Long Bot")
rsi7_low = input(100, title="RSI-7 <", group="Long Bot")
shortProfitPerc = input(title="Short Bot Take Profit (%)",
     type=input.float, minval=0.0, step=0.05, defval=0.5, group="Short Bot") * 0.01
st_short_orders = input(title="Short Bot Step orders (%)",
     type=input.float, minval=0.0, step=0.1, defval=2.0, group="Short Bot") * 0.01
rsi1_up = input(0, title="RSI-1 >", group="Short Bot")
rsi2_up = input(0, title="RSI-2 >", group="Short Bot")
rsi3_up = input(0, title="RSI-3 >", group="Short Bot")
rsi4_up = input(0, title="RSI-4 >", group="Short Bot")
rsi5_up = input(0, title="RSI-5 >", group="Short Bot")
rsi6_up = input(0, title="RSI-6 >", group="Short Bot")
rsi7_up = input(0, title="RSI-7 >", group="Short Bot")
//indicators
rsi1 = rsi(src, rsi1_Len)
rsi1_sec = security(syminfo.tickerid, rsi1_res, rsi1)
rsi2 = rsi(src, rsi2_Len)
rsi2_sec = security(syminfo.tickerid, rsi2_res, rsi2)
rsi3 = rsi(src, rsi3_Len)
rsi3_sec = security(syminfo.tickerid, rsi3_res, rsi3)
rsi4 = rsi(src, rsi4_Len)
rsi4_sec = security(syminfo.tickerid, rsi4_res, rsi4)
rsi5 = rsi(src, rsi5_Len)
rsi5_sec = security(syminfo.tickerid, rsi5_res, rsi5)
rsi6 = rsi(src, rsi6_Len)
rsi6_sec = security(syminfo.tickerid, rsi6_res, rsi6)
rsi7 = rsi(src, rsi7_Len)
rsi7_sec = security(syminfo.tickerid, rsi7_res, rsi7)
//RSI
rsi1_up_signal = rsi1_sec > rsi1_up
rsi1_low_signal = rsi1_sec < rsi1_low
rsi2_up_signal = rsi2_sec > rsi2_up
rsi2_low_signal = rsi2_sec < rsi2_low
rsi3_up_signal = rsi3_sec > rsi3_up
rsi3_low_signal = rsi3_sec < rsi3_low
rsi4_up_signal = rsi4_sec > rsi4_up
rsi4_low_signal = rsi4_sec < rsi4_low
rsi5_up_signal = rsi5_sec > rsi5_up
rsi5_low_signal = rsi5_sec < rsi5_low
rsi6_up_signal = rsi6_sec > rsi6_up
rsi6_low_signal = rsi6_sec < rsi6_low
rsi7_up_signal = rsi7_sec > rsi7_up
rsi7_low_signal = rsi7_sec < rsi7_low
//Buy & Sell
Buy = rsi1_low_signal and rsi2_low_signal and rsi3_low_signal and rsi4_low_signal and rsi5_low_signal and rsi6_low_signal and rsi7_low_signal
Sell = rsi1_up_signal and rsi2_up_signal and rsi3_up_signal and rsi4_up_signal and rsi5_up_signal and rsi6_up_signal and rsi7_up_signal
// input into trading conditions
longOK  = (tradeDirection == "Long Bot")
shortOK = (tradeDirection == "Short Bot")
// in entry orders price
longEntryPrice1 = src_bot * (1 - (st_long_orders))
longEntryPrice2 = src_bot * (1 - (st_long_orders*2))
longEntryPrice3 = src_bot * (1 - (st_long_orders*3))
longEntryPrice4 = src_bot * (1 - (st_long_orders*4))
longEntryPrice5 = src_bot * (1 - (st_long_orders*5))
longEntryPrice6 = src_bot * (1 - (st_long_orders*6))
longEntryPrice7 = src_bot * (1 - (st_long_orders*7))
longEntryPrice8 = src_bot * (1 - (st_long_orders*8))
longEntryPrice9 = src_bot * (1 - (st_long_orders*9))
longEntryPrice10 = src_bot * (1 - (st_long_orders*10))
longEntryPrice11 = src_bot * (1 - (st_long_orders*11))
longEntryPrice12 = src_bot * (1 - (st_long_orders*12))
longEntryPrice13 = src_bot * (1 - (st_long_orders*13))
longEntryPrice14 = src_bot * (1 - (st_long_orders*14))
longEntryPrice15 = src_bot * (1 - (st_long_orders*15))
longEntryPrice16 = src_bot * (1 - (st_long_orders*16))
longEntryPrice17 = src_bot * (1 - (st_long_orders*17))
longEntryPrice18 = src_bot * (1 - (st_long_orders*18))
longEntryPrice19 = src_bot * (1 - (st_long_orders*19))
shortEntryPrice1 = src_bot * (1 + st_short_orders)
shortEntryPrice2 = src_bot * (1 + (st_short_orders*2))
shortEntryPrice3 = src_bot * (1 + (st_short_orders*3))
shortEntryPrice4 = src_bot * (1 + (st_short_orders*4))
shortEntryPrice5 = src_bot * (1 + (st_short_orders*5))
shortEntryPrice6 = src_bot * (1 + (st_short_orders*6))
shortEntryPrice7 = src_bot * (1 + (st_short_orders*7))
shortEntryPrice8 = src_bot * (1 + (st_short_orders*8))
shortEntryPrice9 = src_bot * (1 + (st_short_orders*9))
shortEntryPrice10 = src_bot * (1 + (st_short_orders*10))
shortEntryPrice11 = src_bot * (1 + (st_short_orders*11))
shortEntryPrice12 = src_bot * (1 + (st_short_orders*12))
shortEntryPrice13 = src_bot * (1 + (st_short_orders*13))
shortEntryPrice14 = src_bot * (1 + (st_short_orders*14))
shortEntryPrice15 = src_bot * (1 + (st_short_orders*15))
shortEntryPrice16 = src_bot * (1 + (st_short_orders*16))
shortEntryPrice17 = src_bot * (1 + (st_short_orders*17))
shortEntryPrice18 = src_bot * (1 + (st_short_orders*18))
shortEntryPrice19 = src_bot * (1 + (st_short_orders*19))
// take profit price
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
// take profit values for confirmation
plot(series=(strategy.position_size > 0) ? longExitPrice : na,
     color=color.green, style=plot.style_circles,
     linewidth=3, title="Long Take Profit")
plot(series=(strategy.position_size < 0) ? shortExitPrice : na,
     color=color.red, style=plot.style_circles,
     linewidth=3, title="Short Take Profit")
// entry orders
if (strategy.position_size == 0)
    strategy.order(id="Long0", long=true, limit=src_bot, when=longOK and Buy)
    strategy.order(id="Long1", long=true, limit=longEntryPrice1, when=longOK and Buy)
    strategy.order(id="Long2", long=true, limit=longEntryPrice2, when=longOK and Buy)
    strategy.order(id="Long3", long=true, limit=longEntryPrice3, when=longOK and Buy)
    strategy.order(id="Long4", long=true, limit=longEntryPrice4, when=longOK and Buy)
    strategy.order(id="Long5", long=true, limit=longEntryPrice5, when=longOK and Buy)
    strategy.order(id="Long6", long=true, limit=longEntryPrice6, when=longOK and Buy)
    strategy.order(id="Long7", long=true, limit=longEntryPrice7, when=longOK and Buy)
    strategy.order(id="Long8", long=true, limit=longEntryPrice8, when=longOK and Buy)
    strategy.order(id="Long9", long=true, limit=longEntryPrice9, when=longOK and Buy)
    strategy.order(id="Long10", long=true, limit=longEntryPrice10, when=longOK and Buy)
    strategy.order(id="Long11", long=true, limit=longEntryPrice11, when=longOK and Buy)
    strategy.order(id="Long12", long=true, limit=longEntryPrice12, when=longOK and Buy)
    strategy.order(id="Long13", long=true, limit=longEntryPrice13, when=longOK and Buy)
    strategy.order(id="Long14", long=true, limit=longEntryPrice14, when=longOK and Buy)
    strategy.order(id="Long15", long=true, limit=longEntryPrice15, when=longOK and Buy)
    strategy.order(id="Long16", long=true, limit=longEntryPrice16, when=longOK and Buy)
    strategy.order(id="Long17", long=true, limit=longEntryPrice17, when=longOK and Buy)
    strategy.order(id="Long18", long=true, limit=longEntryPrice18, when=longOK and Buy)
    strategy.order(id="Long19", long=true, limit=longEntryPrice19, when=longOK and Buy)
if (strategy.position_size == 0)
    strategy.order(id="Short0", long=false, limit=src_bot, when=shortOK and Sell)
    strategy.order(id="Short1", long=false, limit=shortEntryPrice1, when=shortOK and Sell)
    strategy.order(id="Short2", long=false, limit=shortEntryPrice2, when=shortOK and Sell)
    strategy.order(id="Short3", long=false, limit=shortEntryPrice3, when=shortOK and Sell)
    strategy.order(id="Short4", long=false, limit=shortEntryPrice4, when=shortOK and Sell)
    strategy.order(id="Short5", long=false, limit=shortEntryPrice5, when=shortOK and Sell)
    strategy.order(id="Short6", long=false, limit=shortEntryPrice6, when=shortOK and Sell)
    strategy.order(id="Short7", long=false, limit=shortEntryPrice7, when=shortOK and Sell)
    strategy.order(id="Short8", long=false, limit=shortEntryPrice8, when=shortOK and Sell)
    strategy.order(id="Short9", long=false, limit=shortEntryPrice9, when=shortOK and Sell)
    strategy.order(id="Short10", long=false, limit=shortEntryPrice10, when=shortOK and Sell)
    strategy.order(id="Short11", long=false, limit=shortEntryPrice11, when=shortOK and Sell)
    strategy.order(id="Short12", long=false, limit=shortEntryPrice12, when=shortOK and Sell)
    strategy.order(id="Short13", long=false, limit=shortEntryPrice13, when=shortOK and Sell)
    strategy.order(id="Short14", long=false, limit=shortEntryPrice14, when=shortOK and Sell)
    strategy.order(id="Short15", long=false, limit=shortEntryPrice15, when=shortOK and Sell)
    strategy.order(id="Short16", long=false, limit=shortEntryPrice16, when=shortOK and Sell)
    strategy.order(id="Short17", long=false, limit=shortEntryPrice17, when=shortOK and Sell)
    strategy.order(id="Short18", long=false, limit=shortEntryPrice18, when=shortOK and Sell)
    strategy.order(id="Short19", long=false, limit=shortEntryPrice19, when=shortOK and Sell)
// exit position based on take profit price
if (strategy.position_size > 0)
    strategy.order(id="exit_Long", long=false, limit=longExitPrice, qty=strategy.position_size)
if (strategy.position_size < 0)
    strategy.order(id="exit_Short", long=true, limit=shortExitPrice, qty=abs(strategy.position_size))
Expand (206 lines)

Overview

The user chooses a long or short bot. Entries depend on every RSI meeting a threshold, while a percentage take profit closes the trade. Step-order percentages and a five percent equity size are configurable. There is no stop loss by default, and the supplied RSI limits start wide enough that the filters do little until the user tightens them.

Details

Published by

hasnocool on GitHub

Code credit

rrolik66, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Source RSIsourceclosesrc
Bot periodtimeframe1bot_res
Source Botsourceohlc4srcin_bot
Trade DirectionstringLong BottradeDirection
RSI-1 periodtimeframe1rsi1_res
RSI-1 Lengthint14rsi1_Len
RSI-2 periodtimeframe5rsi2_res
RSI-2 Lengthint14rsi2_Len
RSI-3 periodtimeframe15rsi3_res
RSI-3 Lengthint14rsi3_Len
RSI-4 periodtimeframe30rsi4_res
RSI-4 Lengthint14rsi4_Len
Show all 36 settings
SettingTypeDefaultVariable
RSI-5 periodtimeframe60rsi5_res
RSI-5 Lengthint14rsi5_Len
RSI-6 periodtimeframe120rsi6_res
RSI-6 Lengthint14rsi6_Len
RSI-7 periodtimeframe1Drsi7_res
RSI-7 Lengthint14rsi7_Len
Long Bot Take Profit (%)float0.5longProfitPerc
Long Bot Step orders (%)float2.0st_long_orders
RSI-1 <int100rsi1_low
RSI-2 <int100rsi2_low
RSI-3 <int100rsi3_low
RSI-4 <int100rsi4_low
RSI-5 <int100rsi5_low
RSI-6 <int100rsi6_low
RSI-7 <int100rsi7_low
Short Bot Take Profit (%)float0.5shortProfitPerc
Short Bot Step orders (%)float2.0st_short_orders
RSI-1 >int0rsi1_up
RSI-2 >int0rsi2_up
RSI-3 >int0rsi3_up
RSI-4 >int0rsi4_up
RSI-5 >int0rsi5_up
RSI-6 >int0rsi6_up
RSI-7 >int0rsi7_up
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

MACD Strategy

by TradersPost
218 stars

This overlay strategy is built around MACD inputs for a fast average, a slow average, and a signal line. Comments say the script keeps MACD values available and can draw a histogram and zero line in a separate pane, with an optional overlay on price. Settings

Strategy v6 Oscillators & momentumMoving averages
Updated 3 months ago · None stated GitHub repository of MACD Strategy
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

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