CCI indicator chart label for TOS

H

haha54

Member
Hello,

I would like to add a CCI label to my chart that shows the value of the "CCI". I did a search on the site and could not find it posted.

Any help would be appreciated.
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
Here is the code:

Code:
# Default CCI with Label
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

declare lower;

input length = 14;
input over_sold = -100;
input over_bought = 100;
input showBreakoutSignals = no;

def price = close + low + high;
def linDev = lindev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;
plot UpSignal = if CCI crosses above ZeroLine then ZeroLine else Double.Nan;
plot DownSignal = if CCI crosses below ZeroLine then ZeroLine else Double.Nan;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

CCI.setDefaultColor(GetColor(9));
OverBought.setDefaultColor(GetColor(5));
ZeroLine.setDefaultColor(GetColor(5));
OverSold.setDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

AddLabel(yes, Concat("CCI = ", CCI), color.red);
 
H

haha54

Member
Thanks, Ben that is what I was looking for. Just one more question. Would it be possible to have the CCI label turn Green if the CCI is +100 or higher? Yellow if the CCI is between 0-99 and Red if the CCI is below -100?
Thanks again!
 

Similar threads

Top