Trying to display a ratings system in a Tradingview table.
Basically, we have 2 parameters, say, “A" & “B”.
A can have ratings from 0 to 4 (i.e. any one of 0,1,2,3,4).
Similarly, B can have ratings from 0 to 4 (i.e. any one of 0,1,2,3,4).
//Example of A Ratings
AFour = (A>EMA5 and EMA5>EMA13)
AThree = (A>EMA5 and EMA5<EMA13)
ATwo = (A<EMA5 and EMA5>EMA13)
AOne = (A<EMA5 and EMA5<EMA13)
//Example of B Ratings
BFour = (B>EMA5 and EMA5>EMA13)
BThree = (B>EMA5 and EMA5<EMA13)
BTwo = (B<EMA5 and EMA5>EMA13)
BOne = (B<EMA5 and EMA5<EMA13)
I wish to translate these text values to numbers e.g. AFour translates to the number 4.
And then, add the A & B ratings, & display them as a final number. e.g. If the rating is AThree & BTwo, the final rating displays as 5.
Progess so far is that I’ve only been able to display the A & B ratings in a table.
if(AFour == true)
table.cell(table_id = indicatorTable, column = 2, row = 1, text = "4", bgcolor = color.blue, text_color = color.white)
if(AFour == false)
if(AThree == true)
table.cell(table_id = indicatorTable, column = 2, row = 1, text = "3", bgcolor = color.green, text_color = color.white)
if(AThree == false)
if(ATwo == true)
table.cell(table_id = indicatorTable, column = 2, row = 1, text = "2", bgcolor = color.orange, text_color = color.black)
if(ATwo == false)
if(AOne == true)
table.cell(table_id = indicatorTable, column = 2, row = 1, text = "1", bgcolor = color.red, text_color = color.black)
if(AOne == false)
table.cell(table_id = indicatorTable, column = 2, row = 1, text = "0", bgcolor = #F7E98E, text_color = color.black)
But I am unable to add the ratings & display their sum total.
Something you could try for example
AFour = (A>EMA5 and EMA5>EMA13) ? 1 : 0
AThree = (A>EMA5 and EMA5<EMA13) ? 1 : 0
ATwo = (A<EMA5 and EMA5>EMA13) ? 1 : 0
AOne = (A<EMA5 and EMA5<EMA13) ? 1 : 0
Atotal = AFour + AThree + ATwo + AOne
if Atotal == 0
// do something
else if Atotal == 1
// do something
...
else if Atotal == 4
// do something
Do the same for the Bs and you'll have your As and Bs rating