Strategy · Pine Script v5 · Own pane

超级趋势RSI

by wynnforthework· code credited to AlgoAlpha

This strategy applies a Supertrend calculation directly to Relative Strength Index values rather than raw price, plotting the result in a separate pane.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code124
Settings13inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago7 Oct 2025

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

124 lines of Pine Script v5 from 策略/开源分享/超级趋势rsi半成品哈.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

超级趋势rsi半成品哈.txt
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha

//@version=5
strategy('超级趋势RSI', overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value =100, slippage=1, commission_type=strategy.commission.percent, commission_value=.05, initial_capital=1000)


// Input parameters
relativeStrengthIndexLength = input.int(14, title="RSI Length", group="RSI Settings")
smoothingLength = input.int(21, title="RSI Smoothing Length", group="RSI Settings")
rsiInputSource = input.source(close, title="RSI Source", group="RSI Settings")
isSmoothed = input.bool(false, "Smooth RSI?", group="RSI Settings")


tp =    input.float(1.1, "止盈" ,step=0.01)
stop =    input.float(0.9, "止损" ,step=0.01)
movingAverageLength = input.int(14, title="MA Length", group="MA Settings", display = display.data_window)
movingAverageType = input.string("HMA", title="MA Type", options=["SMA", "HMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings", display = display.data_window)
showMovingAverage = input.bool(true, "Show RSI MA?", group="MA Settings")

trendFactor = input.float(0.8, title="Factor", group="Super Trend Settings")
averageTrueRangeLength = input.int(10, title="ATR Length", group="Super Trend Settings")

colorUp = input.color(#00ffbb, title="Up Color")
colorDown = input.color(#ff1100, title="Down Color")

// MA Selection
calculateMA(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "HMA" => ta.hma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

// Function to calculate ATR
calculateATR(source, atrLength) =>
    highestHigh = ta.highest(source, atrLength)
    lowestLow = ta.lowest(source, atrLength)
    trueRange = na(highestHigh[1]) ? highestHigh - lowestLow : math.max(highestHigh - lowestLow, math.abs(highestHigh - source[1]), math.abs(lowestLow - source[1]))
    ta.rma(trueRange, atrLength)

// Function to calculate Supertrend
calculateSupertrend(factor, atrPeriod, source) =>
    priceSource = source
    atr = calculateATR(source, atrPeriod)
    upperBand = priceSource + factor * atr
    lowerBand = priceSource - factor * atr
    prevLowerBand = nz(lowerBand[1])
    prevUpperBand = nz(upperBand[1])
    lowerBand := lowerBand > prevLowerBand or source[1] < prevLowerBand ? lowerBand : prevLowerBand
    upperBand := upperBand < prevUpperBand or source[1] > prevUpperBand ? upperBand : prevUpperBand
    int trendDirection = na
    float supertrendValue = na
    prevSupertrend = supertrendValue[1]
    if na(atr[1])
        trendDirection := 1
    else if prevSupertrend == prevUpperBand
        trendDirection := source > upperBand ? -1 : 1
    else
        trendDirection := source < lowerBand ? 1 : -1
    supertrendValue := trendDirection == -1 ? lowerBand : upperBand
    [supertrendValue, trendDirection]

// Calculating RSI
rsiValue = isSmoothed ? ta.hma(ta.rsi(rsiInputSource, relativeStrengthIndexLength), smoothingLength) : ta.rsi(rsiInputSource, relativeStrengthIndexLength)
rsiMovingAverage = calculateMA(rsiValue, movingAverageLength, movingAverageType)

// Calculating Supertrend based on RSI values
[rsiSupertrend, trendDirection] = calculateSupertrend(trendFactor, averageTrueRangeLength, rsiValue)

// Plotting
supertrendPlot = plot(rsiSupertrend, color = trendDirection == -1 ? colorUp : colorDown, title="Supertrend")
rsiPlot = plot(rsiValue, color = color.new(color.gray, 100), title="RSI")
overboughtLine = plot(70, color = color.from_gradient(rsiValue, 50, 70, color.new(color.gray, 70), color.new(colorDown, 0)), title="Overbought Line", linewidth = 3)
oversoldLine = plot(30, color = color.from_gradient(rsiValue, 30, 50, color.new(colorUp, 0), color.new(color.gray, 70)), title="Oversold Line", linewidth = 3)
plot(rsiMovingAverage, color = color.gray, title = "RSI MA", display = showMovingAverage ? display.all : display.none, linewidth = 1)
plot(50, color = color.gray, title="Mid Line")

// Filling
fill(overboughtLine, oversoldLine, color = color.new(color.gray, 90), title="Overbought/Oversold Fill")
fill(supertrendPlot, rsiPlot, color = trendDirection == 1 ? color.new(colorDown, 90) : color.new(colorUp, 90), title="Trend Fill")
fill(supertrendPlot, rsiPlot, rsiValue, rsiSupertrend, color.new(chart.bg_color, 1000), trendDirection == 1 ? colorDown : colorUp)


fn_t3(src, length) =>
    axe1 = ta.ema(src, length)
    axe2 = ta.ema(axe1, length)
    axe3 = ta.ema(axe2, length)
    axe4 = ta.ema(axe3, length)
    axe5 = ta.ema(axe4, length)
    axe6 = ta.ema(axe5, length)
    ab = 0.7
    ac1 = -ab*ab*ab
    ac2 = 3*ab*ab+3*ab*ab*ab
    ac3 = -6*ab*ab-3*ab-3*ab*ab*ab
    ac4 = 1+3*ab+ab*ab*ab+3*ab*ab
    avg = ac1 * axe6 + ac2 * axe5 + ac3 * axe4 + ac4 * axe3

t3_fast = fn_t3(close, 3)
t3_slow = fn_t3(close, 7)

//多空信号
bull = ta.crossover(t3_fast,t3_slow)
bear = ta.crossunder(t3_slow,t3_fast)

short = ta.crossover(rsiSupertrend, rsiValue) and rsiSupertrend > 70 
long = ta.crossunder(rsiSupertrend, rsiValue) and rsiSupertrend < 30
// Char plotting for crossover and crossunder
plotshape(short ? 85 : na, style=shape.triangledown, location=location.absolute, color=colorDown, size=size.tiny, title="Crossover Down")
plotshape(long ? 15 : na, style=shape.triangleup, location=location.absolute, color=colorUp, size=size.tiny, title="Crossunder Up")
// 计算开仓价格的1%以上的价格
takeProfitPrice = strategy.opentrades.entry_price(0) * tp
// 计算开仓价格的0.99倍的价格,用于止损
stopLossPrice = strategy.opentrades.entry_price(0) * stop
if long
    strategy.entry("buy1", strategy.long)

if bear and close > takeProfitPrice
    strategy.close_all('止盈')

if short
    strategy.close_all('趋势结束,平仓')

Overview

Traders can enable optional RSI smoothing via a Hull Moving Average and overlay a secondary moving average selected from multiple types. Supertrend sensitivity is adjustable through the ATR length and factor inputs. Designed as a momentum trend-following model, it evaluates directional changes based on RSI behavior, though explicit risk management and stop loss logic are incomplete in the implementation.

Details

Published by

wynnforthework on GitHub

Code credit

AlgoAlpha, as written in the script's header

Draws

Separate pane below the chart

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
RSI Lengthint14relativeStrengthIndexLength
RSI Smoothing Lengthint21smoothingLength
RSI SourcesourceclosersiInputSource
Smooth RSI?boolfalseisSmoothed
止盈float1.1tp
止损float0.9stop
MA Lengthint14movingAverageLength
MA TypestringHMAmovingAverageType
Show RSI MA?booltrueshowMovingAverage
Factorfloat0.8trendFactor
ATR Lengthint10averageTrueRangeLength
Up Colorcolor#00ffbbcolorUp
Show all 13 settings
SettingTypeDefaultVariable
Down Colorcolor#ff1100colorDown
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

MACD + Divergences [Alorse] is a momentum strategy that calculates the MACD oscillator and identifies regular and hidden divergences using pivot high and low points. It filters trade signals with dual Exponential Moving Averages (EMA 150 and 600) to ensure tra

Strategy v4 Oscillators & momentumDivergence Repaints
Updated 2 months ago · None stated GitHub repository of MACD + Divergences [Alorse]

MACD Crossover (tutorial)

by pineforge-4pass
193 stars

This strategy calculates the Moving Average Convergence Divergence indicator and plots the MACD line, signal line, and histogram in a separate pane. It enters long positions when the MACD line crosses above the signal line and enters short positions when it cr

Strategy v6 Oscillators & momentumMoving averages
Updated 2 days ago · Apache-2.0 GitHub repository of MACD Crossover (tutorial)

ADX Strategy

by hasnocool
106 stars

An ADX-based trend-following strategy that enters long positions when the positive directional indicator (DI+) crosses above the Average Directional Index (ADX) while ADX remains below a preset threshold and a fast EMA is above a slow EMA. It allows adding to

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of ADX Strategy

EMA Ribbon MACD

by iamrichardD
57 stars

This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta

Strategy v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon MACD

This strategy evaluates the dynamic relationship between price and a chosen moving average across six diagnostic dimensions: trend, respect, extension, compression, acceleration, and exhaustion. It plots a normalized relationship oscillator bounded between -10

Strategy v6 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]
7 stars

This strategy combines the Moving Average Convergence Divergence oscillator with an Exponential Moving Average trend filter. It enters long positions when the MACD histogram crosses above zero while price stays above the long-term EMA filter. Long trades close

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of MACD EMA Filter Strategy

More Trend 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