UT Bot + Hull MA Confirmed Signal Delay

not_a_mad_scientist · study · 33 行 · 点赞 1,539 · TradingView 原页

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

Pine Script

//@version=5
indicator('UT Bot + Hull MA Confirmed Signal Delay', overlay=true)
a = input(1, title='UT Bot Key Value (Sensitivity)')
c = input(10, title='UT Bot ATR Period')
useHeikin = input(false, title='Use Heikin Ashi candles')
hullLen = input(55, title='Hull MA Length')
mode = input.string('Hma', title='Hull Type', options=['Hma', 'Thma', 'Ehma'])
srcUT = useHeikin ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) : close
xATR = ta.atr(c)
nLoss = a * xATR
var float xATRTrailingStop = na
xATRTrailingStop := srcUT > nz(xATRTrailingStop[1]) and srcUT[1] > nz(xATRTrailingStop[1]) ? math.max(nz(xATRTrailingStop[1]), srcUT - nLoss) : srcUT < nz(xATRTrailingStop[1]) and srcUT[1] < nz(xATRTrailingStop[1]) ? math.min(nz(xATRTrailingStop[1]), srcUT + nLoss) : srcUT > nz(xATRTrailingStop[1]) ? srcUT - nLoss : srcUT + nLoss
ema1 = ta.ema(srcUT, 1)
utBuy = srcUT > xATRTrailingStop and ta.crossover(ema1, xATRTrailingStop)
utSell = srcUT < xATRTrailingStop and ta.crossover(xATRTrailingStop, ema1)
HMA(src, len) =>
    ta.wma(2 * ta.wma(src, len / 2) - ta.wma(src, len), math.round(math.sqrt(len)))
EHMA(src, len) =>
    ta.ema(2 * ta.ema(src, len / 2) - ta.ema(src, len), math.round(math.sqrt(len)))
THMA(src, len) =>
    ta.wma(ta.wma(src, len / 3) * 3 - ta.wma(src, len / 2) - ta.wma(src, len), len)
HULL = mode == 'Hma' ? HMA(close, hullLen) : mode == 'Ehma' ? EHMA(close, hullLen) : THMA(close, hullLen / 2)
var int signalState = 0
var bool buySignal = false
var bool sellSignal = false
buySignal := utBuy and close > HULL ? true : signalState == 1 and ta.crossover(close, HULL) ? true : false
sellSignal := utSell and close < HULL ? true : signalState == -1 and ta.crossunder(close, HULL) ? true : false
signalState := utBuy and close <= HULL ? 1 : utSell and close >= HULL ? -1 : buySignal or sellSignal ? 0 : signalState
plotshape(buySignal, title='Buy', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), text='Buy')
plotshape(sellSignal, title='Sell', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), text='Sell')
plot(HULL, title='Hull MA', color=color.new(color.orange, 0))
alertcondition(buySignal, title='Buy Alert', message='Confirmed UT Bot Buy (price crossed above HullMA)')
alertcondition(sellSignal, title='Sell Alert', message='Confirmed UT Bot Sell (price crossed below HullMA)')

← 返回列表