0

I am looking to have a reference table of sorts for my tradingview set up. My aim is to compare 5 stock tickers, namely apple(AAPL), microsoft(MSFT), Amazon(AMZN), Google(GOOGL) and Tesla(TSLA). The data is current price, price change(from yesterday's) and percentage change.

Here is the screengrab of the table https://prnt.sc/XzaN3fJjwuZz

What I am doing to do next is to color the cells based on the positive or negative changes. So if a change has been positive, the cell background becomes green, if negative, then red.

I tried using conditional logic but I am getting error: An argument of 'series color' type was used but a 'series int' is expected I searched and could find only two questions in stackoverflow on this topic:

  1. pine script error- An argument of 'series string' type was used but a 'const string' is expected
  2. Converting series integer to integer in pinescript

However, I was not able to understand as to how to relate their answers to my case.

Here is the code snippet I am using to calculate the values:

pr_x2 = request.security(x1,"D", close[1])
pr_x1 = request.security(x1,"", close)
pr_diff = (pr_x1 - pr_x2)
pr_pct = truncate(((pr_diff1/pr_x2)*100),2)

where pr_x2 -> previous day close pr-x1 -> current value

I'm trying to use this condition for background in the cell:

table.cell(panel, 0, 1, str.tostring(pr_diff) + "\nChg: " + str.tostring(pr_pct1) + " %", bgcolor = (pr_diff>0)?color.green:color.red, text_color=color.white)

but then I get the error I have mentioned above.

I read in the discussions forum that converting series integer to integer in pinescript cannot be done. Is there a workaround for my case?

To admin: My apologies if it is similar to a previous thread, but I was not able to find it. It would be very kind of you to point me in the right direction.

Neville N
  • 31
  • 1
  • 4

1 Answers1

0

You are trying on the cell, try applying on the array.

var = array.get(id) conditions ? Color.green : 
      array.get(id) conditions? Color.red
Jonathan Ciapetti
  • 1,261
  • 3
  • 11
  • 16
Noah
  • 1
  • 1