Skip to main content
Added Edit 1 section.
Source Link
Bjorn Mistiaen
  • 6.8k
  • 3
  • 23
  • 47

An example.
This will change the background color, depending on the ticker you select.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true)

var color   myColor = na

if barstate.isfirst
    if syminfo.ticker == "AAPL"
        myColor := color.red
    else if syminfo.ticker == "MSFT"
        myColor := color.green
    else if syminfo.ticker == "TSLA"
        myColor := color.blue
    else
        myColor := na

bgcolor(myColor)

Edit 1 in response to this comment.
When you declare a variable, and initialize it with na, you need to specify the type of the variable.
Also, in your case, syminfo.tickerid must be used instead of syminfo.ticker, because I see that you use the format EXCHANGE:SYMBOL.
The code below will work.
Please remember to add the //@version=4 tag in the beginning of your script.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true, scale=scale.left)

var int Periods = input(20, "Periods")

var color   myColor = na
var float   ATR     = na 

if syminfo.tickerid == "CAPITALCOM:US100"
    ATR := atr(Periods) * 1.9
    myColor := color.green
else 
    ATR := atr(Periods) 
    myColor := color.red

plot(ATR)
bgcolor(myColor)

An example.
This will change the background color, depending on the ticker you select.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true)

var color   myColor = na

if barstate.isfirst
    if syminfo.ticker == "AAPL"
        myColor := color.red
    else if syminfo.ticker == "MSFT"
        myColor := color.green
    else if syminfo.ticker == "TSLA"
        myColor := color.blue
    else
        myColor := na

bgcolor(myColor)

An example.
This will change the background color, depending on the ticker you select.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true)

var color   myColor = na

if barstate.isfirst
    if syminfo.ticker == "AAPL"
        myColor := color.red
    else if syminfo.ticker == "MSFT"
        myColor := color.green
    else if syminfo.ticker == "TSLA"
        myColor := color.blue
    else
        myColor := na

bgcolor(myColor)

Edit 1 in response to this comment.
When you declare a variable, and initialize it with na, you need to specify the type of the variable.
Also, in your case, syminfo.tickerid must be used instead of syminfo.ticker, because I see that you use the format EXCHANGE:SYMBOL.
The code below will work.
Please remember to add the //@version=4 tag in the beginning of your script.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true, scale=scale.left)

var int Periods = input(20, "Periods")

var color   myColor = na
var float   ATR     = na 

if syminfo.tickerid == "CAPITALCOM:US100"
    ATR := atr(Periods) * 1.9
    myColor := color.green
else 
    ATR := atr(Periods) 
    myColor := color.red

plot(ATR)
bgcolor(myColor)
Source Link
Bjorn Mistiaen
  • 6.8k
  • 3
  • 23
  • 47

An example.
This will change the background color, depending on the ticker you select.

//@version=4
study(title="TickerId", shorttitle="TCK", overlay=true)

var color   myColor = na

if barstate.isfirst
    if syminfo.ticker == "AAPL"
        myColor := color.red
    else if syminfo.ticker == "MSFT"
        myColor := color.green
    else if syminfo.ticker == "TSLA"
        myColor := color.blue
    else
        myColor := na

bgcolor(myColor)