0

Excuse me! I'm a beginner programmer from Japan. I'm not a native English user, so I'll show you my broken English!

[Pine-script on Trading View]

Now, I want to create a calculator works on the Trading View's charts.

By clicking 3 prices(high or low price on bars) on the chart, and calculate it by using 3 prices.

Plot it's result on the chart.

After that, reset and repeat function for accepting new inputs by clicking.

[I want to make functions, like below ↓]

my image and process

  1. click bar on the chart
  2. create new labels on the point I clicked
  3. calculate and plot results on the chart
  4. reset and repeat function(keep plotted past results)

It seems simple, but I confess several problems.


[problems]

1.How to get Price & Time at the same time.

→ I want only one click can get Price and Time. (In other words, get X-axis and Y-axis value at once.) But, is there any way?

2. How to repeat this function?

→ I have no good idea how to repeat function. There is a way but not smart idea (delete the indicator and add it again). I know it is not ordinary usage for a indicator, but calculator needs reset button, push it reset and function again with leaving plotted past results on the chart.


//@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)

1 Answers1

0

You can't work with click on the chart with pinescript.

G.Lebret
  • 2,826
  • 2
  • 16
  • 27