# Need help with Linear Regression Reversal Watchlist Column Code

#### ttsdmagic

##### Member
Plus
Hello. I keep getting errors on this code. Please suggest an answer!

The goal for this watchlist column is to change background color when Linear Reg Reversal is equal to 1 AND when CCI (5) Crosses Zero. Agg period is 2 days.

Code:
``````def agg = AggregationPeriod.TWO_DAYS;
def lrr = reference LinearRegrReversal()."LRR"(period = agg);
def cci = reference CCI("length" = 5)."CCI"(period = agg);
def zeroLine = reference CCI("length" = 5)."ZeroLine"(period = agg);

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
scan.AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);``````

Solution
Hello. I keep getting errors on this code. Please suggest an answer!

The goal for this watchlist column is to change background color when Linear Reg Reversal is equal to 1 AND when CCI (5) Crosses Zero. Agg period is 2 days.

Code:
``````def agg = AggregationPeriod.TWO_DAYS;
def lrr = reference LinearRegrReversal()."LRR"(period = agg);
def cci = reference CCI("length" = 5)."CCI"(period = agg);
def zeroLine = reference CCI("length" = 5)."ZeroLine"(period = agg);

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
scan.AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);``````

there are several things wrong here...
Hello. I keep getting errors on this code. Please suggest an answer!

The goal for this watchlist column is to change background color when Linear Reg Reversal is equal to 1 AND when CCI (5) Crosses Zero. Agg period is 2 days.

Code:
``````def agg = AggregationPeriod.TWO_DAYS;
def lrr = reference LinearRegrReversal()."LRR"(period = agg);
def cci = reference CCI("length" = 5)."CCI"(period = agg);
def zeroLine = reference CCI("length" = 5)."ZeroLine"(period = agg);

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
scan.AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);``````

there are several things wrong here,

can't use 2nd agg in a scan or watch list

can't apply 2nd agg to a function. has to be used with a price constant,
open, high, low, close

can't append input parameters with a 2nd set of ( ) at end of a function. all valid input parameters need to be within the main set of ( ).

AssignBackgroundColor() is its own function. it is not used as a plotting parameter.

no need to read 0 from another study.
zeroline= ???
just use 0

looks like you want all your variables to have data from '2 days' time,...
so just set the column time to be 2 days, and don't try to read 2nd agg data in the study.

---------------------

watch list column study , set to 2 day

zlinregcci
http://tos.mx/kzNjzIk

Code:
``````def lrr = LinearRegrReversal()."LRR";
def cci = CCI("length" = 5)."CCI";
def zeroLine = 0;

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);``````

-----------------------

lower study , for testing
set to 2 day

# col_lin_regress_mtf_lower_0

declare lower;

def lrr = LinearRegrReversal()."LRR";
def cci = CCI("length" = 5)."CCI";
def zeroLine = 0;

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);
#
[/code]

there are several things wrong here,

can't use 2nd agg in a scan or watch list

can't apply 2nd agg to a function. has to be used with a price constant,
open, high, low, close

can't append input parameters with a 2nd set of ( ) at end of a function. all valid input parameters need to be within the main set of ( ).

AssignBackgroundColor() is its own function. it is not used as a plotting parameter.

no need to read 0 from another study.
zeroline= ???
just use 0

looks like you want all your variables to have data from '2 days' time,...
so just set the column time to be 2 days, and don't try to read 2nd agg data in the study.

---------------------

watch list column study , set to 2 day

zlinregcci
http://tos.mx/kzNjzIk

Code:
``````def lrr = LinearRegrReversal()."LRR";
def cci = CCI("length" = 5)."CCI";
def zeroLine = 0;

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);``````

-----------------------

lower study , for testing
set to 2 day

# col_lin_regress_mtf_lower_0

declare lower;

def lrr = LinearRegrReversal()."LRR";
def cci = CCI("length" = 5)."CCI";
def zeroLine = 0;

plot scan = if lrr == 1 and cci crosses above zeroLine then 1 else if lrr == 1 and cci crosses below zeroLine then -1 else 0;
AssignBackgroundColor(if scan == 1 then Color.WHITE else if scan == -1 then Color.RED else Color.GRAY);
#
[/code]

Thanks so much for your reply. The code works as expected since you corrected all those errors. Much appreciated!

87k+ Posts
353 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?