52-Week High/Low Distance Tracker
Combined Indicator for charting and scanning
Displays distance from 52-week High and 52-week Low
declare upper;
--- Inputs ---
input showLabels = yes;
input showPlots = no; # Set to yes if you want to see lines in a lower study
--- 52 Week Calculations ---
We use AggregationPeriod.WEEK to ensure it pulls the correct 52-week data
regardless of the chart's current time frame.
def High52Week = Highest(high(period = AggregationPeriod.WEEK), 52);
def Low52Week = Lowest(low(period = AggregationPeriod.WEEK), 52);
--- Math Logic ---
Distance from High (How far below the high we are)
plot DistFromHigh = High52Week - close;
Distance from Low (How far above the low we are)
plot DistFromLow = close - Low52Week;
--- Visual Styling ---
Define colors for professional-grade styling
DefineGlobalColor("HighDist", Color.RED);
DefineGlobalColor("LowDist", Color.GREEN);
Labels for On-Chart Dashboard
AddLabel(showLabels, "52W High: " + High52Week + " (Dist: " + (DistFromHigh) + ")", GlobalColor("HighDist"));
AddLabel(showLabels, "52W Low: " + Low52Week + " (Dist: " + (DistFromLow) + ")", GlobalColor("LowDist"));
Handle Plot Visibility
These are hidden by default to keep the price chart clean, but available for Scans
DistFromHigh.SetHiding(!showPlots);
DistFromLow.SetHiding(!showPlots);
--- Scan/Watchlist Optimization ---
To use this in a scan, you would reference 'DistFromHigh' or 'DistFromLow'