PINE LIBRARY

Contrast Color Library

This lightweight library provides a utility method that analyzes any provided background color and automatically chooses the optimal black or white foreground color to ensure maximum visual contrast and readability.

🟠 Algorithm

The library utilizes the HSP Color Model to calculate the brightness of the background color. The formula for this calculation is as follows:

The library chooses black as the foreground color if the brightness exceeds the threshold (default 0.5), and white otherwise.
colorcolorscontrastdisplaylibraryMATH

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.


专业缠论指标: alphaviz.pro/chanlun
Email: contact@alphaviz.pro
Discord: discord.gg/w2fFtNega4
Also on:

Disclaimer