-3

How do I code the following for Trading View?

if a bars high - low is greater than 0.05 but less than 0.13 then plot the number 5

if a bars high - low is greater than 0.14 but less than 0.16 then plot the number 4

if a bars high - low is greater than 0.17 but less than 0.22 then plot the number 3

if a bars high - low is greater than 0.23 but less than 0.33 then plot the number 2

if a bars high - low is greater than 0.34 but less than 0.66 then plot the number 1

halfer
  • 19,824
  • 17
  • 99
  • 186
RNB
  • 29
  • 4
  • 1
    Poor title. Rewrite to summarize your specific technical issue. – Basil Bourque Nov 04 '22 at 23:44
  • 1
    I’m voting to close this question because ["Can Someone Help Me?" is not an actual question](https://meta.stackoverflow.com/a/284237/162698) – Rob Nov 05 '22 at 00:47
  • 1
    @rob: you can probably use Needs Focus as a standardised equivalent for that close reason (i.e. the question author needs to be more specific about where they are stuck). – halfer Nov 10 '22 at 23:04

1 Answers1

-1

You can use labels to display your numbers because they will be dynamic.

//@version=5
indicator("My script", overlay=true, max_labels_count=500)

diff = high - low

string c = na

if (diff > 0.34) and (diff < 0.66)
    c := "1"
else if (diff > 0.23) and (diff < 0.33)
    c := "2"
else if (diff > 0.17) and (diff < 0.22)
    c := "3"
else if (diff > 0.14) and (diff < 0.16)
    c := "4"
else if (diff > 0.05) and (diff < 0.13)
    c := "5"

if (not na(c))
    label.new(bar_index, high, c, yloc=yloc.abovebar, style=label.style_none)
vitruvius
  • 15,740
  • 3
  • 16
  • 26