繁体   English   中英

在交易视图中获取当前收盘价和最后收盘价之间的百分比差异

[英]Get percentage difference between current bar close and last bar close price in tradingview

我想使用 pine-script 找出鼠标选择的柱的收盘价与 TradingView 图表上最后一个柱的收盘价之间的百分比差异。

我正在使用松脚本 v5。

这可以通过使用交互式输入来完成。
有关详细信息,请参阅Pine 脚本现在是交互式的。

下面的示例可以满足您的要求。

//@version=5
indicator('Bar Selection', overlay=true)

myTime = input.time(0,'Start Bar', confirm=true)

var float selected_close = na
var float pct_diff = na
var label myLabel = label.new(na, na, '', style=label.style_label_left)

if time == myTime
    selected_close := close

bgcolor(time == myTime ? color.yellow : na)

if barstate.islast
    pct_diff := (close / selected_close - 1) * 100
    label.set_xy(myLabel, bar_index + 1, close)
    label.set_text(myLabel, str.tostring(pct_diff, format.percent))

plotchar(pct_diff, 'pct_diff', '', location.top)
plotchar(selected_close, 'selected_close', '', location.top)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM