how to Input - color

W

Wannaspeed

New member
Is there a way to make a color adjustable using an input variable. I've tried searching but I can only find it for plots. Like lets say I have multiple Labels and I want a global color selection. Thanks in advance
 
T

tomsk

Well-known member
VIP
@Wannaspeed There absolutely is a slick way to implement this. Here's an example using an example I just pieced together for you to illustrate this. All you need to do is adjust the color direct from the user interface

Code:
# Recent High with User Selectable Colors
# tomsk
# 11.25.2019

input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};

def cond = close > close[1];
def bar = if cond then BarNumber() else bar[1];

plot data = if barNumber() >= HighestAll(bar) and cond then high else Double.NaN;
     data.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
     data.SetLineWeight (5);
     data.SetDefaultColor(GetColor(LabelColor));
# End Recent High with User Selectable Colors
 
W

Wannaspeed

New member
After much trial and error I got it! You can see my various mistakes in the comment out areas of the code.
Code:
#LABEL COLOR TEST
input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};

def dollarvol = VWAP* volume;
#labelColor (yes, dollarvol);
Addlabel (yes, dollarvol,getColor(labelColor));
#dollarvol.SetDefaultColor(GetColor(LabelColor));
 
T

tomsk

Well-known member
VIP
After much trial and error I got it! You can see my various mistakes in the comment out areas of the code.
Code:
#LABEL COLOR TEST
input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};

def dollarvol = VWAP* volume;
#labelColor (yes, dollarvol);
Addlabel (yes, dollarvol,getColor(labelColor));
#dollarvol.SetDefaultColor(GetColor(LabelColor));
@Wannaspeed Great job!
 
R

RMEdgar

New member
I have tried this and indeed it does change the color but it is not the color requested. Any suggestions? This is code for the Coppock indicator. I would like to change the color of the zero line when I configure the indicator.
Code:
#
#Coppock Indicator
#
declare lower;

input RateOfChangeSlowPeriod = 14;
input RateOfChangeFastPeriod = 11;
input WeightedMAPeriod = 10;
input ZeroLineColor = {default "BLACK" , "WHITE" , "GREEN"};

def AggregationPeriod = if (GetAggregationPeriod() < AggregationPeriod.WEEK) then AggregationPeriod.WEEK else GetAggregationPeriod();

def price = close(period = AggregationPeriod);

def ROC1 = if price[RateOfChangeSlowPeriod] != 0 then (price / price[RateOfChangeSlowPeriod] - 1) * 100 else 0;
def ROC2 = if price[RateOfChangeFastPeriod] != 0 then (price / price[RateOfChangeFastPeriod] - 1) * 100 else 0;

plot Coppock = WMA(ROC1 + ROC2, WeightedMAPeriod);
    Coppock.AssignValueColor(if Coppock > Coppock[1] then Color.GREEN else Color.RED);
    Coppock.SetDefaultColor(GetColor(1));
    Coppock.SetLineWeight(2);
    Coppock.HideBubble();

plot ZeroLine = 0;
    ZeroLine.SetDefaultColor(GetColor(ZeroLineColor));
    ZeroLine.HideBubble();

AddChartBubble(Coppock[1] < 0 and Coppock > Coppock[1] and Coppock[1] < Coppock[2], Coppock, "Buy", Color.CYAN, no);
 
horserider

horserider

Well-known member
VIP
Delete following 2 lines

input ZeroLineColor = {default "WHITE" , "GREEN"};

ZeroLine.SetDefaultColor(GetColor(ZeroLineColor));


Add this line and put in color of your choice if do not want white.

ZeroLine.SetDefaultColor(Color.WHITE);
 
R

RMEdgar

New member
That does not allow me to configure the color without having to edit the code
 
horserider

horserider

Well-known member
VIP
True. But why do you need to change zero line color? 🙄
 
R

RMEdgar

New member
If I have a black zero line and change the background to black it does not show up. Also, If I share the indicator with someone else I do not know what background they are using. This also gives me the freedom to change colors on other indicators If I know how to do it.
 

Similar threads

Top