Pine Script 在图表的右上角写入 ATR 信息
Pine Script write ATR information on the right top of the chart
我不知道 Pine Script,我有一个问题要问你。
您认为是否可以在图表的右上方写一些信息?
在细节上,我需要写 ATR Daily,以及 30% 的 ATR Daily。如果我更改图形上的时间范围,我也需要 previuos 关闭的 AtrDaily。
你能帮帮我吗?
提前致谢
您可以使用 table.new
功能在 table 和 request.security()
函数的右上角显示信息,以请求来自不同时间范围的数据(在您的示例中为每天)。
下面的代码将在图表的右上角打印每日 ATR 和 30% 的每日 ATR。
//@version=5
indicator("My Script", overlay=true)
atr_daily = request.security(syminfo.tickerid, "D", ta.atr(14))
atr_daily_30 = atr_daily * 30 / 100
var testTable = table.new(position = position.top_right, columns = 1, rows = 2, bgcolor = color.yellow, border_width = 1)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = "ATR Daily: " + str.tostring(atr_daily))
table.cell(table_id = testTable, column = 0, row = 1, text = "ATR Daily (30%): " + str.tostring(atr_daily_30), bgcolor=color.teal)
我不知道 Pine Script,我有一个问题要问你。 您认为是否可以在图表的右上方写一些信息? 在细节上,我需要写 ATR Daily,以及 30% 的 ATR Daily。如果我更改图形上的时间范围,我也需要 previuos 关闭的 AtrDaily。 你能帮帮我吗?
提前致谢
您可以使用 table.new
功能在 table 和 request.security()
函数的右上角显示信息,以请求来自不同时间范围的数据(在您的示例中为每天)。
下面的代码将在图表的右上角打印每日 ATR 和 30% 的每日 ATR。
//@version=5
indicator("My Script", overlay=true)
atr_daily = request.security(syminfo.tickerid, "D", ta.atr(14))
atr_daily_30 = atr_daily * 30 / 100
var testTable = table.new(position = position.top_right, columns = 1, rows = 2, bgcolor = color.yellow, border_width = 1)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = "ATR Daily: " + str.tostring(atr_daily))
table.cell(table_id = testTable, column = 0, row = 1, text = "ATR Daily (30%): " + str.tostring(atr_daily_30), bgcolor=color.teal)