dboichenko

Get intraday extended data

dboichenko 已更新   
If you have interacted with Pine for some time, you probably noticed that if you are using DWM resolutions, you will not be able to obtain complete data from the extended intraday ticker using the usual functions request.security() and request.security_lower_tf(). This is quite logical if you understand the principle of mapping data from the secure context to the main one. The main reason is the different opening and closing times of the intraday data with extended clocks and DWM.

This script visualizes one of the approaches to solving this problem. I will briefly describe the principle of operation:

For example, take the symbol NASDAQ:AAPL.
Our main resolution is 1D, but we want to receive extended data from a 4-hour interval. The daytime bar opens at 09:30 and closes at 16:00. The same period at a resolution of 4 hours covers 4 bars:
04:00 - 08:00
08:00 - 12:00
12:00 - 16:00
16:00 - 20:00
So, if we use the request.security_lower_tf() function, we will not get the bars 04:00 - 08:00 and 16:00 - 20:00 because their closing times are not within the range of the main context (09:30 - 16:00).

If we use the request.security() function, we will get the bar 04:00 - 08:00, but we will not get the bar 16:00 - 20:00 because its closing time will be in the future, and it is impossible to get values from the future.

So, what I propose is to use the upgraded request.security() function, inside which another function will be executed, storing all the bars in a var array and putting the post-market bars in the array of the next day. Next, all we have to do is isolate these bars, place them in the previous array, and remove them from the current one.

I visualized the received data simply as text, but you can do it differently using the proposed mechanism.

In order for everything to work, you need to fill in the inputs correctly:
"Symbol for calculate" - This is the symbol from which we will receive extended data.
"Intraday data period" - The period from which we will receive extended data.
"Specify your chart timeframe here" - This is an input that allows you to operate with data from the main context while being inside the secure one. Enter your current chart timeframe here. If there are problems, a warning will appear informing you about this.

If you want to use these developments, take the get_data() function, it will return:
1. the number of past items - it is useful for outputting values in real time, because it is not possible to simply delete them there, because they will always arrive and it is easier to make a slice with an indentation for this number
2. cleared object of type Inner_data containing arrays of open, high, low, close, volume, time, time_close intraday data
3. its same value from the previous bar
版本注释:
bugs fix
版本注释:
changed input logic on security
版本注释:
change comment
版本注释:
improve
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?