Incorrect label being applied from code


Category:
0
0

I was able to update a column on a watchlist to add a label and background color based on the closing price being above or below the 34 ema. Here is the code I am using:

plot data = close ;

def MovAvgExponentia1 = ExpAverage(close, 34 );

AddLabel(yes,
if
close > MovAvgExponential
then “ 34ema + ”

else if close < MovAvgExponential

then “ 34ema – ”
else “ 34ema = ”);

AssignBackgroundColor(
if close > MovAvgExponential then Color.DARK_GREEN
else
if close < MovAvgExponential then Color.RED
else Color.BLACK);

This works perfectly most of the time. However there could be some occurrences when the 34ema and the closing price would be the same, hence I will just get a 34ema= against a black ground.  I use this on the top 250 optional stocks on volume and there were several which showed this “34ema= label” which was in error and should have been caught and assigned the red or green background. I’ve checked the close and am not sure why this is happening – if you have any suggestions I would very much appreciate it.

 

Thanks, David

 

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on September 2, 2018 9:31 am
52 views
0
Private answer

This has been moved to the “Watch Lists” topic. The title has been updated to remove redundant terms.

I tested this and the three stocks listed at the bottom of your screenshot do not show up as “34ema =” on mine.

CELG appears as “34ema+”

HD appears as “34ema+”

M appears as “34ema-“

The only suggestion I have is to check the aggregation period you have assigned to the watchlist column.

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on September 2, 2018 11:14 am