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

#https://usethinkscript.com/threads/...ression-reversal-watchlist-column-code.14742/

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]

DQh3joa.jpg
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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

#https://usethinkscript.com/threads/...ression-reversal-watchlist-column-code.14742/

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]

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
469 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top