PINE LIBRARY

MaterialPalette

119
MaterialPalette Library

█ OVERVIEW

This Pine Script® library provides a convenient way to access and utilize colors based on the popular Material Design color system directly within your TradingView scripts. It offers a comprehensive set of functions to retrieve specific shades of various base colors, allowing developers to create visually consistent and aesthetically pleasing indicators and strategies.

By importing this library, you gain access to functions that generate colors based on saturation, darkness level, and opacity, simplifying the process of managing color palettes in your projects.

█ FEATURES

  • Provides exported functions for 18 base Material Design colors (e.g., `red()`, `blue()`, `green()`, `amber()`, etc.).
  • Each color function allows selection from multiple shades based on `saturationLevel` (int) and `darkLevel` (int).
  • All color functions accept an `opacity` parameter (integer, 0-100).
  • Includes a `tone()` function for quick access to predefined base tones (e.g., `tone("red")`).
  • Offers a consistent and organized approach to using Material Design colors in Pine Script®.
  • Includes detailed `Function`, `param`, and `Returns` annotations within the code for comprehensive documentation.


█ HOW TO USE

To use this library in your own Pine Script® indicator or strategy, you first need to import it using the `import` statement.

1. Import the Library:
Add the following line at the beginning of your script. Remember to replace `mastertop_astray` with the actual TradingView username the library is published under, and `VERSION` with the specific version number of the library you wish to use (you can find this on the library's script page).

Pine Script®
import mastertop_astray/MaterialPalette/VERSION as mp // Example: import mastertop_astray/MaterialPalette/1 as mp

*(We use `mp` as a short alias for `MaterialPalette` for convenience)*

2. Call Exported Functions:
Once imported, you can call the exported functions using the alias (`mp.` prefix).

Pine Script®
//@version=6 indicator("My Indicator Using MaterialPalette") import mastertop_astray/MaterialPalette/VERSION as mp // Replace VERSION // --- Get Colors --- // Get a specific shade: Dark Red (darkLevel=3), highest saturation (13), fully opaque (0) darkRed = mp.red(13, 3, 0) // Get another shade: Light Blue (lightLevel=1), medium saturation (e.g., 7), 50% opacity lightBlueTransparent = mp.lightBlue(7, 1, 50) // Get a base tone color: Green, fully opaque baseGreen = mp.tone("green", 0) // Get another base tone: Amber, 80% opacity amberToneTransparent = mp.tone("amber", 80) // --- Use Colors in Plotting --- plot(close, color = darkRed, title = "Close Line") plot(sma(close, 20), color = lightBlueTransparent, title = "SMA 20") bgcolor(close > open ? mp.green(1, 2, 90) : mp.red(1, 2, 90)) // Use light shades for background // Use a base tone hline(100, "Upper Band", color = amberToneTransparent)


█ EXPORTED FUNCTIONS

This library provides two main categories of functions:

1. Color Shade Generators (`red()` to `blueGrey()`):
  • Includes: 18 functions for base colors (`red()`, `pink()`, ..., `blueGrey()`).
  • Purpose: Generate specific shades of the base color according to Material Design palettes.
  • Parameter `saturationLevel` (int): Controls color intensity/saturation. The valid range and default value vary depending on the specific color function (typically 1-13 or 1-9). Please check the `param` annotation in the code for each function.
  • Parameter `darkLevel` (int): Sets the lightness/darkness of the shade (1: Light, 2: Medium/Base, 3: Dark). Default is 2.
  • Parameter `opacity` (int): Sets the color's transparency (0 = Opaque, 100 = Invisible). Default is 0.
  • Returns: The calculated `color` value.
  • Note: For exact default values and valid saturation ranges for each specific color function, refer to the detailed `param` annotations within the library's source code.


2. Base Tone Function (`tone()`):
  • Purpose: Retrieve a single, predefined base color tone from the palette.
  • Parameter `colorName` (simple string): The text name identifying the desired base color (e.g., 'red', 'blue', 'green', 'light_blue').
  • Parameter `opacity` (int): Sets the color's transparency (0 = Opaque, 100 = Invisible). Default is 0.
  • Returns: The corresponding base tone `color`.
  • Note: Please consult the function's implementation in the source code for the complete list of valid `colorName` strings.


█ VISUALIZATION TABLE (For Demonstration)

The library's source code includes logic (within an `if barstate.islast` block) that generates a large table displaying all available color shades.

Important: This table will only appear on your chart if you add the entire library code itself directly as an indicator. This is primarily intended for demonstration, reference, and development purposes to visualize the palette. When using the library normally via the `import` statement in your own scripts, this table code is not executed or needed.

█ SUMMARY

The `MaterialPalette` library offers a structured and easy way for Pine Script® developers to incorporate Material Design colors into their TradingView scripts, enhancing visual appeal and consistency. Please refer to the detailed comments within the code for specifics on parameter ranges and available tones.

This source code is subject to the terms of the Mozilla Public License 2.0.
© mastertop_astray

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.