简体   繁体   中英

Pinescript: Referencing another security in an indicator

I'm attempting to make an indicator that references a moving average of a different security.

For example: Change the color of candles on "ETHUSD" chart if "BTCUSD" price is above the 200 day weekly moving average.

I haven't found a way to reference the data of a moving average on a different security or symbol. I'm not sure if this is even possible within Pinescript of Tradingview.

Any help would be greatly appreciated. Thanks for your time!

Sure it's possible. Use something like:

//@version=4
study("", "", true)
priceIsAboveMa = close > sma(close, 200)
btcPriceIsAboveMa = security("BITSTAMP:BTCUSD", "D", priceIsAboveMa)
barcolor(btcPriceIsAboveMa ? color.lime : color.red)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM