TradingView
PineCoders
13 Mei 2021 pukul 04.32

Color Gradient Framework [PineCoders] 

Euro Fx/U.S. DollarFXCM

Huraian

█ OVERVIEW

This indicator shows how you can use the new color functions in Pine to generate color gradients. We provide functions that will help Pine coders generate gradients for multiple use cases using base colors for bull and bear states.


█ CONCEPTS

For coders interested in maximizing the use of color in their scripts, TradingView has added new color functions and new functionality to existing functions. For us coders, this translates in the ability to generate colors on the fly and use dynamic colors ("series color") in more places.

New functions allow us to:
 • Generate colors dynamically from calculated RGBA components ("A" is the Alpha channel, known to Pine coders as the "transparency"). See color.rgb().
 • Extract RGBA components from existing colors. See color.r(), color.g(), color.b() and color.t().
 • Generate linear gradients between two colors. See color.from_gradient().

Improvements to existing color/plotting functions allow more flexible use of color:
 • plotcandle() now accepts a "series color" argument for its `wickcolor` and `bordercolor` parameters.
 • plotarrow() now accepts a "series color" argument for its `colorup` and `colordown` parameters.

Gradients are not only useful to make script visuals prettier; they can be used to pack more information in your displays. Our gradient #4 goes overboard with the concept by using a different gradient for the source line, its fill, and the background.


█ OUR SCRIPT

The script presents four functions to generate gradients:
f_c_gradientRelative(_source, _min, _max, _c_bear, _c_bull) f_c_gradientRelativePro(_source, _min, _max, _c_bearWeak, _c_bearStrong, _c_bullWeak, _c_bullStrong) f_c_gradientAdvDec(_source, _center, _c_bear, _c_bull) f_c_gradientAdvDecPro(_source, _center, _steps, _c_bearWeak, _c_bearStrong, _c_bullWeak, _c_bullStrong)


The relative gradient functions are useful to generate gradients on a source that oscillates between known upper/lower limits. They use the relative position of the source between the `_min` and `_max` levels to generate the color. A centerline is derived from the `_min` and `_max` levels. The source's position above/below that centerline determines if the bull/bear color is used, and the relative position of the source between the centerline and the max/min level determines the gradient of the bull/bear color.

The advance/decline gradient functions are useful to generate gradients on a source for which min/max levels are unknown. These functions use source advances and declines to determine a gradient level. The `f_c_gradientAdvDec()` version uses the historical maximum of advances/declines to determine how many correspond to the strongest bull/bear colors, making its gradients adaptive. The `f_c_gradientAdvDecPro()` version requires the explicit number of advances/declines that correspond to the strongest bull/bear colors. This is useful when coloring chart bars, for example, where too many gradient levels are difficult to distinguish. Using the Pro version of the function allows you to limit the number of gradient levels to 5, for example, so that transitions are fewer, but more obvious. The `_center` parameter of the advance/decline functions allows them to determine which of the bull/bear colors to use.

Note that the custom `f_colorNew(_color, _transp)` function we use in our script should soon no longer be necessary, as changes are under way to allow color.new() to accept series arguments.

Inputs
The script's inputs demonstrate one way you can allow users to choose base bull/bear colors. Because users can modify any of the colors, only two are technically needed: one for bull, one for bear, as we do for the configuration of the bull/bear colors for the background in the gradient #4 configuration. Providing a few presets from which users can choose can be useful for color-challenged script users, but that type of inputs has the disadvantage of not rendering optimally in all OS/Browser environments.

You can use the inputs to select one of eight gradient demonstrations to display.


█ THANKS

Thanks to the PineCoders team for validating the code and description of this publication.
Thanks also to the many TradingView devs from multiple teams who made these improvements to Pine colors possible.



Look first. Then leap.

Nota Keluaran

v2.0
We added an RGBA color tuner at the bottom of the inputs. You can use it to play around with values and see the result displayed in the indicator's background. Remember to bring down the transparency to make your RGB colors visible.

Nota Keluaran

v3.0
• Removed `var` declaration inside `f_colorNew()`.
• Aesthetic fix.

Nota Keluaran

v4
color.new() now accepts series arguments for both its `color` and `transp` parameters. Accordingly, we replaced calls to our custom `f_colorNew(_color, _transp)` function with calls to color.new().
Komen
ImmortalFreedom
My visions of polychromatic digital artistry capabilities with ease in Pine Script, are now fulfilled. Electric sheep no longer have to just dream of charting rainbow indicators anymore. Next generation indicator possibilities with stunning dynamic vibrancy, built utilizing the ever evolving "Immense Power of Pine", are now a reality for all members to code in Pine Editor.

I humbly appreciate the work of any TV staff who made color.rgb() and color.from_gradient() feasible, "Thank you, thank you for allowing TViewer charting experiences to be even more beautiful and magnificent in the future. 💙"

Any other PineCoder participation for this polychromatic multicator script... 💚
PineCoders
@midtownsk8rguy, What a humble man you are ) You are conveniently omitting the fact that, in the back alleys where we collaborate with the Pine team to improve Pine, you were a major contributor to the design of these new functions, as was the case for many other new features brought to Pine coders in the last few years. Thanks for helping us push the boundaries of Pine, for your boundless creativity, wicked attention to detail, rare conceptual skills, and for making it fun to collaborate with you. Onward!
slowcoconut
@PineCoders, @immortalfreedomday idk who you are, but I love you. thank you for sharing such immense work. its challenging me to be better, and share more, too
racer8
@midtownsk8rguy, electric sheep? Such poetic words :)
PineCoders
Thank you all for the good words! Much appreciated. 💙
racer8
Ooh! Its nice to see improvements in TV's creativity :D Art is something that often goes underappreciated in TV. Indeed, electric sheep will be flying everywhere painting rainbows.This is somewhat of a game changer. Thxs for posting...especially in these dark times, what we need is a rainbow to cheer us up :)
joelly3d
Cant wait to integrate into my strategy and assistant indicators. been working on them for 9 months now. :)
Mindspirit
Hello, I was wondering if something can be worked on to get master-gradient functions using the overloaded Fill command for vertical Gradients. Thank you.
Luven
I am new to pine and wonder how you managed it to plot in different windows whilst in one script?
PineCoders
@Luven, Welcome to Pine! This is the best place to start your journey:
tradingview.com/?solution=43000561836
You can add the same indicator multiple times to the same chart, which is what we did here. Then, you can change the settings of each instance independently. If you want to save your setup, you can save a template or save the chart layout.
Lebih