如何在交易视图上制作计算器和重复功能?

问题描述 投票:0回答:1

我想在 Trading View 的图表上创建一个计算器。

点击图表上的 3 个价格(柱上的最高价或最低价)并使用这 3 个价格进行计算。我还想将其结果绘制在图表上。

之后,我想重置并重复功能以通过单击接受新输入。

我想制作函数,如下所示:

my image and process

  1. 单击图表上的栏
  2. 在我点击的点上创建新标签
  3. 计算结果并将结果绘制在图表上
  4. 重置和重复功能(保留过去的结果)

看似简单,但我承认有几个问题:

  1. 如何同时获取价格和时间?我希望只需点击一下即可获得价格和时间。 (换句话说,一次获取X轴和Y轴值。)

  2. 如何重复这个功能?我不知道如何重复功能。 有一种方法但不是聪明的想法(删除指标并重新添加)。 我知道这不是指标的普通用法,但计算器需要重置按钮,按下重置按钮并再次运行,并将过去的结果绘制在图表上。

//@version=5
indicator("ABC_caluculator", overlay=true)

Price_A = input.price(defval=0, title = "A", group="ABC_caluculator",  confirm=true)
Price_B = input.price(defval=0, title = "B", group="ABC_caluculator",  confirm=true)
Price_C = input.price(defval=0, title = "C", group="ABC_caluculator",  confirm=true) 

Price_N = Price_C + (Price_B - Price_A)
Price_V = Price_B + (Price_B - Price_C)
Price_E = Price_B + (Price_B - Price_A) 
Price_NT= Price_C + (Price_C - Price_A)


//Table

//Format
tblPos = input.string(title="Position on Chart", defval="Bottom Right", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right", "Middle Left", "Middle Right", "Middle Bottom" ], group = "Table Customization")
tblposition = tblPos == "Top Left" ? position.top_left : tblPos == "Top Right" ? position.top_right : tblPos == "Bottom Left" ? position.bottom_left : tblPos == "Bottom Right" ? position.bottom_right : tblPos == "Middle Left" ? position.middle_left : tblPos == "Middle Right" ? position.middle_right : position.bottom_center
text_halign = input.string(defval = "Center", title="Horizontal Alignment", options=["Left", "Center", "Right"], group = "Table Customization")
text_halign_pos = text_halign == "Left" ? text.align_left : text_halign == "Center" ? text.align_center : text.align_right
text_valign = input.string(defval = "Center", title="Vertical Alignment", options=["Top", "Center", "Bottom"], group = "Table Customization")
text_valign_pos = text_valign == "Top" ? text.align_top : text_valign == "Center" ? text.align_center : text.align_bottom
text_size = input.string(defval = "Auto", title="Text Size", options=["Auto", "Tiny", "Small", "Normal", "Large", "Huge"], group = "Table Customization")
text_size_op = text_size == "Auto" ? size.auto : text_size == "Tiny" ? size.tiny : text_size == "Small" ? size.small : text_size == "Normal" ? size.normal : text_size == "Large" ? size.large : size.huge


//Dimensions
border_width = input.int(defval=1, title="Border Width", group = "Dimensions")
frame_width = input.int(defval=5, title="Frame Width", group = "Dimensions")
table_width = input.int(defval=5, title="Cell Width", group = "Dimensions")
table_height = input.int(defval=5, title="Cell Height", group = "Dimensions")

//Colors
tblBorderColor = input.color(title="Border Color", defval=#636363, group = "Table Styles")
celllBgColor = input.color(title="Background Color", defval=#d1d1d1, group = "Table Styles")
cellTextColor = input.color(title="Text Color", defval=#000000, group = "Table Styles")

resultsTable = table.new(position = tblposition, columns = 6, rows = 6, bgcolor = #ffffff, border_width = border_width,frame_color = tblBorderColor, frame_width = frame_width)
//A,B,C
table.cell(resultsTable, column=0, row=0, text= "A", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=1, row=0, text= str.tostring(Price_A), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=0, row=1, text= "B", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=1, row=1, text= str.tostring(Price_B), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=0, row=2, text= "C", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=1, row=2, text= str.tostring(Price_C), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)

//N,V,E,NT
table.cell(resultsTable, column=2, row=0, text= "N値", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=3, row=0, text= str.tostring(Price_N), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=2, row=1, text= "V値", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=3, row=1, text= str.tostring(Price_V), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=2, row=2, text= "E値", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=3, row=2, text= str.tostring(Price_E), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=2, row=3, text= "NT値", width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
table.cell(resultsTable, column=3, row=3, text= str.tostring(Price_NT), width = table_width, height = table_height, text_size = text_size_op, text_color=cellTextColor, text_halign=text_halign_pos, text_valign=text_valign_pos, bgcolor=celllBgColor)
pine-script calculator pine-script-v5 tradingview-api
1个回答
0
投票

您无法使用 pinescript 单击图表。

© www.soinside.com 2019 - 2024. All rights reserved.