你好,感谢你对此进行调查!
我在某些策略中使用标签,以使其更容易获得正确的入场价,退出价和止损价。但是,它们总是显示大量的小数,而我并不需要,这会阻塞图表。有什么办法可以将这些数字四舍五入为2或3个小数。我只遇到过舍入函数,该函数舍入为整数并且不适合该任务。
举个例子:
我得到了我的水平浮动
entry_price = valuewhen(short_entry and strategy.position_size == 0, close, 0)
然后,我使用
label.new(x=bar_index, y=high, text = "Entry = " + tostring(entry_price), color=color.black, textcolor=color.black, style=label.style_arrowdown, yloc = yloc.abovebar)
非常感谢你的输入!
tostring()
有一个可选参数,可让你使用所需的小数位数来格式化字符串。要使用它,请传递一个类似的字符串"#.####"
。比较以下标签的输出:
//@version=4
study("My Script", overlay=true)
a = 0.12345678
l1 = label.new(bar_index, high, tostring(a))
l2 = label.new(bar_index, low, tostring(a, "#.##"), style=label.style_label_up)
非常感谢,这真是一种魅力!当看参考手册时,我完全没有得到它。