'Get & apply setting (e.g. color) from another indicator
I am creating multiple indicators - ideally to be used together.
Since many levels share the same coloring, I was wondering if I can
- get the color a user may specify in the "main" indicator for e.g. "open" line
- and re-use the same color on the second ("sub") indicator
I couldnt find it in the docs. Any hint?
Solution 1:[1]
You can't use input
from one indicator on another indicator. In some cases, you can use indicator output to another indicator using indicator on indicator function.
After saying that, you can do nice things with libraries in pine script. While you can't get inputs between two indicators, with libraries you can have the same input to all the indicators that imports this library.
You can even do a choosable color palette if you wish:
//@version=5
library("ChartColors", true)
export colorOfChart(string palette) =>
color colorOfBackgroung = na
color colorOfCandle = na
if palette == "purple/white"
colorOfBackgroung := color.new(color.purple, 90)
colorOfCandle := close > open ? color.purple : color.white
else if palette == "green/red"
colorOfBackgroung := color.new(color.green, 90)
colorOfCandle := close > open ? color.green : color.red
[colorOfBackgroung, colorOfCandle]
And than import the library to your code:
//@version=5
import usrname/ChartColors/2 as colors
indicator("My script", overlay=true)
palette = input.string(defval="green/red", title="Chosse color palette", options=["green/red", "purple/white"])
[bgColor, candleColor] = colors.colorOfChart(palette)
bgcolor(bgColor)
barcolor(candleColor)
plot(close)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mr_statler |