简体   繁体   中英

How do I refer to the historical data of different stocks in Pinescript?

How do I refer to the historical data of different stocks in Pinescript?

I want to refer to the historical data of Apple and Microsoft

Normally, Pinescript automatically refers the close function to the symbol that is on the chart.

So how do I define that the close function refers to different stocks?

For example: Define that as an entry rule the closing price of MSFT, AAPL and SPX must be greater than the previous day's price.

You should use the security function for this together with the History reference operator

The first parameter is the ticker , so you can write the stock's name you want to get the data from there.

Then you can request previous day's close price like below:

//@version=5
indicator("My script", overlay=true)
apple_prev_day_close = request.security("BATS:AAPL", "D", close[1])
plot(apple_prev_day_close)

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