This ProBuilder code snippet is designed to calculate and plot the highest high and lowest low prices within a specified time range across the last 5 days. It is useful for analyzing price movements within specific trading hours over a recent period.
starthour = 100000
endhour = 160000
count = today-date
tcondition = time>=starthour and time<=endhour
if count<=5 and count>0 then
if tcondition then
hh=max(hh,high)
ll=min(ll,low)
endif
if tcondition[1] and not tcondition then
drawhline(hh) coloured(0,255,0)
drawhline(ll) coloured(255,0,0)
hh=0
ll=close*1000
endif
endif
return
Explanation of the Code:
- Variable Initialization: The variables starthour and endhour define the start and end of the time range (in HHMMSS format) for which the highs and lows are to be calculated.
- Counting Days: The variable count is used to ensure that the data from only the last 5 days is considered. It calculates the difference between today’s date and the date of the current data point.
- Time Condition: tcondition checks if the current time is within the specified range.
- Calculating Highs and Lows: If tcondition is true, the code updates the highest high (hh) and lowest low (ll) for the current day within the specified time range.
- Plotting Lines: When the time condition changes from true to false (end of the specified time range), horizontal lines are drawn at the highest high and lowest low values calculated, colored green and red respectively.
- Resetting Variables: After plotting, hh and ll are reset to prepare for the next day’s calculation. ll is set to an exaggerated low value (close price multiplied by 1000) to ensure it captures the actual lowest low the next day.
This snippet is particularly useful for traders or analysts who focus on price action within specific market hours and need to visually track extremes over a short historical period.