There is a common misconception among beginners when working with lower time-frames that can lead to confusion or a misunderstanding of the data in front of them. Hopefully, this article can help people to understand the limitations of importing data from a time-frame which is lower (faster) than the chart time-frame on which an indicator is applied.
A request often received will usually contain something along the lines of:
I primarily trade on the 1hour chart but would like to perform some multi time-frame analysis. Can you help me create an indicator that shows me what [insert indicator name here] is doing on other time-frames. I am primarily interested in the 4h, daily and 5 minute time-frames.
At this point, we then enter into a discussion to explain why trying to import 5-minute data on a 1-hour chart may not yield the results they desire.
The higher the time-frame, the lower the resolution
First, let’s start with the basics. Most people do not have trouble understanding that a 5-minute candlestick contains an overview of what happened over the last 5 minutes. We can think of it as a summary because we get the big picture of what happened (
OHLCV) but at the same time, some information is actually lost. For example, a 5-minute candlestick will not tell us if the price hit the low before the high or the high before the low. Generally, if we want more information we need to go to a lower timeframe. For example, 5 x 1-minute bars will be able to provide more of this detail (but again not all of it). All this means that as you rise through the time-frames, you trade information to gain a big picture overview. Let’s take a look at an example:
The image above shows a side by side comparison of the 1-minute GBPUSD chart vs the same period of the 5-minute candles on the right. Additionally, the 5-minute candles have been manually drawn on the 1-minute chart.
The second image illustrates that the 5-minute candle does not contain all the information regarding how price action unfolded over that period of time. Make a mental note of this as understanding it will help later when we show examples of missing information after importing 1-minute data on a 5-minute chart.
Your Script is run less frequently on higher time-frames
The next key thing to understand is that for historical data, your script is run once per bar/candle. So if we are on a higher timeframe, that means there are fewer bars on screen and in turn, that means we will run the script fewer times. In other words, you will just get one snapshot, one chance to calculate things and one chance to take action every 5 minutes on the 5-minute chart. Conversely, you would get 5 snapshots over the same period on the 1-minute timeframe. This is shown in the image below.
Note: When working with live data, your study scripts will run on every tick. Strategies will do this too if you enable an option. This can lead to repainting when you refresh your browser. However, that is a topic for another day!
Quit Stating the obvious!
Ok, ok! Here is the important bit. Given that the script will run less frequently, this means that if you try to import 1-minute data on a 5-minute time-frame, you only get a small 1-minute snapshot of the lower time-frame every 5 minutes. You will not get all 5 bars! You will be missing 4 bars of information.
In the image below we have added a 9 period SMA to both the 1-minute and 5-minute time-frames. However, the 5-minute time-frame is importing the 9-period SMA from the 1-minute time-frame.
If you look at horizontal blue lines you will see that we are just importing a snapshot of where the 1-minute SMA level was at during the last 1-minute bar in every 5-minute period. These points are then just joined up from point-to-point between bars. It does not show you the complete movement of the 1-minute SMA over the 5-minute period. Noice the curve vs the diagonal lines.
These mechanics have some subtle implications that you might not expect.
If your strategy or indicator generates a signal based on what is happening on the lower time-frame, it may not produce a signal when you are expecting it to. Take another look at the image above. Now Imagine that you wanted to go short as soon as price closes below the SMA on the downside. When backtesting during the last 5-minute period, you would have gone short at the end of the 5-minute period rather than on the first bar when the 1-minute actually broke it. Importing 1-minute data will not help you enter earlier!
In addition, a potentially less obvious and more sinister issue is that it can give you a misleading view of what happened. Let’s take another closer look at the chart. We can see that it looked like the high busted through the 9 period MA on the lower time-frame. However, if you look at the actual price action, it never actually broke the 1-minute SMA.
It looks like this because the high of the 5 minute period was towards the start of the bar but at that time, the SMA was also much higher. By the end of the bar, we get
OHLCon the 5-minute chart showing the highest high over that period but only a snapshot of the 1-minute SMA at the end of the chart.
To be clear, this is NOT a bug! It is simply the mechanics and limitations of consolidating data when we wish to view an “overview” of what happened on a higher time-frame!
So although it is possible to import lower time-frame data into a script, you should consider if it is the right approach for you. Hopefully, this article will help you make that decision in a more informed way!
Find This Post Useful?
If this post saved you time and effort, please consider support the site! There are many ways to support us some won’t cost you a penny.
Backtest Rookies is a registered with Brave publisher!
Brave users can drop us a tip.
Alternatively, support us by switching to Brave using this referral link and we will receive some BAT!
Is there a possibility to capture all the lower timeframe data in the form of pinescript array?