本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// @version=5
//
// LNL Keltner Candles with Reversals
//
// Mean reversion reversal candles with custom painted candles based on the price touch or close above or below keltner channel limits (upper & lower bands).
//
// Can serve as an additional indicator or as the mean reversion tool.
//
// Created by L&L Capital
//
indicator("LNL Keltner Candles", shorttitle = "Keltner Candles", overlay=true)
// Inputs
length = input(defval=13, title="Length")
factor = input(defval=1.5, title="ATR Factor")
pricetypeUpper = input(high, title="Price Type Upper")
pricetypeLower = input(low, title="Price Type Lower")
// Keltner Channels Calculations
shift = factor * ta.atr(length)
average = ta.ema(close,length)
upperband = average + shift
lowerband = average - shift
upperlimit = pricetypeUpper > upperband
lowerlimit = pricetypeLower < lowerband
// Mean Reversion Arrows Calculations
UpBar = close > open
DnBar = close < open
AvgRange = 0.05 * math.avg(high - low, 20)
// Keltner Channels Plots & Colors
[middle, upper, lower] = ta.kc(close, length, factor)
plot(middle, color=color.new(#1848cc,0),title="Avg",display = display.none)
plot(upper, color=color.new(#1848cc,0),title="Upper Band",display = display.none)
plot(lower, color=color.new(#1848cc,0),title="Lower Band",display = display.none)
bar_color = upperlimit ? color.new(#ff0000,0) : lowerlimit ? color.new(#27c22e,0) : color.new(color.white,0)
barcolor(color=bar_color)
// Reversal Arrows Plots & Colors
SignalUp = DnBar[3] and DnBar[2] and DnBar[1] and UpBar[0] and close[3] >= close[2] and low[1] > open[0] and close[2] >= close[1] and low <= lowerband
plotshape(SignalUp,title='Reversal Up',style=shape.triangleup,location=location.belowbar,color=(color.purple),size=size.tiny)
SignalDown = UpBar[3] and UpBar[2] and UpBar[1] and DnBar[0] and close[3] <= close[2] and low[1] < open[0] and close[2] <= close[1] and high >= upperband
plotshape(SignalDown,title='Reversal Down',style=shape.triangledown,location=location.abovebar,color=(color.purple),size=size.tiny)