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提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想在圖表上使用此腳本?