RSI Scalping & Swing Signals With Alerts

TrendFriendIndicators · study · 89 行 · 点赞 1,690 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// © FriendOfTheTrend
//@version=5
indicator("RSI Scalping & Swing Signals With Alerts", shorttitle="RSI Scalper", overlay=false)
 
//Inputs
source = input.source(close, title="RSI Source")
length = input.int(3, title="RSI Length")
maLength = input.int(2, title="Short Moving Average Length")
rsiLength = input.int(5, title="RSI Smoothing Length")
longMaLength = input.int(30, title="Long Moving Average Length")
longMaOn = input.bool(true, title="Turn Long MA On/Off")
signalsOn = input.bool(true, title="Turn Bull/Bear Cross Signals On/Off")
 
//Turn Bullish/Bearish Table On/Off
tableOn = input.bool(true, title="Turn Bull & Bear Label On/Off")
 
//RSI
rsi = ta.rsi(source, length)
smoothRSI = ta.sma(rsi, rsiLength)
 
//Moving Average
ma = ta.rma(smoothRSI, maLength)
 
//Long Moving Average
longMa = ta.sma(smoothRSI, longMaLength)
 
//Plot RSI & Mid Line
maLine = plot(ma, title="MA Line", color=smoothRSI > ma ? #00e67600 : #ff525200, linewidth=1, style=plot.style_line)
rsiLine = plot(smoothRSI, title="RSI Line", color=smoothRSI > ma ? #00e67600 : #ff525200, linewidth=1, style=plot.style_line)
longMaPlot = plot(longMaOn ? longMa : na, title="Long MA Line", color=smoothRSI > longMa ? color.lime : color.red, linewidth=2, style=plot.style_line)
midLine = plot(50,"Mid Line", color.white)
resLine = plot(20,"20 Line", #00bcd450)
supLine = plot(80,"80 Line", #00bcd450)
MAsignalUp = ta.crossover(smoothRSI, longMa)
MAsignalDown = ta.crossunder(smoothRSI, longMa)
plotshape(signalsOn ? MAsignalUp : na, title="Cross MA Signal Up", style=shape.circle, location=location.bottom, color=color.lime, size=size.tiny)
plotshape(signalsOn ? MAsignalDown : na, title="Cross MA Signal Down", style=shape.circle, location=location.bottom, color=color.red, size=size.tiny)
 
//Background Fill
fill(rsiLine, maLine, color = smoothRSI > ma ? #00e676 : #ff5252, title = "Color Fill RSI Line To MA Line")
fill(maLine, midLine, color = ma < smoothRSI and ma >= 50 ? #00e67630 : na, title = "Color Fill MA Line To Mid Line Above Mid Line")
fill(rsiLine, midLine, color = ma > smoothRSI and smoothRSI >= 50 ? #00e67630 : na, title = "Color Fill RSI Line To Mid Line Above Mid Line")
fill(rsiLine, midLine, color = ma < smoothRSI and smoothRSI < 50 ? #ff525235 : na, title = "Color Fill RSI Line To Mid Line Below Mid Line")
fill(maLine, midLine, color = ma > smoothRSI and ma < 50 ? #ff525235 : na, title = "Color Fill MA Line To Mid Line Below Mid Line")
fill(maLine, longMaPlot, color = ma < smoothRSI and ma >= longMa ? #00e67630 : na, title = "Color Fill MA Line To Long MA Line")
fill(rsiLine, longMaPlot, color = ma > smoothRSI and smoothRSI >= longMa ? #00e67630 : na, title = "Color Fill RSI Line To Long MA Line")
fill(maLine, longMaPlot, color = ma < smoothRSI and ma < longMa ? #ff525235 : na, title = "Color Fill MA Line To Long MA Line")
fill(rsiLine, longMaPlot, color = ma > smoothRSI and smoothRSI < longMa ? #ff525235 : na, title = "Color Fill RSI Line To Long MA Line")
 
//Buy/Sell RSI
sell = smoothRSI < ma
buy = smoothRSI > ma
 
//Label Info
labelColor = color.new(#000000, 0)
labelText = ""
labelColor2 = color.new(#000000, 0)
labelText2 = ""
 
//Label Info Logic
if buy
    labelColor := color.lime
    labelText := string("Bullish RSI")
else if sell
    labelColor := color.red
    labelText := string("Bearish RSI")
else
    labelColor := color.blue
    labelText := string("Neutral RSI")
    
//Second Label Logic
if smoothRSI > longMa and ma > longMa and longMaOn
    labelColor2 := color.lime
    labelText2 := string("Above Long MA")
else if smoothRSI < longMa and ma < longMa and longMaOn
    labelColor2 := color.red
    labelText2 := string("Below Long MA")
 
//Plot Label
dataTable = table.new(position.top_right, columns=1, rows=2, bgcolor=#00000000)
if tableOn and barstate.islast
    table.cell(table_id=dataTable, column=0, row=0, text=labelText, height=0, text_color=color.white, text_halign=text.align_left, text_valign= text.align_center, bgcolor=labelColor)
    table.cell(table_id=dataTable, column=0, row=1, text=labelText2, height=0, text_color=color.white, text_halign=text.align_left, text_valign= text.align_center, bgcolor=labelColor2)
 
//Alerts
alertcondition(ta.crossover(smoothRSI, ma), title="RSI Ribbon Turning Bullish", message="RSI Ribbon Turning Bullish")
alertcondition(ta.crossunder(smoothRSI, ma), title="RSI Ribbon Turning Bearish", message="RSI Ribbon Turning Bearish")
alertcondition(ta.crossover(smoothRSI, longMa), title="RSI Ribbon Crossing Above Long MA", message="RSI Ribbon Crossing Above Long MA")
alertcondition(ta.crossunder(smoothRSI, longMa), title="RSI Ribbon Crossing Below Long MA", message="RSI Ribbon Crossing Below Long MA")

← 返回列表