Library · Pine Script v5 · Library

ColorScheme

by ricardosantos79· code credited to RicardoSantos

ColorScheme is a Pine Script v5 library that stores named colors in paired string and color arrays.

View on GitHub

GitHub stars261on the repository
Pine versionv5runs as is
Lines of code341
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago13 Nov 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

341 lines of Pine Script v5 from beta/libs/ColorScheme.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ColorScheme.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=5

// @description A color scheme generator.
library(title='ColorScheme')

import RicardoSantos/ColorExtension/1 as colex

// @function Initiate the array data registry that will hold the color profile.
// @returns tuple with 2 arrays (string array, color array)
export init() => //{
    var string[] keys = array.new_string(0)
    var color[] colors = array.new_color(0)
    [keys, colors]
//{ usage:
// [__K, __V] = init(0, '', #ffffff)
//{ remarks:
//}}}

// @function Checks the integrity of the registers.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data holder array.
// @returns void.
export check_registry_integrity (string[] key_registry, color[] color_registry) => //{
    int _size_k = array.size(key_registry)
    int _size_c = array.size(color_registry)
    if _size_k != _size_c
        runtime.error('ColorScheme -> check_registry_integrity(): registers size do not match.')
//{ usage:
//{ remarks:
//}}}

// @function Add new (key, color) entry to the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param key string, the unique key to reference the value.
// @param value color, the color value of the specified key.
// @returns void.
export add (string[] key_registry, color[] color_registry, string key, color value) => //{
    check_registry_integrity(key_registry, color_registry)
    int is_key_in = array.indexof(key_registry, key)
    if is_key_in > -1
        runtime.error('ColorScheme -> add(): key is already present in registry.')
    else
        array.push(key_registry, key)
        array.push(color_registry, value)
//{ usage:
//{ remarks:
//}}}

// @function Get a (key, color) entry from the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param key string, the unique key to reference the value.
// @returns void.
export get_color (string[] key_registry, color[] color_registry, string key) => //{
    check_registry_integrity(key_registry, color_registry)
    int _key_index = array.indexof(key_registry, key)
    if _key_index < 0
        runtime.error('ColorScheme -> delete(): key is not present in registry.')
        color(na)
    else
        array.get(color_registry, _key_index)
//{ usage:
//{ remarks:
//}}}

// @function Edit a (key, color) entry in the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param key string, the unique key to reference the value.
// @param new_key string, the unique key to reference the value.
// @returns void.
export edit_key (string[] key_registry, color[] color_registry, string key, string new_key) => //{
    check_registry_integrity(key_registry, color_registry)
    int _key_index = array.indexof(key_registry, key)
    int _new_key_index = array.indexof(key_registry, key)
    if _key_index < 0
        runtime.error('ColorScheme -> edit_key(): key is not present in registry.')
    if _new_key_index > -1
        runtime.error('ColorScheme -> edit_key(): new key is already present in registry.')
    else
        array.set(key_registry, _key_index, new_key)
//{ usage:
//{ remarks:
//}}}

// @function Edit a (key, color) entry in the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param key string, the unique key to reference the value.
// @param new_value color, the color value of the specified key.
// @returns void.
export edit_color (string[] key_registry, color[] color_registry, string key, color new_value) => //{
    check_registry_integrity(key_registry, color_registry)
    int _key_index = array.indexof(key_registry, key)
    if _key_index < 0
        runtime.error('ColorScheme -> edit_color(): key is not present in registry.')
    else
        array.set(color_registry, _key_index, new_value)
//{ usage:
//{ remarks:
//}}}

// @function Delete a (key, color) entry from the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param key string, the unique key to reference the value.
// @returns void.
export delete (string[] key_registry, color[] color_registry, string key) => //{
    check_registry_integrity(key_registry, color_registry)
    int _key_index = array.indexof(key_registry, key)
    if _key_index < 0
        runtime.error('ColorScheme -> delete(): key is not present in registry.')
        color(na)
    else
        array.remove(key_registry, _key_index)
        array.remove(color_registry, _key_index)
//{ usage:
//{ remarks:
//}}}

// @function Delete all (key, color) entrys from the registry.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @returns void.
export delete_all (string[] key_registry, color[] color_registry) => //{
    array.clear(key_registry)
    array.clear(color_registry)
//{ usage:
//{ remarks:
//}}}

// @function Enumerate models available to profile colors.
// @param index int, index of model. (1:'monochromatic', 2:'analog', 3:'triadic', 4:'tetradic', 5:'square', anything else:'monochromatic')
// @returns string.
export model (int index=0) => //{
    switch index
        1 => 'monochromatic'
        2 => 'analog'
        3 => 'triadic'
        4 => 'tetradic'
        5 => 'square'
        => 'monochromatic'
//{ usage:
//{ remarks:
//}}}

// @function Generate a multi color scheme.
// @param key_registry string array, key data holder array.
// @param color_registry color array, color value data array.
// @param primary color, the origin color to base the profile.
// @param model string, default='monochromatic', options=('monochromatic', 'triadic near', 'triadic far', 'tetradic')
// @returns void.
export generate_scheme(string[] key_registry, color[] color_registry, color primary, string model='monochromatic') =>
    check_registry_integrity(key_registry, color_registry)
    // delete_all(key_registry, color_registry) // possible implementation to clear registry conflicts?
    add(key_registry, color_registry, 'primary 0', primary)
    // primary color hsl properties:
    [_primary_hue, _primary_saturation, _primary_lightness] = colex.rgb_to_hsl(color.r(primary), color.g(primary), color.b(primary))
    switch model
        model(1) =>
            // monochromatic generates 4 colors: primary + 3 shades to the most distant edge (dark, light)
            // generate shades to dark or light
            if _primary_lightness >= 50.0
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.25, 0.0))
            else
                float _inverse_range = 100.0 - _primary_lightness
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + _inverse_range * 0.25, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + _inverse_range * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + _inverse_range * 0.75, 0.0))
        model(2) =>
            // analog generates 2 adjacent base colors and 3 shades to the most distant edge (dark, light) for each
            [_lower, _upper] = colex.analog(primary)
            [_lower_hue, _lower_saturation, _lower_lightness] = colex.rgb_to_hsl(color.r(_lower), color.g(_lower), color.b(_lower))
            [_upper_hue, _upper_saturation, _upper_lightness] = colex.rgb_to_hsl(color.r(_upper), color.g(_upper), color.b(_upper))
            // generate shades to dark or light
            if _primary_lightness >= 50.0
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.25, 0.0))
            else
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.75, 0.0))
        model(3) =>
            // triadic generates 2 far spectrum base colors and 3 shades to the most distant edge (dark, light) for each
            [_lower, _upper] = colex.triadic(primary)
            [_lower_hue, _lower_saturation, _lower_lightness] = colex.rgb_to_hsl(color.r(_lower), color.g(_lower), color.b(_lower))
            [_upper_hue, _upper_saturation, _upper_lightness] = colex.rgb_to_hsl(color.r(_upper), color.g(_upper), color.b(_upper))
            // generate shades to dark or light
            if _primary_lightness >= 50.0
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.25, 0.0))
            else
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.75, 0.0))
        model(4) =>
            // tetradic generates 3 complement colors in a rectangular shape and 3 shades for each.
            [_complement, _lower, _upper] = colex.tetradic(primary)
            [_complement_hue, _complement_saturation, _complement_lightness] = colex.rgb_to_hsl(color.r(_complement), color.g(_complement), color.b(_complement))
            [_lower_hue, _lower_saturation, _lower_lightness] = colex.rgb_to_hsl(color.r(_lower), color.g(_lower), color.b(_lower))
            [_upper_hue, _upper_saturation, _upper_lightness] = colex.rgb_to_hsl(color.r(_upper), color.g(_upper), color.b(_upper))
            // generate shades to dark or light
            if _primary_lightness >= 50.0
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'complement 0', _complement)
                add(key_registry, color_registry, 'complement 1', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'complement 2', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'complement 3', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.25, 0.0))
            else
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'complement 0', _complement)
                add(key_registry, color_registry, 'complement 1', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'complement 2', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'complement 3', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.75, 0.0))
        model(5) =>
            // tetradic generates 3 complement colors in a rectangular shape and 3 shades for each.
            [_complement, _lower, _upper] = colex.square(primary)
            [_complement_hue, _complement_saturation, _complement_lightness] = colex.rgb_to_hsl(color.r(_complement), color.g(_complement), color.b(_complement))
            [_lower_hue, _lower_saturation, _lower_lightness] = colex.rgb_to_hsl(color.r(_lower), color.g(_lower), color.b(_lower))
            [_upper_hue, _upper_saturation, _upper_lightness] = colex.rgb_to_hsl(color.r(_upper), color.g(_upper), color.b(_upper))
            // generate shades to dark or light
            if _primary_lightness >= 50.0
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness * 0.25, 0.0))
                add(key_registry, color_registry, 'complement 0', _complement)
                add(key_registry, color_registry, 'complement 1', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.75, 0.0))
                add(key_registry, color_registry, 'complement 2', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.50, 0.0))
                add(key_registry, color_registry, 'complement 3', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness * 0.25, 0.0))
            else
                add(key_registry, color_registry, 'primary 1', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'primary 2', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'primary 3', colex.hsl(_primary_hue, _primary_saturation, _primary_lightness + (100.0 - _primary_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'lower 0', _lower)
                add(key_registry, color_registry, 'lower 1', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'lower 2', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'lower 3', colex.hsl(_lower_hue, _lower_saturation, _lower_lightness + (100.0 - _lower_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'upper 0', _upper)
                add(key_registry, color_registry, 'upper 1', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'upper 2', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'upper 3', colex.hsl(_upper_hue, _upper_saturation, _upper_lightness + (100.0 - _upper_lightness) * 0.75, 0.0))
                add(key_registry, color_registry, 'complement 0', _complement)
                add(key_registry, color_registry, 'complement 1', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.25, 0.0))
                add(key_registry, color_registry, 'complement 2', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.50, 0.0))
                add(key_registry, color_registry, 'complement 3', colex.hsl(_complement_hue, _complement_saturation, _complement_lightness + (100.0 - _complement_lightness) * 0.75, 0.0))
//{ usage:
//{ remarks:
//}}}

color primary = input.color(#e3f650)
int imodel = input(1)
[__K, __V] = init()
if barstate.isfirst
    generate_scheme(__K, __V, primary, model(imodel))
    label.new(bar_index, 0.0, 'primary 0', color=get_color(__K, __V, 'primary 0'))
    if imodel > 0
        label.new(bar_index, 1.0, 'primary 1', color=get_color(__K, __V, 'primary 1'))
        label.new(bar_index, 2.0, 'primary 2', color=get_color(__K, __V, 'primary 2'))
        label.new(bar_index, 3.0, 'primary 3', color=get_color(__K, __V, 'primary 3'))
    if imodel > 1
        label.new(bar_index+10, 0.0, 'lower 0', color=get_color(__K, __V, 'lower 0'))
        label.new(bar_index+10, 1.0, 'lower 1', color=get_color(__K, __V, 'lower 1'))
        label.new(bar_index+10, 2.0, 'lower 2', color=get_color(__K, __V, 'lower 2'))
        label.new(bar_index+10, 3.0, 'lower 3', color=get_color(__K, __V, 'lower 3'))
        label.new(bar_index+20, 0.0, 'upper 0', color=get_color(__K, __V, 'upper 0'))
        label.new(bar_index+20, 1.0, 'upper 1', color=get_color(__K, __V, 'upper 1'))
        label.new(bar_index+20, 2.0, 'upper 2', color=get_color(__K, __V, 'upper 2'))
        label.new(bar_index+20, 3.0, 'upper 3', color=get_color(__K, __V, 'upper 3'))
    if imodel > 3
        label.new(bar_index+30, 0.0, 'complement 0', color=get_color(__K, __V, 'complement 0'))
        label.new(bar_index+30, 1.0, 'complement 1', color=get_color(__K, __V, 'complement 1'))
        label.new(bar_index+30, 2.0, 'complement 2', color=get_color(__K, __V, 'complement 2'))
        label.new(bar_index+30, 3.0, 'complement 3', color=get_color(__K, __V, 'complement 3'))

Overview

ColorScheme creates an empty registry, checks that the key and color arrays stay the same length, and adds, reads, or renames entries by unique keys. Duplicate or missing keys raise runtime errors. It draws nothing and has no signals, entries, exits, or position rules. Callers supply the keys and colors.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

Type

Library, Pine Script v5

Draws

Library (no plots)

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
primarycolor#e3f650primary
imodelint1imodel
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

KernelFunctions

by artificial-intelligence-edge
75 stars

KernelFunctions is a Pine Script v5 library that exports kernel weight functions for Nadaraya-Watson style estimation. It calculates a Rational Quadratic kernel, a Gaussian kernel based on a radial basis function, and a periodic kernel that models repeating be

Library v5
Updated 2 days ago · MIT GitHub repository of KernelFunctions

Ta

by nersent
29 stars

This Pine Script v5 library exports thin wrappers around built-in technical analysis functions. It covers moving averages, momentum measures such as RSI and CCI, volatility tools including ATR and standard deviation, range extremes, cross detection, and runnin

Library v5
Updated 11 months ago · Custom licence GitHub repository of Ta

Bands

by heyphat
26 stars

This library exports a Band type and functions that build a simple-moving-average basis with upper and lower envelopes from standard deviation. It classifies a source as above, below, or inside those envelopes, measures band width, and scales an imported z-sco

Library v6 Volatility & bandsMoving averages
Updated 2 months ago · AGPL-3.0 GitHub repository of Bands

Mylib

by ferranbt
21 stars

This script serves as a minimal utility library written in Pine Script v6. It provides an exported helper function that calculates the sum of two numeric arguments. As a reusable code library, it produces no visual plots, charts, or trading signals, and it con

Library v6
Updated 7 weeks ago · MPL-2.0 GitHub repository of Mylib

HLevel

by stupenkov
14 stars

HLevel is a Pine Script v5 utility library designed to manage horizontal price levels for cryptocurrency charts. It defines custom types for pivots and levels, along with methods to initialize, add, track, and expire price levels based on pivot high and pivot

Library v5
Updated 3 years ago · None stated GitHub repository of HLevel

Zignaly2Beta

by ruckard
13 stars

This library provides helper functions to format and build JSON webhook alert payloads for the Zignaly automated trading platform. It constructs formatted messages containing parameters such as trading pair, exchange, account type, leverage, margin mode, hedge

Library v5
Updated 1 year ago · None stated GitHub repository of Zignaly2Beta

More libraries

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers