After getting a bit more details from the author of the post I have a new solution. The goal is to compute the average high for the current day on an intraday chart. The code must first identify the first bar of the new day. Then count the number of bars since that first bar. We'll also need to keep a running sum total for the high of each bar since the first bar of the new day. Then we simply plot the result of that running sum of highs divided by the number of bars. And we do this for every bar on the chart.
Here is the code. Screenshot below shows the result. Notice that the code resets on the first bar of each new day.
def newDay = GetDay() <> GetDay()[1];
rec runningSumOfHighs = if newDay then high else runningSumOfHighs[1] + high;
rec numberOfBarsToday = if newDay then 1 else numberOfBarsToday[1] + 1;
plot averageHighsForToday = runningSumOfHighs / numberOfBarsToday;
Replace this line:
plot averageHighsForToday = runningSumOfHighs / numberOfBarsToday;
With this:
plot averageHighsForToday = if GetDay() == GetLastDay() then runningSumOfHighs / numberOfBarsToday else Double.NaN;