This ProBuilder code snippet is designed to calculate the timeframe of each bar on the chart and use this information to compute key metrics for a Donchian Channel. The Donchian Channel is a popular indicator used in market trading to show the highest high and the lowest low over a set number of periods.
once NbBar = 2
MyDay=openday
dayminutes = 1440*(MyDay-MyDay[1])
MyHour=openhour
hourminutes = 60*(MyHour-MyHour[1])
MyMin=openminute
barminutes = MyMin - MyMin[1] + hourminutes + dayminutes
barminutes=abs(barminutes)
Mybarminutes = lowest[max(1,NbBar)](barminutes)[1]
if barindex>MyBarminutes then
lower = lowest[Mybarminutes](low)
upper = highest[Mybarminutes](high)
middle = (upper + lower) / 2
endif
return lower as "lower", upper as "upper", middle as "middle", mybarminutes
Explanation of the Code:
This snippet is particularly useful for traders and analysts looking to understand price movements within specific timeframes and apply this understanding to technical indicators like the Donchian Channel.
Check out this related content for more information:
https://www.prorealcode.com/topic/chart-timeframe-detection-in-an-indicator/#post-63681
Visit Link