Skip to content
All library documents

HSV and HSL Color Conversion, Gradients, and Contrast Utilities

Article TradingView scripts

Summary

This Pine Script library supplies color utilities for chart indicators and visualizations. It converts between RGB and HSV or HSL representations, constructs colors from those components, and limits hue, saturation, lightness or value, and alpha inputs to valid ranges. Its gradient functions interpolate between endpoint colors according to a signal’s position between specified bounds, including a shortest-path adjustment for hue rotation.

Additional helpers invert color brightness, estimate relative luminance and brightness, select contrasting colors using a threshold, apply easing curves, and derive hue or gradient values from a plotted series. The library is intended to support chart presentation rather than generate trading signals or test a strategy. The source shows implementation formulas but offers no visual examples, accuracy comparisons, or trading evidence; users should check the output and contrast behavior in their own scripts, particularly where accessibility or precise color matching matters.

Key ideas

  • RGB colors can be converted to HSV or HSL components and reconstructed from those components.
  • Gradient helpers map a signal’s position within a range to interpolated color values.
  • Hue interpolation accounts for circular wraparound so the transition can follow a shorter path.
  • Brightness and luminance helpers support threshold-based choices of contrasting text or fill colors.
  • The library concerns visualization and provides no evidence about trading performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.