i am different
i am different

Reputation: 183

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

I couldnt find it in the docs. Any hint?

Upvotes: 1

Views: 437

Answers (1)

mr_statler
mr_statler

Reputation: 2161

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)

Upvotes: 2

Related Questions