Accessing Historical Data from Different Timeframes in ProBuilder

07 Jun 2020
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to access and display historical data from a different timeframe within the current chart’s timeframe. Specifically, it retrieves the date, open time, and close time of a candlestick from the 1-hour timeframe and displays this information in the current timeframe.


timeframe(1 hour, updateonclose) //save the candlestick date, open and close time in variable arrays
$candleDate[barindex]=date
$candleOpenTime[barindex]=OpenTime
$candleCloseTime[barindex]=time
timeframe(default) //get the 10th back 1-hour candlestick info
iindex = max(0,lastset($candleDate)-10)
idate = $candleDate[iindex]
iopen = $candleOpenTime[iindex]
iclose = $candleCloseTime[iindex]
return idate, iopen, iclose

The code snippet above is structured to perform the following steps:

  • Set the timeframe to 1 hour: The timeframe(1 hour, updateonclose) function changes the chart’s timeframe to 1 hour for the purpose of data extraction. The updateonclose parameter ensures that the data is updated at the close of each 1-hour candlestick.
  • Store historical data in arrays: The date, open time, and close time of each candlestick are stored in respective arrays – $candleDate, $candleOpenTime, and $candleCloseTime. These arrays are indexed by barindex, which represents the current bar’s index in the 1-hour timeframe.
  • Switch back to the default timeframe: The timeframe(default) function resets the chart’s timeframe to the default setting, typically the timeframe that the chart was originally set to display.
  • Access historical data from the arrays: The code calculates the index for the 10th last candlestick in the 1-hour timeframe using max(0, lastset($candleDate)-10). It then retrieves the date, open time, and close time for this specific candlestick using the calculated index.
  • Return the retrieved data: Finally, the date, open time, and close time of the 10th last 1-hour candlestick are returned, making them available for display or further processing in the current timeframe.

This example is useful for traders or analysts who need to compare or analyze data across different timeframes on the same chart.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/recuperer-les-donnees-horaires-des-bougies/#post-145801

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...