【问题标题】:How to get price at location of mouse pointer in Tradingview Pine Script?如何在 Tradingview Pine Script 中获取鼠标指针位置的价格?
【发布时间】:2021-06-04 14:40:42
【问题描述】:

我编写了一个简单的函数来跟踪我的空头头寸的收益或损失。这样我就不必一直重新登录 Kraken 进行检查或在脑海中进行数学运算。

study("Current P/L", overlay=true)

numberOfBitcoinsSold = 49
sellPrice = 37901

plotchar(((sellPrice - close) * numberOfBitcoinsSold), "Bar Index", "", location = location.top) //my gains and losses

这可行,但我也想知道在给定的理论价格下我可能拥有多少。我想将鼠标悬停在给定的价格上并让它计算在该价格下的收益。如何在用户鼠标的 y 坐标处检索价格?当前系统仅适用于已经存在的柱,而不适用于未来的某个特定点。

【问题讨论】:

  • 我们可以从绘图工具箱中手动绘制在图表上的趋势线输入价格吗?如果能做到这一点,工作就会完成。只需绘制一条趋势线,让代码从我们的首选位置(趋势线)获取输入 继续将图表上的趋势线移动到希望价格 :)

标签: pine-script


【解决方案1】:

很遗憾,您无法通过 pine 访问有关鼠标指针位置的任何内容。

您可以使用表格或绘图线和标签来预先计算在给定理论价格下您的 PnL 的百分比区间。

最简单的可能是使用输入变量来接受您想要的价格水平并从中计算您的盈亏。

qty = input(49, title = "Qty")
sellPrice = input(37901, title = "Sell Price")
PnLprice = input(20000, title = "PnL Price")

PnL = (sellPrice - PnLprice) * qty

var PnLline = line.new(x1 = bar_index - 1, y1 = PnLprice, x2 = bar_index, y2 = PnLprice, color = color.red, style = line.style_dashed, width = 2, extend = extend.left)
line.set_x1(PnLline, x = bar_index - 1)
line.set_x2(PnLline, x = bar_index)

var PnLlabel = label.new(x = bar_index, y = PnLprice, style = label.style_label_left, color = color.red, textcolor = color.white, text = "Short PnL : " + tostring(PnL), size = size.normal)
label.set_x(PnLlabel, x = bar_index)

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2021-09-22
    • 2022-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    相关资源
    最近更新 更多