本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator(title='Strong Pullback Indicator [Rami_LB]', shorttitle='Strong Pullback Indicator', overlay=true)
var GRP1 = "RSI"
overboughtCountInput = input(4, title='RSI - Overbought Conditions (Standard: 4)', group = GRP1)
oversoldCountInput = input(4, title='RSI - Oversold Conditions (Standard: 4)', group = GRP1)
rsiLength = input(14, title='RSI - Length', group = GRP1)
rsiSource = input.source(close, title='RSI - Source', group = GRP1)
var GRP2 = "Bullish vs. Bearish Candle Counter"
length = input(100, title='Number of Candles to Analyze', group = GRP2)
bullishPercentage = input(60, title='Bullish Percentage (%)', group = GRP2)
bearishPercentage = input(60, title='Bearish Percentage (%)', group = GRP2)
var GRP3 = "TP/SL Lines"
showTPLines = input(false, title='TP/SL Lines - Show TP Lines', group = GRP3)
showSLLines = input(false, title='TP/SL Lines - Show SL Lines', group = GRP3)
targetValueTP = input.float(1.0, title='TP/SL Lines - Target for TP', step=0.1, group = GRP3)
targetValueSL = input.float(1.0, title='TP/SL Lines - Target for SL', step=0.1, group = GRP3)
var GRP4 = "Alerts"
alertEnabled = input(false, title='Enable Alert', group = GRP4)
bullishCount() =>
bullishCandles = 0
for i = 0 to length - 1 by 1
if close[i] > open[i]
bullishCandles += 1
bullishCandles
bullishCandles
bearishCount() =>
bearishCandles = 0
for i = 0 to length - 1 by 1
if close[i] < open[i]
bearishCandles += 1
bearishCandles
bearishCandles
bullishCandlesCount = bullishCount()
bearishCandlesCount = bearishCount()
bullishPercentageValue = bullishCandlesCount * 100 / length
bearishPercentageValue = bearishCandlesCount * 100 / length
bullishCondition = bullishPercentageValue >= bullishPercentage ? true : false
bearishCondition = bearishPercentageValue >= bearishPercentage ? true : false
fTop = high[4] < high[3] and high[3] < high[2] and high[2] < high[1] and high[1] > high[0] and low[1] > low[0] and open[0] > close[0]
fBottom = low[4] > low[3] and low[3] > low[2] and low[2] > low[1] and low[1] < low[0] and high[1] < high[0] and close[0] > open[0]
rsiConditionTop(offset) =>
rsi1m = ta.rsi(rsiSource[offset], rsiLength)
rsi5m = request.security(syminfo.tickerid, '5', ta.rsi(rsiSource[offset], rsiLength))
rsi15m = request.security(syminfo.tickerid, '15', ta.rsi(rsiSource[offset], rsiLength))
rsi30m = request.security(syminfo.tickerid, '30', ta.rsi(rsiSource[offset], rsiLength))
rsi1h = request.security(syminfo.tickerid, '60', ta.rsi(rsiSource[offset], rsiLength))
rsi2h = request.security(syminfo.tickerid, '120', ta.rsi(rsiSource[offset], rsiLength))
rsi4h = request.security(syminfo.tickerid, '240', ta.rsi(rsiSource[offset], rsiLength))
rsi1d = request.security(syminfo.tickerid, 'D', ta.rsi(rsiSource[offset], rsiLength))
overboughtCount = 0
overboughtCount := rsi1m > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi5m > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi15m > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi30m > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi1h > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi2h > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi4h > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount := rsi1d > 70 ? overboughtCount + 1 : overboughtCount
overboughtCount >= overboughtCountInput
rsiConditionBottom(offset) =>
rsi1m = ta.rsi(rsiSource[offset], rsiLength)
rsi5m = request.security(syminfo.tickerid, '5', ta.rsi(rsiSource[offset], rsiLength))
rsi15m = request.security(syminfo.tickerid, '15', ta.rsi(rsiSource[offset], rsiLength))
rsi30m = request.security(syminfo.tickerid, '30', ta.rsi(rsiSource[offset], rsiLength))
rsi1h = request.security(syminfo.tickerid, '60', ta.rsi(rsiSource[offset], rsiLength))
rsi2h = request.security(syminfo.tickerid, '120', ta.rsi(rsiSource[offset], rsiLength))
rsi4h = request.security(syminfo.tickerid, '240', ta.rsi(rsiSource[offset], rsiLength))
rsi1d = request.security(syminfo.tickerid, 'D', ta.rsi(rsiSource[offset], rsiLength))
oversoldCount = 0
oversoldCount := rsi1m < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi5m < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi15m < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi30m < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi1h < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi2h < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi4h < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount := rsi1d < 30 ? oversoldCount + 1 : oversoldCount
oversoldCount >= oversoldCountInput
rsiMetTop = rsiConditionTop(0) or rsiConditionTop(1) or rsiConditionTop(2) or rsiConditionTop(3) or rsiConditionTop(4)
rsiMetBottom = rsiConditionBottom(0) or rsiConditionBottom(1) or rsiConditionBottom(2) or rsiConditionBottom(3) or rsiConditionBottom(4)
fTop := fTop and rsiMetTop
fBottom := fBottom and rsiMetBottom
plotshape(fTop, title='Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), offset=0, size=size.small)
plotshape(fBottom, title='Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), offset=0, size=size.small)
var float slPriceTop = na
var float tpPriceTop = na
if fTop
slPriceTop := high[1] + (high[1] - close[0]) * targetValueSL
tpPriceTop := close[0] - (high[1] - close[0]) * 2 * targetValueTP
tpPriceTop
var float slPriceBottom = na
var float tpPriceBottom = na
if fBottom
slPriceBottom := low[1] - (close[0] - low[1]) * targetValueSL
tpPriceBottom := close[0] + (close[0] - low[1]) * 2 * targetValueTP
tpPriceBottom
bgcolor(bullishCondition ? color.new(color.red, 90) : bearishCondition ? color.new(color.green, 90) : na, title='Candle Counter Color')
if fTop and showSLLines
line.new(x1=bar_index, y1=slPriceTop, x2=bar_index + 6, y2=slPriceTop, color=color.red, width=1)
if fTop and showTPLines
line.new(x1=bar_index, y1=tpPriceTop, x2=bar_index + 6, y2=tpPriceTop, color=color.green, width=1)
if fBottom and showSLLines
line.new(x1=bar_index, y1=slPriceBottom, x2=bar_index + 6, y2=slPriceBottom, color=color.red, width=1)
if fBottom and showTPLines
line.new(x1=bar_index, y1=tpPriceBottom, x2=bar_index + 6, y2=tpPriceBottom, color=color.green, width=1)
alertcondition(alertEnabled and fTop, title='Top Fractal Alert', message='A Top Fractal has been generated!')
alertcondition(alertEnabled and fBottom, title='Bottom Fractal Alert', message='A Bottom Fractal has been generated!')