Skip to content

Instantly share code, notes, and snippets.

@NVentimiglia
Last active September 18, 2024 17:30
Show Gist options
  • Save NVentimiglia/52e0ce1ad871fdb4bd86153523d17fa9 to your computer and use it in GitHub Desktop.
Save NVentimiglia/52e0ce1ad871fdb4bd86153523d17fa9 to your computer and use it in GitHub Desktop.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// https://gist.github.com/NVentimiglia/52e0ce1ad871fdb4bd86153523d17fa9
//@version=5
indicator("[Nic] Intraday Volume Cycles")
sample = input.int(10, "Days to sample")
// heatmap colors
chm1 = #ff0000 // extra high red
chm2 = #ff7800 // high orange
chm3 = #ffcf03 // medium yellow
chm4 = #a0d6dc // normal
chm5 = #1f9cac // low
chmbg = #5a0000 // background
// Datatype which tracks volume by intraday time
type cycleData
int m
int h
float[] volumes
// Cache of cycle sets
var cycleData[] cycles = array.new<cycleData>()
// find current cycleData
cycleData current = na
for [index, value] in cycles
if timeframe.isintraday ? (value.m == minute(time) and value.h == hour(time)) : (value.h == dayofweek(time))
current := value
break
// create cycleData if is null
if na(current)
current := timeframe.isintraday ? cycleData.new(minute(time), hour(time), array.new<float>()) : cycleData.new(dayofweek(time), dayofweek(time), array.new<float>())
current.volumes.push(volume)
cycles.push(current)
else
// update history
if current.volumes.size() >= sample
current.volumes.remove(0)
current.volumes.push(volume)
// Derivitive data
int arraySize = array.size(current.volumes)
average = array.avg(current.volumes)
highest = array.max(current.volumes)
percent = volume / average * 100
color = volume >= highest ? chm1 : percent >= 150 ? chm2 : percent >= 100 ? chm3 : percent >= 75 ? chm4 : chm5
// plot highest
plot(highest, "Highest", chmbg, style=plot.style_columns)
// plot current
plot(volume, "Volume", color, style=plot.style_columns)
// plot average
plot(average, "Average", color.blue, linewidth = 2, style = plot.style_line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment