pine-script - 如何在 Pine Script 中设置标签位置?
问题描述
我正在寻找一些帮助来为我的标签设置位置。如果可能的话,我想把它们放在图表的左上角。
否则最坏的情况将是有一个未来的抵消。我不知道从哪里开始,非常感谢任何帮助。
谢谢
//@version=4
study("Order Flow Share Size Calculator", overlay=true)
//------------------------------------------------------------------------------
// Inputs
risk = input(100.00, "Risk Amount (USD)", type=input.float)
Show_Label_Long = input(true, title="Long Position")
Show_Label_Short = input(true, title="Short Position")
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Variables and Calculations Long
EntryL = high + 0.01
StopL = low - 0.01
StoplossL = EntryL - StopL
SharesL = round(risk/StoplossL)
// Long Label
LongLabel = "Shares = " + tostring(SharesL) + "\n" + "\nEntry = $" + tostring(round(EntryL * 100)/100) + "\n" + "\nStop = $" +tostring(round(StopL * 100)/100)
// Variables and Calacutations Short
EntryS = low - 0.01
StopS = high + 0.01
StoplossS = StopS - EntryS
SharesS = round(risk/StoplossS)
// Short Lables
ShortLabel = "Shares = " + tostring(SharesS) +"\n" + "\nEntry = $" + tostring(round(EntryS * 100)/100) + "\n" + "\nStop = $" +tostring(round(StopS *100)/100)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Create Label Long
if Show_Label_Long
LL = label.new (x=bar_index, y=na, text=LongLabel, xloc=xloc.bar_index, yloc=yloc.belowbar, color=color.green, style=label.style_none, textcolor=color.green, size=size.normal, textalign=text.align_center)
label.delete(LL[1])
// Create Label Short
if Show_Label_Short
SL = label.new (x=bar_index, y=na, text=ShortLabel, xloc=xloc.bar_index, yloc=yloc.abovebar, color=color.red, style=label.style_none, textcolor=color.red, size=size.normal, textalign=text.align_center)
label.delete(SL[1])
//------------------------------------------------------------------------------
解决方案
不幸的是,现在松树中的标签没有绝对位置。但是你可以尝试这样的事情来抵消你的标签:
//@version=4
study("Label in future", overlay=true)
count = input(1)
// we use minimal time of bars as an offset in future
var float minBarTime = 999999999999
var label l = label.new(bar_index, close, "Text", xloc=xloc.bar_time)
currentTime = time(timeframe.period)
timeOfCurrentBar = change(currentTime, 1)
minBarTime := not na(minBarTime) ? min(timeOfCurrentBar, minBarTime) : timeOfCurrentBar
// add to current time calculated time of bar
label.set_x(l, int(currentTime+(count*minBarTime)))
label.set_y(l, hl2)
推荐阅读
- typescript - typescript:具有通用函数集合的通用接口:参数 XXX 和“args”的类型不兼容
- javascript - 递归函数不返回
- c# - AutoFac - 通过继承对象的枚举创建工厂
- node.js - ReferenceError: indexproduct 未定义
- c++ - 如何从同一输入行获得不同的用户输入?
- swift - 变量 UILabel 名称
- virtualbox - VirtualBox VM 导入 Oracle 云基础设施后更改 MAC 地址
- c++ - 2D 阵列不正确的值问题(粒子光子)
- android - android离线时如何调用API?
- python - 按钮释放时的 Kivy 功能范围(小部件树)