本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study("QuarryLake Indicator Map", overlay=false)
///Keltner channel///
nPeriod = input(title="Period", type=input.integer, defval=200, minval=1)
Mult = 5
xPrice = ema(hlc3, nPeriod)
xMove = ema(high - low, nPeriod)
xMoveMult = xMove * Mult
xUpper = xPrice + xMoveMult
xLower = xPrice - xMoveMult
// plot(xPrice, color=red, title="KSmid")
// p1 = plot(xUpper, color=white, title="KSup")
// p2 = plot(xLower, color=white, title="KSdn")
// fill(p1, p2, color = close > xUpper ? green : close < xLower ? red : white)
kclongcondition = close > xUpper
kcshortcondition = close < xLower
kccloselongcondition = crossunder(close, xUpper)
kccloseshortcondition = crossover(close, xLower)
///Volatility Stop///
length = input(3)
mult1 = input(1.5)
atr_ = atr(length)
max1 = 0.0
min1 = 0.0
is_uptrend_prev = false
stop = 0.0
vstop_prev = 0.0
vstop1 = 0.0
is_uptrend = false
is_trend_changed = false
max_ = 0.0
min_ = 0.0
vstop = 0.0
max1 := max(nz(max_[1]), close)
min1 := min(nz(min_[1]), close)
is_uptrend_prev := nz(is_uptrend[1], true)
stop := is_uptrend_prev ? max1 - mult1 * atr_ : min1 + mult1 * atr_
vstop_prev := nz(vstop[1])
vstop1 := is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend := close - vstop1 >= 0
is_trend_changed := is_uptrend != is_uptrend_prev
max_ := is_trend_changed ? close : max1
min_ := is_trend_changed ? close : min1
vstop := is_trend_changed ? is_uptrend ? max_ - mult1 * atr_ : min_ + mult1 * atr_ :
vstop1
// plot(vstop, color = is_uptrend ? green : red, style=line, linewidth=1)
vstoplongcondition = close > vstop
vstoplongclosecondition = crossunder(close, vstop)
vstopshortcondition = close < vstop
vstopshortclosecondition = crossover(close, vstop)
///Waddah Attar Explosion///
sensitivity = input(150, title="Sensitivity")
fastLength = input(20, title="FastEMA Length")
slowLength = input(40, title="SlowEMA Length")
channelLength = input(20, title="BB Channel Length")
mult = input(2.0, title="BB Stdev Multiplier")
DEAD_ZONE = nz(rma(tr(true), 100)) * 3.7
calc_macd(source, fastLength, slowLength) =>
fastMA = ema(source, fastLength)
slowMA = ema(source, slowLength)
fastMA - slowMA
calc_BBUpper(source, length, mult) =>
basis = sma(source, length)
dev = mult * stdev(source, length)
basis + dev
calc_BBLower(source, length, mult) =>
basis = sma(source, length)
dev = mult * stdev(source, length)
basis - dev
t1 = (calc_macd(close, fastLength, slowLength) -
calc_macd(close[1], fastLength, slowLength)) * sensitivity
t2 = (calc_macd(close[2], fastLength, slowLength) -
calc_macd(close[3], fastLength, slowLength)) * sensitivity
e1 = calc_BBUpper(close, channelLength, mult) -
calc_BBLower(close, channelLength, mult)
trendUp = t1 >= 0 ? t1 : 0
trendDown = t1 < 0 ? -1 * t1 : 0
waelongcondition = trendUp and trendUp > DEAD_ZONE and trendUp > e1
waeshortcondition = trendDown and trendDown > DEAD_ZONE and trendDown > e1
///Long///
longcondition = kclongcondition and vstoplongcondition and waelongcondition
closeconditionlong = kccloselongcondition or vstoplongclosecondition
///Short///
shortcondition = kcshortcondition and vstopshortcondition and waeshortcondition
closeconditionshort = kccloseshortcondition or vstopshortclosecondition
///plot Condition///
prevlong = 0
prevlong := longcondition ? 1 : closeconditionlong ? -1 : prevlong[1]
longfinal = longcondition and prevlong[1] == -1
prevlongcover = 0
prevlongcover := closeconditionlong ? 1 : longcondition ? -1 : prevlongcover[1]
longcoverfinal = closeconditionlong and prevlongcover[1] == -1
prevshort = 0
prevshort := shortcondition ? 1 : closeconditionshort ? -1 : prevshort[1]
shortfinal = shortcondition and prevshort[1] == -1
prevshortcover = 0
prevshortcover := closeconditionshort ? 1 : shortcondition ? -1 : prevshortcover[1]
shortcoverfinal = closeconditionshort and prevshortcover[1] == -1
//plot///
plotshape(longfinal, color=color.green, style=shape.circle, size=size.tiny, location=location.bottom)
plotshape(longcoverfinal, color=color.aqua, style=shape.xcross, size=size.tiny, location=location.bottom)
plotshape(shortfinal, color=color.red, style=shape.circle, size=size.tiny, location=location.bottom)
plotshape(shortcoverfinal, color=color.fuchsia, style=shape.xcross, size=size.tiny, location=location.bottom)
barcolor(prevlong > 0 ? color.green : na, offset=1)
barcolor(prevshort > 0 ? color.red : na, offset=1)
noposition = prevlong < 1 and prevshort < 1
plotshape(0, "KC", shape.square, location.absolute, color=kclongcondition ? color.green : kcshortcondition ? color.red : color.white, size=size.tiny, transp=0)
plotshape(-1, "Vstop", shape.square, location.absolute, color=vstoplongcondition ? color.green : vstopshortcondition ? color.red : color.white, size=size.tiny, transp=0)
plotshape(-2, "WAE", shape.square, location.absolute, color=waelongcondition ? color.green : waeshortcondition ? color.red : color.white, size=size.tiny, transp=0)
///alert///
alertcondition(longfinal, title='Long Entry', message='Long Entry!')
alertcondition(longcoverfinal, title='Long Cover Alert', message='Long Cover Tradingview Alert')
alertcondition(shortfinal, title='Short Entry', message='Short Entry!')
alertcondition(shortcoverfinal, title='Short Cover Alert', message='Short Cover Tradingview Alert')
///Save Hong Kong, the revolution of our times.///