# Adding Color to Plots and Labels

#### MerryDay

##### Moderator
Staff member
VIP
Adding Color to Plots and Labels
A frequent request is for coloring plots, labels, watch lists: green for upticks, red for down.
This example can be applied to a plot of any type of oscillator.

Ruby:
``````# TOS RSI
declare lower ;
input show_label = yes ;
input price = close ;
input OB = 75 ;
input OS = 35 ;
input rsi_length = 14 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(50, 200, 255)) ;
DefineGlobalColor("rising",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("pretrend", CreateColor (200, 125, 255)) ;
# ########################################################

Plot RSI = reference RSI("price" = PRICE, "length" = rsi_length);
# ########################################################
#RSI> RSI[1] this statement is saying if the current candle is greater than the previous candle
#that is what [1] denotes. Thus defining uptick. The same is then done for downticks.
RSI.AssignValueColor(
if RSI> OB then GlobalColor("maxxed") else
if RSI< OS then GlobalColor("pretrend") else
if RSI> RSI[1] then GlobalColor("rising")
else GlobalColor("bear"));
RSI.SetLineWeight(3);
# ########################################################

plot OverBought = OB;
plot OverSold = OS;
plot UpArrow = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownArrow = if RSI crosses below OverBought then OverBought else Double.NaN;

DefineGlobalColor("OBcolor", CreateColor(171, 171, 225)) ;
DefineGlobalColor("OScolor", CreateColor(220, 220, 128)) ;
OverBought.SetDefaultColor(GlobalColor("OBcolor"));
OverSold.SetDefaultColor(GlobalColor("OScolor"));
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
if RSI> OB then "RSI maxxed" else
if RSI< OS then "RSI pre-trend" else
if RSI> RSI[1] then "RSI Trending " +round(RSI,2)
else "RSI Bear " +round(RSI,2) ,
if RSI> OB then GlobalColor("maxxed") else
if RSI< OS and RSI>RSI[1] then GlobalColor("pretrend") else
if RSI> RSI[1] then GlobalColor("rising")
else GlobalColor("bear"));
AddCloud(if RSI >= OB then RSI else Double.NaN, OB,
GlobalColor("maxxed"), GlobalColor("maxxed"));
AddCloud(if RSI <= OS then OS else Double.NaN, RSI,
GlobalColor("pretrend"), GlobalColor("pretrend"));
# ########################################################``````

Last edited:

#### floydddd

##### Active member
thanks. love tutorials!

#### MerryDay

##### Moderator
Staff member
VIP
Here is another example, a poster requested a Schaff watchlist

Chart & Labels
Ruby:
``````# TOS Schaff Cycle
declare lower ;
input show_label = yes ;
input OB = 80 ;
input OS = 20 ;
# ########################################################
#Using GlobalColors makes the colors modifiable
DefineGlobalColor("maxxed", CreateColor(0, 70, 30)) ;
DefineGlobalColor("rising",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("bear",  CreateColor(225, 0, 0)) ;
DefineGlobalColor("begin", CreateColor(50, 200, 255)) ;
DefineGlobalColor("zero", CreateColor (200, 125, 255)) ;
# ########################################################
Plot Schaff  = SchaffTrendCycle()."STC" ;
# ########################################################
#Schaff> Schaff[1] this statement is saying if the current candle is greater than the previous candle
#that is what [1] denotes. Thus defining uptick. The same is then done for downticks.
Schaff.AssignValueColor(
if Schaff> OB then GlobalColor("maxxed") else
if Schaff< OS and Schaff< Schaff[1] then GlobalColor("zero") else
if Schaff< OS and Schaff> Schaff[1] then GlobalColor("begin") else
if Schaff> Schaff[1] then GlobalColor("rising")
else GlobalColor("bear"));
Schaff.SetLineWeight(3);
# ########################################################

plot OverBought = OB;
plot OverSold = OS;
plot UpArrow = if Schaff crosses above OverSold then OverSold else Double.NaN;
plot DownArrow = if Schaff crosses below OverBought then OverBought else Double.NaN;

DefineGlobalColor("OBcolor", CreateColor(171, 171, 225)) ;
DefineGlobalColor("OScolor", CreateColor(220, 220, 128)) ;
OverBought.SetDefaultColor(GlobalColor("OBcolor"));
OverSold.SetDefaultColor(GlobalColor("OScolor"));
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
UpArrow.SetDefaultColor(color.dark_green);
DownArrow.SetDefaultColor(color.dark_red);
# ########################################################
# The same logic that was used in coloring the plot can be used in labels
if Schaff> OB then "Schaff maxxed" else
if Schaff< OS and Schaff< Schaff[1] then "Schaff bottomed" else
if Schaff< OS and Schaff> Schaff[1] then "Schaff Trend BEGIN" else
if Schaff> Schaff[1] then "Schaff rising " +round(Schaff,2)
else "Schaff falling " +round(Schaff,2) ,
if Schaff> OB then GlobalColor("maxxed") else
if Schaff< OS and Schaff< Schaff[1] then GlobalColor("zero") else
if Schaff< OS and Schaff> Schaff[1] then GlobalColor("begin") else
if Schaff> Schaff[1] then GlobalColor("rising")
else GlobalColor("bear"));
AddCloud(if Schaff >= OB then Schaff else Double.NaN, OB,
GlobalColor("maxxed"), GlobalColor("maxxed"));
AddCloud(if Schaff <= OS then OS else Double.NaN, Schaff,
GlobalColor("zero"), GlobalColor("zero"));
# ########################################################``````
Watchlist #1:
Ruby:
``````# TOS Schaff Cycle
input OB = 80 ;
input OS = 20 ;
# ########################################################
Plot Schaff  = SchaffTrendCycle()."STC" ;
# ########################################################
AssignBackgroundColor(
if Schaff> OB then color.dark_green else
if Schaff< OS and Schaff>=Schaff[1] then CreateColor(50, 200, 255) else
if Schaff< OS then CreateColor (200, 125, 255) else
if Schaff> Schaff[1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
# ########################################################``````
Watchlist #2
Ruby:
``````# TOS Schaff Cycle
input OB = 80 ;
input OS = 20 ;
# ########################################################
plot Schaff  = SchaffTrendCycle()."STC" ;
# ########################################################
if Schaff> OB then "maxxed" else
if Schaff< OS and Schaff< Schaff[1] then "bottomed" else
if Schaff< OS and Schaff> Schaff[1] then "Trend BEGIN" else
if Schaff> Schaff[1] then "rising "
else "falling" );
# ########################################################
AssignBackgroundColor(
if Schaff> OB then color.dark_green else
if Schaff< OS and Schaff>=Schaff[1] then CreateColor(50, 200, 255) else
if Schaff< OS then CreateColor (200, 125, 255) else
if Schaff> Schaff[1] then CreateColor(0, 165, 0)
else CreateColor(225, 0, 0));
# ########################################################``````

Last edited:

#### zamanib

##### New member
I need help in coding custom quotes column for my watchlist/marketwatch
Indicator Standard deviation channel -- I want to create 3 custom column for my watchlist/marketwatch
I try to edit the indicator code and add label and color
I only want to see the lower channel to turn green - else grey once price close below or at standardDev 2 (lower line) I will do it 3 times just edit the setting from StandDev to 3 and 4

Here is original code-

input price = close;
input deviations = 2.0;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = stdevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);
}

plot UpperLine = regression + deviations * stdDeviation;
plot MiddleLine = regression;
plot LowerLine = regression - deviations * stdDeviation;

UpperLine.SetDefaultColor(GetColor(8));
MiddleLine.SetDefaultColor(GetColor(8));
LowerLine.SetDefaultColor(GetColor(8));

---------------------------------------------------------
I modify to for custom column --- NEED HELP TO CORRECT IT
THIS WHAT I HAVE DONE

input price = close;
input deviations = 1.0;
input fullRange = Yes;
input length = 21;

def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(price);
stdDeviation = stdevAll(price);
} else {
regression = InertiaAll(price, length);
stdDeviation = stdevAll(price, length);
}

def LowerLine = regression - deviations * stdDeviation;

plot LowerLineBelow = if close < LowerLine then 1 else 0;

AssignBackgroundColor (if LowerLineBelow >= 1 then color.DARK_GREEN else color.LIGHT_GRAY);

#### MerryDay

##### Moderator
Staff member
VIP
@zamanib FYI, it is not necessary to make multiple posts w/ the same question. All new posts rise to the top and are displayed regardless how old the thread or what sub-forum you post in. Multiple posts mean we have that many more posts to click on and less time to actually answer questions.

#### zamanib

##### New member
@zamanib FYI, it is not necessary to make multiple posts w/ the same question. All new posts rise to the top and are displayed regardless how old the thread or what sub-forum you post in. Multiple posts mean we have that many more posts to click on and less time to actually answer questions.
my bad -sorry -- I am new