Skip to content

Instantly share code, notes, and snippets.

@bmurtagh
Created April 6, 2026 13:20
Show Gist options
  • Select an option

  • Save bmurtagh/22364a7b01b6cd761c95b84ed52eebae to your computer and use it in GitHub Desktop.

Select an option

Save bmurtagh/22364a7b01b6cd761c95b84ed52eebae to your computer and use it in GitHub Desktop.
# 3-Day Average Range Label
# Calculates (High-Low) for the last 3 completed days and averages them.
declare upper;
input location = Location.TOP_LEFT;
input size = fontsize.small;
# Reference the Daily High and Low with a period of "DAY"
# We use [1], [2], and [3] to reference the previous 3 completed bars.
def h1 = Round(high(period = "DAY")[1],2);
def l1 = Round(low(period = "DAY")[1],2);
def h2 = Round(high(period = "DAY")[2],2);
def l2 = Round(low(period = "DAY")[2],2);
def h3 = Round(high(period = "DAY")[3],2);
def l3 = Round(low(period = "DAY")[3],2);
# Calculate the range for each day
def range1 = h1 - l1;
def range2 = h2 - l2;
def range3 = h3 - l3;
# Calculate the Average
def avgRange = (range1 + range2 + range3) / 3;
#addlabel(yes, "range1: " + range1);
#addlabel(yes, "range2: " + range2);
#addlabel(yes, "range3: " + range3);
#addlabel(yes, "h1: " + h1);
#addlabel(yes, "l1: " + l1);
#addlabel(yes, "h2: " + h2);
#addlabel(yes, "l2: " + l2);
#addlabel(yes, "h3: " + h3);
#addlabel(yes, "l3: " + l3);
#AddLabel(yes, "PH: $" + PrevHigh + " ", Color.YELLOW, location, size, "row ownership" = yes);
#AddLabel(yes, "3d AvgRange: $ " + Round(avgRange, 2) + " ", if avgRange < 1 then Color.GREEN else Color.LIGHT_GRAY, location , size, "row ownership" = yes);
AddLabel(yes, "3d AvgRange: $ " + Round(avgRange, 2) + " ", Color.LIGHT_GRAY, location , size, "row ownership" = yes);
# Optional: Add a label for today's current range for comparison
def currentRange = high(period = "DAY") - low(period = "DAY");
AddLabel(yes, "Today's Range: $" + Round(currentRange, 2) + " ", Color.CYAN,location, size, "row ownership" = yes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment