CCI Watchlist Column for ThinkorSwim

BenTen

Administrative
Staff
VIP
Here is the CCI (Commodity Channel Index) watchlist column for ThinkorSwim.
  • Green = CCI crosses above the oversold level
  • Red = CCI crosses below the overbought level
  • Blue = CCI crosses the Zero line

ygaW022.png


thinkScript Code

Code:
#
# 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;
def ZeroLine = 0;

def condition1 = CCI crosses above over_sold;
def condition2 = CCI crosses below over_bought;
def condition3 = CCI crosses Zeroline;

AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);
 

hoojsn

New member
Thanks, Ben. Actually I am waiting for it for quite a while. How do you make the colour in CCI column?
 

BenTen

Administrative
Staff
VIP
@hoojsn What do you mean? Are you asking about the code that specifies the color background?

Here it is:

Code:
AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);
 

Stockleed

New member
@BenTen

Thank you for the code. Am I by chance doing something wrong I cannot get the background colors to show up for each condition using the code you provided above.

Any help would be greatly appreciated

cbc2f726732c348aed88503447fb43aa-full.png
 

Stockleed

New member
Thanks for your reply @Pensar here is the code I have entered


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;
def ZeroLine = 0;

def condition1 = CCI crosses above over_sold;
def condition2 = CCI crosses below over_bought;
def condition3 = CCI crosses Zeroline;

AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);



Am I missing something?
 

Pensar

Well-known member
VIP
Thanks for your reply @Pensar here is the code I have entered


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;
def ZeroLine = 0;

def condition1 = CCI crosses above over_sold;
def condition2 = CCI crosses below over_bought;
def condition3 = CCI crosses Zeroline;

AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);



Am I missing something?
@Stockleed As long as its the same code as in the 1st post of this thread, it should work. I loaded it into a watchlist column and the colors display without any issue.
 

Similar threads

Top