本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("UT Bot PRO + HTF + Pivots + PP SuperTrend (Non-Repainting)",
overlay=true, max_labels_count=500, max_lines_count=500)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Visibility
showUT = input.bool(true, "Show UT Bot")
showVWAP = input.bool(true, "Show HA VWAP")
showPivots = input.bool(true, "Show Standard Pivots")
showPPST = input.bool(true, "Show Pivot SuperTrend")
showSLTP = input.bool(true, "Show SL / TP")
// UT Bot
sens = input.float(1.2, "UT Sensitivity", step=0.1)
atrLen = input.int(10, "UT ATR Length")
// HTF Filter
htfTF = input.timeframe("15", "HTF Timeframe")
htfLen = input.int(200, "HTF EMA Length")
// Volume Filter
volLen = input.int(20, "Volume MA Length")
// PP SuperTrend
prd = input.int(2, "Pivot Period")
factor = input.float(3.0, "ATR Factor")
pd = input.int(10, "ATR Period")
// Risk Management
slATR = input.float(1.5, "SL ATR Multiplier")
tpATR = input.float(3.0, "TP ATR Multiplier")
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HEIKIN ASHI DATA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = request.security(haTicker, timeframe.period, close)
haHigh = request.security(haTicker, timeframe.period, high)
haLow = request.security(haTicker, timeframe.period, low)
haHlc3 = (haHigh + haLow + haClose) / 3
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// UT BOT (NON-REPAINT)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
nLoss = sens * atr
src = haClose
var float trailStop = na
trailStop := na(trailStop[1]) ? src - nLoss :
src > trailStop[1] and src[1] > trailStop[1] ? math.max(trailStop[1], src - nLoss) :
src < trailStop[1] and src[1] < trailStop[1] ? math.min(trailStop[1], src + nLoss) :
src > trailStop[1] ? src - nLoss : src + nLoss
buyUT = ta.crossover(src, trailStop)
sellUT = ta.crossunder(src, trailStop)
plot(showUT ? trailStop : na, "UT Stop", color=color.orange, linewidth=2)
plot(showVWAP ? ta.vwap(haHlc3) : na, "HA VWAP", color=color.blue)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// HTF TREND FILTER (NO LOOKAHEAD)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
htfClose = request.security(syminfo.tickerid, htfTF, close,
barmerge.gaps_off, barmerge.lookahead_off)
htfEMA = ta.ema(htfClose, htfLen)
htfBull = htfClose > htfEMA
htfBear = htfClose < htfEMA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME FILTER
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
volOK = volume > ta.sma(volume, volLen)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// STANDARD PIVOTS (AUTO TF)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pivotTF = timeframe.isintraday ? "D" : timeframe.isdaily ? "W" : "M"
ph = request.security(syminfo.tickerid, pivotTF, high[1])
pl = request.security(syminfo.tickerid, pivotTF, low[1])
pc = request.security(syminfo.tickerid, pivotTF, close[1])
pp = (ph + pl + pc) / 3
r1 = 2 * pp - pl
s1 = 2 * pp - ph
r2 = pp + (ph - pl)
s2 = pp - (ph - pl)
plot(showPivots ? pp : na, "PP", color=color.white, linewidth=2)
plot(showPivots ? r1 : na, "R1", color=color.red)
plot(showPivots ? s1 : na, "S1", color=color.lime)
plot(showPivots ? r2 : na, "R2", color=color.red)
plot(showPivots ? s2 : na, "S2", color=color.lime)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PIVOT POINT SUPERTREND (CONFIRMED)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ph2 = ta.pivothigh(prd, prd)
pl2 = ta.pivotlow(prd, prd)
var float center = na
lastpp = not na(ph2) ? ph2 : not na(pl2) ? pl2 : na
center := na(lastpp) ? center : na(center) ? lastpp : (center * 2 + lastpp) / 3
Up = center - factor * ta.atr(pd)
Dn = center + factor * ta.atr(pd)
var float TUp = na
var float TDown = na
TUp := close[1] > nz(TUp[1]) ? math.max(Up, nz(TUp[1])) : Up
TDown := close[1] < nz(TDown[1]) ? math.min(Dn, nz(TDown[1])) : Dn
var int Trend = 1
Trend := close > nz(TDown[1]) ? 1 :
close < nz(TUp[1]) ? -1 : nz(Trend[1], 1)
ppst = Trend == 1 ? TUp : TDown
plot(showPPST ? ppst : na, "PP SuperTrend",
color=Trend == 1 ? color.lime : color.red, linewidth=2)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FINAL NON-REPAINT ENTRY CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buySignal =
barstate.isconfirmed and
buyUT and
Trend == 1 and
haClose > ta.vwap(haHlc3) and
htfBull and
volOK
sellSignal =
barstate.isconfirmed and
sellUT and
Trend == -1 and
haClose < ta.vwap(haHlc3) and
htfBear and
volOK
plotshape(buySignal, "BUY", shape.labelup, color=color.lime, textcolor=color.black)
plotshape(sellSignal, "SELL", shape.labeldown, color=color.red, textcolor=color.white)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ATR SL / TP
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atrVal = ta.atr(14)
longSL = close - atrVal * slATR
longTP = close + atrVal * tpATR
shortSL = close + atrVal * slATR
shortTP = close - atrVal * tpATR
plot(showSLTP and buySignal ? longSL : na, "Long SL", color=color.red, style=plot.style_linebr)
plot(showSLTP and buySignal ? longTP : na, "Long TP", color=color.green, style=plot.style_linebr)
plot(showSLTP and sellSignal ? shortSL : na, "Short SL", color=color.red, style=plot.style_linebr)
plot(showSLTP and sellSignal ? shortTP : na, "Short TP", color=color.green, style=plot.style_linebr)