Hallo,
I need help for previous hourly high/low. The code below doesn’t show the correct high/low for the second hour after opening – tried with Futures and Stocks. It is also strange that the plot has to be moved at return with hourlyhigh [1]. Everything else seems to work fine. Please have a look…
Best regards
//Previous Hourly High/Low
once hourhigh=undefined
once hourlow=undefined
hhigh= high[0]
hlow= low[0]
if Hour <> Hour[1] then
hourhigh = Highest[BarIndex – lastHourBarIndex](hhigh)
hourlow = Lowest[BarIndex – lastHourBarIndex](hlow)
lastHourBarIndex = BarIndex
if Day <> Day[1] then
hourhigh = hourhigh[1]
hourlow = hourlow[1]
endif
endif
return hourhigh[1] coloured(0,0,0) style(line,1) as “Prev Hour High”, hourlow[1] coloured(0,0,0) style(line,1) as “Prev Hour Low”
To write code, please use the <> “insert PRT code” button, to make code more readable. Thank you.
Try this one:
//Previous Hourly High/Low
defparam calculateonlastbars=1000
if OpenHour <> OpenHour[1] then
PreviousHigh = hourhigh
PreviousLow = hourlow
hourhigh = 0
hourlow = 999999
endif
hourhigh = max(hourhigh,high)
hourlow = min(hourlow,low)
return PreviousHigh coloured(0,0,0) style(line,1) as "Prev Hour High", PreviousLow coloured(0,0,0) style(line,1) as "Prev Hour Low"
Thanks for the reply. Is there a solution without “defparam calculateonlastbars”, because this has also an influence if this code is part of a script with other calculations??
The solution is to remove that line, it only limits the calculation for that bars quantity, that’s all.