PineScript16 Candlestick Rejection V1.0.0

voonology · study · 198 行 · 点赞 18 · TradingView 原页

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

Pine Script

//@version=6
indicator("PineScript16 Candlestick Rejection V1.0.0",
     shorttitle="PS16 Rejection",
     overlay=true)
 
// INPUTS
groupPattern = "Rejection Pattern"
 
wickRatio = input.float(
     2.0, "Minimum Wick / Body",
     minval=0.5, step=0.1,
     group=groupPattern)
 
minWickPct = input.float(
     50.0, "Minimum Wick % of Range",
     minval=1, maxval=100,
     group=groupPattern)
 
closePct = input.float(
     35.0, "Maximum Close Distance %",
     minval=1, maxval=50,
     group=groupPattern)
 
// EMA FILTER
groupEMA = "EMA Trend Filter"
 
useEMA = input.bool(
     true, "Enable EMA Filter",
     group=groupEMA)
 
fastLen = input.int(
     20, "Fast EMA",
     minval=1, group=groupEMA)
 
slowLen = input.int(
     50, "Slow EMA",
     minval=1, group=groupEMA)
 
// RSI FILTER
groupRSI = "RSI Momentum Filter"
 
useRSI = input.bool(
     false, "Enable RSI Filter",
     group=groupRSI)
 
rsiLen = input.int(
     14, "RSI Length",
     minval=1, group=groupRSI)
 
// ATR FILTER
groupATR = "ATR Wick Filter"
 
useATR = input.bool(
     false, "Enable ATR Filter",
     group=groupATR)
 
atrLen = input.int(
     14, "ATR Length",
     minval=1, group=groupATR)
 
atrMult = input.float(
     0.3, "Minimum Wick ATR Multiple",
     minval=0.0, step=0.1,
     group=groupATR)
 
// DISPLAY
groupDisplay = "Display"
 
showEMA = input.bool(
     true, "Show EMA Lines",
     group=groupDisplay)
 
showSignals = input.bool(
     true, "Show Rejection Signals",
     group=groupDisplay)
 
// CANDLE CALCULATIONS
body = math.abs(close - open)
 
candleRange = high - low
 
upperWick = high - math.max(open, close)
 
lowerWick = math.min(open, close) - low
 
validRange = candleRange > 0
 
safeBody = math.max(body, syminfo.mintick)
 
lowerWickPct = validRange ?
     lowerWick / candleRange * 100 : 0.0
 
upperWickPct = validRange ?
     upperWick / candleRange * 100 : 0.0
 
bullClosePct = validRange ?
     (high - close) / candleRange * 100 : 100.0
 
bearClosePct = validRange ?
     (close - low) / candleRange * 100 : 100.0
 
// RAW REJECTION PATTERNS
bullishPattern = validRange and
     lowerWick >= safeBody * wickRatio and
     lowerWickPct >= minWickPct and
     bullClosePct <= closePct
 
bearishPattern = validRange and
     upperWick >= safeBody * wickRatio and
     upperWickPct >= minWickPct and
     bearClosePct <= closePct
 
// EMA CALCULATIONS
emaFast = ta.ema(close, fastLen)
 
emaSlow = ta.ema(close, slowLen)
 
bullTrend = emaFast > emaSlow and
     close > emaFast
 
bearTrend = emaFast < emaSlow and
     close < emaFast
 
emaBullOK = not useEMA or bullTrend
 
emaBearOK = not useEMA or bearTrend
 
// RSI CALCULATIONS
rsiValue = ta.rsi(close, rsiLen)
 
rsiBullOK = not useRSI or rsiValue > 50
 
rsiBearOK = not useRSI or rsiValue < 50
 
// ATR CALCULATIONS
atrValue = ta.atr(atrLen)
 
atrBullOK = not useATR or
     lowerWick >= atrValue * atrMult
 
atrBearOK = not useATR or
     upperWick >= atrValue * atrMult
 
// CONFIRMED SIGNALS
bullishSignal = barstate.isconfirmed and
     bullishPattern and
     emaBullOK and
     rsiBullOK and
     atrBullOK
 
bearishSignal = barstate.isconfirmed and
     bearishPattern and
     emaBearOK and
     rsiBearOK and
     atrBearOK
 
// EMA PLOTS
plot(showEMA ? emaFast : na,
     "Fast EMA",
     color=color.aqua,
     linewidth=2)
 
plot(showEMA ? emaSlow : na,
     "Slow EMA",
     color=color.orange,
     linewidth=2)
 
// REJECTION SIGNALS
plotshape(
     showSignals and bullishSignal,
     title="Bullish Rejection",
     style=shape.labelup,
     location=location.belowbar,
     color=color.lime,
     text="BUY",
     textcolor=color.black,
     size=size.tiny)
 
plotshape(
     showSignals and bearishSignal,
     title="Bearish Rejection",
     style=shape.labeldown,
     location=location.abovebar,
     color=color.red,
     text="SELL",
     textcolor=color.white,
     size=size.tiny)
 
// ALERT CONDITIONS
alertcondition(
     bullishSignal,
     title="Bullish Rejection Alert",
     message="PineScript16 Bullish Rejection | {{ticker}} | {{interval}} | Close: {{close}}")
 
alertcondition(
     bearishSignal,
     title="Bearish Rejection Alert",
     message="PineScript16 Bearish Rejection | {{ticker}} | {{interval}} | Close: {{close}}")

← 返回列表