indicator calculation in scanner watchlist  [SOLVED]

Questions about MultiCharts and user contributed studies.
ppc
Posts: 41
Joined: 04 Nov 2014
Has thanked: 4 times

indicator calculation in scanner watchlist

Postby ppc » 04 Jun 2016

Hi, I apply the following indicator in market scanner:
if close > highest(high[1],20) and Average(close,5)>Average(close,20) then plot1("AAA");
plot2(Average(close,5),"5",yellow);
plot3(Average(close,20),"20",cyan);
plot4(Average(close,5)-Average(close,20),"diff",cyan);
It plot "AAA" if fullfil 2 conditions but I find that it even plot "AAA" when 2nd condition [ (Average(close,5) > Average(close,20) ]is not fullfiled. I have attached a output image which show some results like that. Thanks for your opinion.
Attachments
scanner image 1.png
(42.45 KiB) Downloaded 923 times

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: indicator calculation in scanner watchlist

Postby TJ » 04 Jun 2016

Hi, I apply the following indicator in market scanner:
if close > highest(high[1],20) and Average(close,5)>Average(close,20) then plot1("AAA");
plot2(Average(close,5),"5",yellow);
plot3(Average(close,20),"20",cyan);
plot4(Average(close,5)-Average(close,20),"diff",cyan);
It plot "AAA" if fullfil 2 conditions but I find that it even plot "AAA" when 2nd condition [ (Average(close,5) > Average(close,20) ]is not fullfiled. I have attached a output image which show some results like that. Thanks for your opinion.

Before you jump head first into the scanner,
have you tried to plot the variables on the chart to verified that the logics are valid?

Take the example of this line:

Code: Select all

if close > highest(high[1],20) and Average(close,5)>Average(close,20) then plot1("AAA");
You should break it down and plot it on the chart first:

Code: Select all


A5 = Average(close,5);
A20 = Average(close,20);

plot10( highest(high[1],20), "highest(high[1],20)");
if A5 > A20 then plot20( c, "AAA"); // <--- plot as a large dot


User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: indicator calculation in scanner watchlist

Postby TJ » 04 Jun 2016

see post 1 & 2
[FAQ] How to Post Codes (... so that people can read)
viewtopic.php?f=16&t=11713

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: indicator calculation in scanner watchlist

Postby TJ » 04 Jun 2016

Look up the keyword:

NoPlot

ppc
Posts: 41
Joined: 04 Nov 2014
Has thanked: 4 times

Re: indicator calculation in scanner watchlist

Postby ppc » 05 Jun 2016

Hi TJ,

I cannot follow your idea. Could you tell more about your idea? Thanks.

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: indicator calculation in scanner watchlist

Postby TJ » 05 Jun 2016

Hi TJ,

I cannot follow your idea. Could you tell more about your idea? Thanks.

Have you done all three posts?

Which part do you not understand?

ppc
Posts: 41
Joined: 04 Nov 2014
Has thanked: 4 times

Re: indicator calculation in scanner watchlist

Postby ppc » 05 Jun 2016

Hi TJ,

You suggest to Look up the keyword: NoPlot in your post link but cannot find it . I don't understand how to relate NoPlot to my current issues. I have read the post which provides guideline how to make a post and make code reading easier.

I post the code using the guideline for easy reading

Code: Select all

if close > highest(high[1],20) and Average(close,5)>Average(close,20) then plot1("AAA");
plot2(Average(close,5),"5",yellow);
plot3(Average(close,20),"20",cyan);
plot4(Average(close,5)-Average(close,20),"diff",cyan);
My intention is to plot "AAA" if 2 conditions are true
condition1 :close > highest(high[1],20)
condition2: Average(close,5)>Average(close,20)
but it plots when only 1 condition is true. I have no idea what's wrong with code and appreciate if anyone can give me suggestion. Thanks.

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1503 times
Contact:

Re: indicator calculation in scanner watchlist

Postby JoshM » 06 Jun 2016

My intention is to plot "AAA" if 2 conditions are true
condition1 :close > highest(high[1],20)
condition2: Average(close,5)>Average(close,20)
but it plots when only 1 condition is true. I have no idea what's wrong with code and appreciate if anyone can give me suggestion. Thanks.
I would try to turn on/off the "AAA" plot based on the two conditions like this:

Code: Select all

if (close > highest(high[1],20)) and (Average(close,5)>Average(close,20)) then begin
Plot1("AAA");
end else
NoPlot(1);

plot2(Average(close,5),"5",yellow);
plot3(Average(close,20),"20",cyan);
plot4(Average(close,5)-Average(close,20),"diff",cyan);
This NoPlot() keyword can remove a plot from the current bar when its conditions are no longer true (according to the wiki).

User avatar
TJ
Posts: 7235
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

Re: indicator calculation in scanner watchlist

Postby TJ » 06 Jun 2016

Hi TJ,

You suggest to Look up the keyword: NoPlot in your post link but cannot find it .
When learning a new keyword,
you should look up the definition and read the usage example in the wiki PowerLanguage Keyword Reference

My intention is to plot "AAA" if 2 conditions are true
::
You need to complete your thought....
My intention is to plot "AAA" if 2 conditions are true
but otherwise noplot
Computers are dumb, but very obedient. You have to tell them precisely what needs to be done.

ppc
Posts: 41
Joined: 04 Nov 2014
Has thanked: 4 times

Re: indicator calculation in scanner watchlist  [SOLVED]

Postby ppc » 06 Jun 2016

Thanks JoshM and TJ's help to resolve the issues


Return to “MultiCharts”