本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Trade Visualizer", overlay=true, max_lines_count=2)
// DISTANCE SETTINGS
distance = input.float(40.0, "Distance", minval=0.01, group="Distance")
unit = input.string("Ticks", "Measurement", options=["Ticks", "Points", "Pips", "Dollars (Price)", "Cents (Price)", "Dollars (Per Contract)"], group="Distance")
// LINE APPEARANCE
lineColor = input.color(color.rgb(222, 184, 135), "Line Color", group="Lines")
styleOption = input.string("Dotted", "Line Style", options=["Solid", "Dashed", "Dotted"], group="Lines")
lineThickness = input.int(1, "Line Thickness", minval=1, maxval=5, group="Lines")
selectedStyle = switch styleOption
"Solid" => line.style_solid
"Dashed" => line.style_dashed
=> line.style_dotted
// CONVERT CHOSEN UNIT TO PRICE DISTANCE
pipSize = syminfo.currency == "JPY" ? 0.01 : 0.0001
rawOffset = switch unit
"Ticks" => distance * syminfo.mintick
"Points" => distance
"Pips" => distance * pipSize
"Dollars (Price)" => distance
"Cents (Price)" => distance / 100.0
"Dollars (Per Contract)" => distance / syminfo.pointvalue
// ROUND DISTANCE TO THE NEAREST TICK; MINIMUM ONE TICK
offsetTicks = math.max(1.0, math.round(rawOffset / syminfo.mintick))
offset = offsetTicks * syminfo.mintick
// USE REAL MARKET PRICES EVEN WHEN VIEWING HEIKIN ASHI CANDLES
standardSymbol = ticker.standard(syminfo.tickerid)
livePrice = request.security(standardSymbol, timeframe.period, close)
upperPrice = math.round_to_mintick(livePrice + offset)
lowerPrice = math.round_to_mintick(livePrice - offset)
// MAINTAIN EXACTLY TWO LINES; UPDATE WITH EACH REALTIME PRICE CHANGE
var line upperLine = na
var line lowerLine = na
if barstate.islast
if na(upperLine)
upperLine := line.new(bar_index - 1, upperPrice, bar_index, upperPrice, extend=extend.both, color=lineColor, style=selectedStyle, width=lineThickness)
lowerLine := line.new(bar_index - 1, lowerPrice, bar_index, lowerPrice, extend=extend.both, color=lineColor, style=selectedStyle, width=lineThickness)
else
line.set_xy1(upperLine, bar_index - 1, upperPrice)
line.set_xy2(upperLine, bar_index, upperPrice)
line.set_xy1(lowerLine, bar_index - 1, lowerPrice)
line.set_xy2(lowerLine, bar_index, lowerPrice)
line.set_color(upperLine, lineColor)
line.set_color(lowerLine, lineColor)
line.set_style(upperLine, selectedStyle)
line.set_style(lowerLine, selectedStyle)
line.set_width(upperLine, lineThickness)
line.set_width(lowerLine, lineThickness)