本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Uptrick UVES Pro v6 - Buy/Sell Volume", shorttitle="UVES Pro v6", overlay=true)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupTrend = "Trend Settings"
len = input.int(20, "EMA Length", minval=1, group=groupTrend)
src = input.source(close, "Source", group=groupTrend)
showEMA = input.bool(true, "Show EMA", group=groupTrend)
showSignal = input.bool(true, "Show Signal Line", group=groupTrend)
emaWidth = input.int(3, "EMA Width", minval=1, maxval=5, group=groupTrend)
groupSmooth = "Signal Smoothing"
method = input.string("EMA", "Method", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=groupSmooth)
smoothLen = input.int(5, "Smoothing Length", minval=1, maxval=100, group=groupSmooth)
signalWidth = input.int(2, "Signal Width", minval=1, maxval=5, group=groupSmooth)
groupVol = "Volume Table"
showTable = input.bool(true, "Show Volume Table", group=groupVol)
tablePositionInput = input.string("top_right", "Table Position", options=["top_right", "top_left", "middle_right", "middle_left", "bottom_right", "bottom_left"], group=groupVol)
tableTextSizeInput = input.string("normal", "Text Size", options=["tiny", "small", "normal", "large", "huge"], group=groupVol)
tableBG = input.color(color.new(color.black, 15), "Table Background", group=groupVol)
buyColor = input.color(color.lime, "Buy Color", group=groupVol)
sellColor = input.color(color.red, "Sell Color", group=groupVol)
ratioColor = input.color(color.aqua, "Buy/Sell Ratio Color", group=groupVol)
groupSignals = "Signal Settings"
showLabels = input.bool(true, "Show Buy/Sell Signals", group=groupSignals)
confirmedOnly = input.bool(true, "Signals on Closed Bars Only", group=groupSignals)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. MOVING AVERAGES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ema = ta.ema(src, len)
ma(float source, int length, string selectedMethod) =>
switch selectedMethod
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
signalLine = ma(ema, smoothLen, method)
emaUp = ema > ema[1]
signalUp = signalLine > signalLine[1]
emaColor = emaUp ? color.lime : color.red
signalColor = signalUp ? color.lime : color.red
plot(showEMA ? ema : na, title="EMA", color=emaColor, linewidth=emaWidth)
plot(showSignal ? signalLine : na, title="Signal Line", color=signalColor, linewidth=signalWidth)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. TREND SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
turnUp = signalUp and not signalUp[1]
turnDown = not signalUp and signalUp[1]
buySignal = turnUp and (not confirmedOnly or barstate.isconfirmed)
sellSignal = turnDown and (not confirmedOnly or barstate.isconfirmed)
plotshape(showLabels and buySignal, title="Uptrend", text="Uptrend", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.small)
plotshape(showLabels and sellSignal, title="Downtrend", text="Downtrend", style=shape.labeldown, location=location.abovebar, color=color.maroon, textcolor=color.white, size=size.small)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. ESTIMATED BUY / SELL VOLUME
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
barVolume = nz(volume, 0.0)
barRange = high - low
buyVol = barRange > 0 ? barVolume * math.max(0.0, math.min(1.0, (close - low) / barRange)) : barVolume / 2.0
sellVol = math.max(0.0, barVolume - buyVol)
totalVol = buyVol + sellVol
buyPct = totalVol > 0 ? buyVol / totalVol : na
sellPct = totalVol > 0 ? sellVol / totalVol : na
buySellPct = sellVol > 0 ? buyVol / sellVol : na
buyPctText = na(buyPct) ? "N/A" : str.tostring(buyPct * 100, "0.00") + "%"
sellPctText = na(sellPct) ? "N/A" : str.tostring(sellPct * 100, "0.00") + "%"
ratioText = totalVol <= 0 ? "N/A" : sellVol <= 0 ? "∞ (Sell = 0)" : str.tostring(buySellPct * 100, "0.00") + "%"
buyVolText = str.tostring(buyVol, format.volume)
sellVolText = str.tostring(sellVol, format.volume)
totalVolText = str.tostring(totalVol, format.volume)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. TABLE OPTIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
tablePosition = switch tablePositionInput
"top_left" => position.top_left
"middle_right" => position.middle_right
"middle_left" => position.middle_left
"bottom_right" => position.bottom_right
"bottom_left" => position.bottom_left
=> position.top_right
tableTextSize = switch tableTextSizeInput
"tiny" => size.tiny
"small" => size.small
"large" => size.large
"huge" => size.huge
=> size.normal
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. VOLUME ANALYSIS TABLE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table volTable = table.new(tablePosition, 2, 6, bgcolor=tableBG, border_color=color.gray, border_width=1, frame_color=color.gray, frame_width=1)
if barstate.islast
if showTable
table.cell(volTable, 0, 0, "VOLUME ANALYSIS", text_color=color.white, bgcolor=color.new(color.blue, 35), text_size=tableTextSize)
table.cell(volTable, 1, 0, "CURRENT BAR", text_color=color.white, bgcolor=color.new(color.blue, 35), text_size=tableTextSize)
table.cell(volTable, 0, 1, "Estimated Buy Volume", text_color=buyColor, text_size=tableTextSize)
table.cell(volTable, 1, 1, buyVolText, text_color=buyColor, text_size=tableTextSize)
table.cell(volTable, 0, 2, "Estimated Sell Volume", text_color=sellColor, text_size=tableTextSize)
table.cell(volTable, 1, 2, sellVolText, text_color=sellColor, text_size=tableTextSize)
table.cell(volTable, 0, 3, "Buy % of Total", text_color=buyColor, text_size=tableTextSize)
table.cell(volTable, 1, 3, buyPctText, text_color=buyColor, text_size=tableTextSize)
table.cell(volTable, 0, 4, "Sell % of Total", text_color=sellColor, text_size=tableTextSize)
table.cell(volTable, 1, 4, sellPctText, text_color=sellColor, text_size=tableTextSize)
table.cell(volTable, 0, 5, "BUY / SELL RATIO", text_color=ratioColor, text_size=tableTextSize)
table.cell(volTable, 1, 5, ratioText, text_color=ratioColor, bgcolor=color.new(color.blue, 75), text_size=tableTextSize)
else
table.clear(volTable, 0, 0, 1, 5)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="UVES Pro - Uptrend", message="UVES Pro: Signal-line slope turned upward.")
alertcondition(sellSignal, title="UVES Pro - Downtrend", message="UVES Pro: Signal-line slope turned downward.")
alertcondition(emaUp and barstate.isconfirmed, title="UVES Pro - EMA Rising", message="UVES Pro: EMA is rising.")
alertcondition(not emaUp and barstate.isconfirmed, title="UVES Pro - EMA Falling", message="UVES Pro: EMA is falling.")