1

I cannot find a way in which the command tickerid works for me.. I want to make an IF statment where

If (the current ticker i'm on = a specific ticker i've put) then (execute a formula) else (do nothing)

So i want my indicator to work in different parameters depending on the assets.

Can someone help me what command i should use ?

2 Answers 2

4

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)
1
  • Added Edit 1 to my answer. Commented Mar 17, 2021 at 14:52
-1
"ticker_id": "DXB_KLV",
    "base_currency": "DXB",
    "target_currency": "KLV",
    "last_price": "6.699087",
    "base_volume": "109045.96631366048",
    "target_volume": "730508.4153342808",
    "oferta": "6.699087",
    "preguntar": "5.585349",
    "alto": "6.699087",
    "bajo": "5.585349"
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Apr 16 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.