PineScript16 Williams %R Pro

voonology · study · 165 行 · 点赞 32 · TradingView 原页

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

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Voonology
// PineScript16 — Developed by Voonology
// Version: 1.0.0
//@version=6
indicator(
     "Williams %R Pro",
     shorttitle = "WPR Pro",
     overlay = false)
 
//────────────────────────────
// INPUTS
//────────────────────────────
wrLength = input.int(54, "Williams %R Length", minval = 1)
 
emaPeriod = input.int(20, "EMA Period", minval = 1)
 
rsiPeriod = input.int(7, "RSI Period", minval = 1)
rsiBuyLevel = input.float(52, "RSI Buy Level")
rsiSellLevel = input.float(52, "RSI Sell Level")
 
macdFast = input.int(12, "MACD Fast Length", minval = 1)
macdSlow = input.int(26, "MACD Slow Length", minval = 1)
macdSignal = input.int(9, "MACD Signal Length", minval = 1)
 
//────────────────────────────
// WILLIAMS %R
//────────────────────────────
highestHigh = ta.highest(high, wrLength)
lowestLow = ta.lowest(low, wrLength)
 
wrRange = math.max(highestHigh - lowestLow, syminfo.mintick)
percentR = 100 * (close - highestHigh) / wrRange
 
//────────────────────────────
// EMA FILTER
//────────────────────────────
emaValue = ta.ema(close, emaPeriod)
 
bullTrend = close > emaValue
bearTrend = close < emaValue
 
//────────────────────────────
// RSI FILTER
//────────────────────────────
rsiValue = ta.rsi(close, rsiPeriod)
 
rsiBull = rsiValue > rsiBuyLevel
rsiBear = rsiValue < rsiSellLevel
 
//────────────────────────────
// MACD FILTER
//────────────────────────────
[macdLine, signalLine, histLine] = ta.macd(
     close,
     macdFast,
     macdSlow,
     macdSignal)
 
macdBull = macdLine > 0 and macdLine > signalLine
macdBear = macdLine < 0 and macdLine < signalLine
 
//────────────────────────────
// SIGNAL CONDITIONS
//────────────────────────────
longCond =
     ta.crossover(percentR, -20) and
     bullTrend and
     rsiBull and
     macdBull
 
shortCond =
     ta.crossunder(percentR, -80) and
     bearTrend and
     rsiBear and
     macdBear
 
//────────────────────────────
// ALERT CONDITIONS
//────────────────────────────
alertcondition(
     longCond,
     title = "Williams %R Long",
     message = "LONG {{ticker}} @ {{close}}")
 
alertcondition(
     shortCond,
     title = "Williams %R Short",
     message = "SHORT {{ticker}} @ {{close}}")
 
// Optional realtime alerts
if longCond
    alert(
         "LONG " + syminfo.ticker +
         " | Price=" + str.tostring(close, "#.##") +
         " | RSI=" + str.tostring(rsiValue, "#.##") +
         " | MACD=" + str.tostring(macdLine, "#.####"),
         alert.freq_once_per_bar_close)
 
if shortCond
    alert(
         "SHORT " + syminfo.ticker +
         " | Price=" + str.tostring(close, "#.##") +
         " | RSI=" + str.tostring(rsiValue, "#.##") +
         " | MACD=" + str.tostring(macdLine, "#.####"),
         alert.freq_once_per_bar_close)
 
//────────────────────────────
// PLOTS
//────────────────────────────
wrColor =
     percentR > -20 ? color.red :
     percentR < -80 ? color.lime :
     color.blue
 
plot(
     percentR,
     title = "Williams %R",
     color = wrColor,
     linewidth = 2)
 
hline(-20, "Overbought", color = color.red)
hline(-80, "Oversold", color = color.green)
hline(-50, "Midline", color = color.gray)
 
plotchar(
     longCond,
     title = "BUY",
     char = "▲",
     location = location.bottom,
     color = color.lime,
     size = size.tiny)
 
plotchar(
     shortCond,
     title = "SELL",
     char = "▼",
     location = location.top,
     color = color.red,
     size = size.tiny)
 
// Data Window Values
plot(
     rsiValue,
     title = "RSI(7)",
     color = color.purple,
     display = display.data_window)
 
plot(
     macdLine,
     title = "MACD Line",
     color = color.orange,
     display = display.data_window)
 
plot(
     signalLine,
     title = "MACD Signal",
     color = color.gray,
     display = display.data_window)
 
plot(
     emaValue,
     title = "EMA",
     color = color.yellow,
     display = display.data_window)

← 返回列表