本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Smart Stochastic PRO Embedded RSI", shorttitle="SS PRO RSI", overlay=false)
//═══════════════════════════════════════════════════════════
// STOCHASTIC SOURCE MODE
//═══════════════════════════════════════════════════════════
useStochRSI = input.bool(false, "Use Stochastic RSI Source")
//═══════════════════════════════════════════════════════════
// STOCHASTIC SETTINGS
//═══════════════════════════════════════════════════════════
kLen = input.int(14, "K Length", minval=1)
kSmooth = input.int(3, "K Smoothing", minval=1)
dLen = input.int(3, "D Length", minval=1)
rsiLen = input.int(14, "RSI Length")
sens = input.float(2.0, "Momentum Sensitivity", step=0.1)
//═══════════════════════════════════════════════════════════
// COLORS
//═══════════════════════════════════════════════════════════
upColor = input.color(color.lime, "Bull Color")
downColor = input.color(color.red, "Bear Color")
flatColor = input.color(color.gray, "Neutral Color")
//═══════════════════════════════════════════════════════════
// TRIGGER COLOR MODE
//═══════════════════════════════════════════════════════════
trigColorMode = input.string(
"HA + ST + UT Voting",
"Trigger Color Mode",
options=["Default", "HA + ST + UT Voting"])
trigBullCol = input.color(color.new(#00E676, 0), "Bull Trigger")
trigBearCol = input.color(color.new(#FF1744, 0), "Bear Trigger")
trigNeutCol = input.color(color.new(#B0BEC5, 0), "Neutral Trigger")
//═══════════════════════════════════════════════════════════
// FILTER TOGGLES
//═══════════════════════════════════════════════════════════
useHA = input.bool(true, "Use Heiken Ashi")
useST = input.bool(true, "Use Supertrend")
useUT = input.bool(true, "Use UT Bot")
//═══════════════════════════════════════════════════════════
// SUPERTREND SETTINGS
//═══════════════════════════════════════════════════════════
stLength = input.int(10, "ST ATR Length")
stFactor = input.float(3.0, "ST Factor", step=0.1)
//═══════════════════════════════════════════════════════════
// UT BOT SETTINGS
//═══════════════════════════════════════════════════════════
utKeyValue = input.float(1.0, "UT Key Value", step=0.1)
utATRLen = input.int(1, "UT ATR Period")
//═══════════════════════════════════════════════════════════
// HEIKEN ASHI
//═══════════════════════════════════════════════════════════
haClose = (open + high + low + close) / 4
var float haOpen = na
haOpen := na(haOpen[1]) ?
(open + close) / 2 :
(haOpen[1] + haClose[1]) / 2
haBull = haClose > haOpen
haBear = haClose < haOpen
//═══════════════════════════════════════════════════════════
// SUPERTREND
//═══════════════════════════════════════════════════════════
[stLine, stDir] = ta.supertrend(stFactor, stLength)
stBull = stDir < 0
stBear = stDir > 0
//═══════════════════════════════════════════════════════════
// UT BOT
//═══════════════════════════════════════════════════════════
xATR = ta.atr(utATRLen)
nLoss = utKeyValue * xATR
utSrc = haClose
var float xATRTS = 0.0
xATRTS :=
utSrc > nz(xATRTS[1]) and utSrc[1] > nz(xATRTS[1]) ?
math.max(nz(xATRTS[1]), utSrc - nLoss) :
utSrc < nz(xATRTS[1]) and utSrc[1] < nz(xATRTS[1]) ?
math.min(nz(xATRTS[1]), utSrc + nLoss) :
utSrc > nz(xATRTS[1]) ?
utSrc - nLoss :
utSrc + nLoss
utBull = utSrc > xATRTS
utBear = utSrc < xATRTS
//═══════════════════════════════════════════════════════════
// VOTING SYSTEM
//═══════════════════════════════════════════════════════════
score = 0
score := score + (
useHA ?
(haBull ? 1 : haBear ? -1 : 0)
: 0)
score := score + (
useST ?
(stBull ? 1 : stBear ? -1 : 0)
: 0)
score := score + (
useUT ?
(utBull ? 1 : utBear ? -1 : 0)
: 0)
votingColor =
score > 0 ? trigBullCol :
score < 0 ? trigBearCol :
trigNeutCol
//═══════════════════════════════════════════════════════════
// NORMAL STOCHASTIC
//═══════════════════════════════════════════════════════════
stochRaw = ta.stoch(close, high, low, kLen)
//═══════════════════════════════════════════════════════════
// STOCH RSI
//═══════════════════════════════════════════════════════════
rsiValue = ta.rsi(close, rsiLen)
rsiLowest = ta.lowest(rsiValue, kLen)
rsiHighest = ta.highest(rsiValue, kLen)
stochRsiRaw =
100 * (rsiValue - rsiLowest) /
math.max(rsiHighest - rsiLowest, 0.001)
//═══════════════════════════════════════════════════════════
// SELECT SOURCE
//═══════════════════════════════════════════════════════════
baseSource =
useStochRSI ?
stochRsiRaw :
stochRaw
//═══════════════════════════════════════════════════════════
// FINAL K & D
//═══════════════════════════════════════════════════════════
k = ta.sma(baseSource, kSmooth)
d = ta.sma(k, dLen)
//═══════════════════════════════════════════════════════════
// MOMENTUM COLORS
//═══════════════════════════════════════════════════════════
change = k - k[1]
up = change > sens
down = change < -sens
trendColor =
up ? upColor :
down ? downColor :
flatColor
//═══════════════════════════════════════════════════════════
// TRIGGER COLOR
//═══════════════════════════════════════════════════════════
trigColor =
trigColorMode == "HA + ST + UT Voting" ?
votingColor :
d > d[1] ?
upColor :
d < d[1] ?
downColor :
flatColor
//═══════════════════════════════════════════════════════════
// SIGNALS
//═══════════════════════════════════════════════════════════
buySignal =
ta.crossover(k, d) and
k < 20 and
score > 0
sellSignal =
ta.crossunder(k, d) and
k > 80 and
score < 0
//═══════════════════════════════════════════════════════════
// BACKGROUND ZONES
//═══════════════════════════════════════════════════════════
bgcolor(k > 80 ? color.new(color.red, 85) : na)
bgcolor(k < 20 ? color.new(color.green, 85) : na)
//═══════════════════════════════════════════════════════════
// LEVELS
//═══════════════════════════════════════════════════════════
hline(80, "Overbought", color=color.red)
hline(50, "Midline", color=color.gray)
hline(20, "Oversold", color=color.green)
//═══════════════════════════════════════════════════════════
// PLOTS
//═══════════════════════════════════════════════════════════
plot(k, "K Line", color=trendColor, linewidth=3)
plot(d, "D Line", color=trigColor, linewidth=2)
//═══════════════════════════════════════════════════════════
// SIGNAL SHAPES
//═══════════════════════════════════════════════════════════
plotshape(
buySignal,
title="BUY",
location=location.bottom,
style=shape.triangleup,
color=color.lime,
size=size.small)
plotshape(
sellSignal,
title="SELL",
location=location.top,
style=shape.triangledown,
color=color.red,
size=size.small)
//═══════════════════════════════════════════════════════════
// ALERTS
//═══════════════════════════════════════════════════════════
alertcondition(
buySignal,
title="BUY ALERT",
message="Smart Stochastic BUY Signal")
alertcondition(
sellSignal,
title="SELL ALERT",
message="Smart Stochastic SELL Signal")
alertcondition(
score > 0 and score[1] <= 0,
title="Bullish Flip",
message="{{ticker}} turned BULLISH")
alertcondition(
score < 0 and score[1] >= 0,
title="Bearish Flip",
message="{{ticker}} turned BEARISH")