[LunaOwl] 智慧型RSI

LunaOwl · study · 103 行 · 点赞 502 · TradingView 原页

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

Pine Script

//--------------------------*
//-- This source code is subject to the terms of the Mozilla Public License 2.0
//-- the URL at https://mozilla.org/MPL/2.0/
//-- 開源代碼受Mozilla公眾授權條款2.0版規範, 網址是https://mozilla.org/MPL/2.0/
//
//@versoin=4
//
//  作品: [LunaOwl] 智慧型RSI
//
////////////////////////////////
//     ~~!!*(๑╹◡╹๑) **       //
//  製作:  @LunaOwl 彭彭      //
//  日期:  2020年04月13日     //
//  修改1: 2020年04月15日     //
//  修改2: 2020年04月17日     //
//  修改3: 2020年04月20日     //
////////////////////////////////
//
//--------------------------*
//-- after simple improvement and addition of logical judgment, it becomes a passive judge 
//-- from subjective judgments, avoid the shortcomings of peoples in watching passivation,
//-- and the trade can be more consistent.
//-- 經過簡單的改良與添加邏輯, 使RSI從主觀判斷成為被動的確認指標, 避免人在判斷鈍化上的缺點,
//-- 並且使得交易有一致性。
//
//
//--------------------------*
//ver.2- adjust new style design and create two options.
//修改2: 調整新的設計樣式, 建立兩個選項。
//
//--------------------------*
//ver.3- Create alert condition. maybe I should refer to the Alert Creation Framework,
//       there is also room for improvement.
//修改3: 建立快訊選項, 我應該參考警報創建框架,所以未來還有進步的空間。
//
//--------------------------*
 
study(title = "[LunaOwl] 智慧型RSI", shorttitle = "智慧型RSI")
 
//==輸入參數==//
 
src          = input(close, title = "數據來源")
rsi_1_len    = input(14, minval = 1, title = "RSI期數1")
rsi_2_len    = input( 5, minval = 1, title = "RSI期數2")
rsi_ema_len  = input(14, minval = 1, title = "指數平均期數")
overbought   = input(70, minval = 1, title = "設定超買數值")
oversold     = input(30, minval = 1, title = "設定超賣數值")
 
//==建立選項==//
 
button_candle  = input(true,  "開啟蠟燭線趨勢")
button_bgcolor = input(false, "開啟指標背景色")
 
//==計算邏輯==//
 
//直接套RSI函式計算
rsi_1    = rsi(src, rsi_1_len)
rsi_2    = rsi(src, rsi_2_len)
rsi_ema  = ema(rsi_1, rsi_ema_len)
 
//==調色盤==//
 
color_long    = #009688   //深青色
color_short   = #FF5252   //洋紅色
color_neutral = #FFD600   //淡黃色
color_over    = #B2B5BE   //淡灰色
 
//==設定樣式==//
 
rsi_1_color = rsi_1 > rsi_ema ? color_long : color_short
 
plot(rsi_1, title = "RSI期數1", linewidth = 2, transp = 0, color = rsi_1_color)
A = plot(rsi_2  , title = "RSI期數2"   , linewidth = 1, transp = 35, color = color_neutral)
B = plot(rsi_ema, title = "RSI指數均線", linewidth = 1, transp =  0, color = color_neutral)
 
background_color = rsi_2 > rsi_ema ? color_long : color_short
fill(A, B, title = "RSI背景填色1", color = background_color, transp = 60)
 
//==繪製燭台/背景==//
 
bgcolor(not button_bgcolor ? na : background_color, title = "背景底色", transp = 85)
barcolor(not button_candle ? na : background_color, title = "燭台趨勢")
 
//==繪製超買/超賣/基準線==//
 
C = plot(overbought, title = "超買線顏色", linewidth = 1, transp = 50, color = color_over)
D = plot(oversold,   title = "超賣線顏色", linewidth = 1, transp = 50, color = color_over)
fill(C, D, title = "RSI背景填色2", color = color_over, transp = 88)
 
//==繪製基準線==//
 
plot(50, title = "基準線", linewidth = 1, transp = 0, color = color_neutral)
 
//==設定快訊==//
 
//可以按快捷鍵"alt+a"建立快訊
alertcondition(rsi_2 > rsi_ema, 
     title   = "設置買入快訊", 
     message = "提示: RSI期數2向上穿越均線,發送買入快訊")
  
alertcondition(rsi_2 < rsi_ema, 
     title   = "設置賣出快訊",
     message = "提示: RSI期數2向下跌穿均線,發送賣出快訊")

← 返回列表