Color sma based on highest and lowest value of the day


Category:
0
0

So here is the script I’m using on TOS

plot sma1 = Average(close, 2);

sma1.AssignValueColor(if sma1 > sma1[1] then Color.liME else Color.magENTA);

It is a very simple script that colors the 2sma in lime when it’s moving up and magenta when it’s moving down

but i want to expand this idea

and have that moving average colored blue only if the lastest value of that sma is higher than the highest value of that sma on the day so far………………and also for the down side, to have that moving average colored RED if the lastest value of that sma is lower than the lowest value of that sma on the day so far

do you know how to do that? thanks

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on October 31, 2018 12:28 pm
81 views
0
Private answer

I had to change the title of your question to one that actually describes the context of your question.

What you have requested here creates a third condition (color) which you did not mention. Allow me to explain. If sma1 is higher than previous AND sma1 is higher than its highest value for the day, color blue. What if sma1 is higher than previous but NOT higher than its highest value? When you include the red color condition, that right there is your third condition.

So I selected the color gray for your third condition. While sma1 is neither higher than its daily highest, nor lower then it daily lowest, it will be colored gray. Attached screenshot shows the result.

Here is the code:

plot sma1 = Average(close, 2);
def newDay = GetDay() <> GetDay()[1];
rec dailyHighest = if newDay then sma1 else if sma1 > dailyHighest[1] then sma1 else dailyHighest[1];
rec dailyLowest = if newDay then sma1 else if sma1 < dailyLowest[1] then sma1 else dailyLowest[1]; def colorBlue = sma1 > sma1[1] and sma1 > dailyHighest[1];
def colorRed = sma1 < sma1[1] and sma1 < dailyLowest[1];
sma1.AssignValueColor(if colorBlue then Color.BLUE else if colorRed then Color.RED else Color.GRAY);

 

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4089)
Answered on November 1, 2018 8:20 am