Price percent from EMA with background color


Category:
0
0

Hi Pete,

Can this code show background color on the watchlist when the following parameters are met? This was taken from this question: https://www.hahn-tech.com/ans/price-from-ema/

I want to assign background color green when the watchlist filter is showing positive values between a value of 0.0 to 0.35

To give you a specific example, i implemented this code and there’s multiple stocks showing different values.

For example:
-TMUS= 0.06
– CHK= – 0.12
– DINO= -0.03
-LDOS= 0.31

Based on this result, the watchlist filter background should be green for LDOS and TMUS.

input maLengthOne = 21;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot percentFrom = 10 * (close / maOne – 1);

 

Marked as spam
Posted by (Questions: 1, Answers: 2)
Asked on November 29, 2022 6:45 pm
23 views
0
Private answer

Since you logged into the forum using your Twitter account we don't have a valid email address for you. This means you are not getting email notifications when you post new content on our website. Don't post your email address here or you will get spammed. Contact me directly and we can get that updated.

Here is the solution you requested:

input minimumValue = 0.0;
input maximumValue = 0.35;
input maLengthOne = 21;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot percentFrom = 10 * (close / maOne – 1);
percentFrom.AssignValueColor(if percentFrom > minimumValue and percentFrom < maximumValue then Color.BLACK else Color.CURRENT); AssignBackgroundColor(if percentFrom > minimumValue and percentFrom < maximumValue then Color.GREEN else Color.CURRENT);

I included user inputs for min/max values so the rest of our viewers can use this for their own preferences.

And while I was working this I realized the percentFrom variable is not computed correctly. That line of code should be as follows:

plot percentFrom = 100 * (close / maOne – 1);

But changing this would also require you to update the min/max value inputs to account for the adjusted value. I am providing this correction for the benefit of those who come across this post at a later date. And I will updated the solution in the original post as well.

Marked as spam
Posted by (Questions: 37, Answers: 3958)
Answered on November 29, 2022 7:48 pm
Perfect Pete, this works very well. Thanks for the help!!
( at November 29, 2022 7:58 pm)