Reputation: 11
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 ?
Upvotes: 1
Views: 1213
Reputation: 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"
Upvotes: -1
Reputation: 6865
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)
Upvotes: 4