Alert when Signal Line changes color


0
0

I deleted my original post to try and clean it up a bit (For some reason, editing does not work)

I did see a similar post but wasn’t able to make it work with my code.

My signal line can be “Green”, “Red” or “Gray”

What I was hoping to achieve is to be alerted when the signal line changes from “Gray” to “Green” or

from “Gray” to “Red”

#—————————————————————————

Thank you for your time

 

Attachments:
Marked as spam
Posted by (Questions: 11, Answers: 16)
Asked on August 3, 2020 4:53 am
130 views
0
input expLength17 = 17; input expType17 = AverageType.EXPONENTIAL; input expPrice17 = close; def exp17 = MovingAverage(exptype17, expprice17, explength17); def average = exp17; plot MA = average; MA.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS); MA.SetLineWeight(2); MA.DefineColor("Up", createColor(0,82,3)); MA.DefineColor("Down",createColor(110,15,10)); MA.DefineColor("Flat", color.GRAY); def DayGreen = long and daylong and majorTrendUp60 and majorTrendUp100; def DayRed = short and dayshort and majorTrendDn60 and majorTrendDn100; ma.AssignvalueColor(if DayGreen then MA.Color("Up")else if DayRed then MA.Color("Down") else MA.Color("Flat"));
( at August 3, 2020 4:55 am)
0
Thank you once again for all your help I'll remember attaching a file in the future :)
( at August 3, 2020 11:28 am)
0
Private answer

When you have code of less than 2 dozen lines you should included it within the body of the question and not as a separate comment. If you reach the character limit in the body of the question and the code does not fit, they you will save the code to a plain text file and include it as an attachment just like you did with the screenshot.

All of the logic required for your alert is here:

ma.AssignvalueColor(if DayGreen then MA.Color("Up")else if DayRed then MA.Color("Down") else MA.Color("Flat"));

That is the statement that changes the color so everything you need to add an alert to this chart study is right there in that line of code. Here is an alert that will trigger on the first bar changing from gray to green:

Alert(!DayGreen[1] and !DayRed[1] and DayGreen, "Gray to Green", Alert.BAR, Sound.RING);

Alerts are explained in the following link:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert

The first parameter of the Alert() function contains the true/false condition that triggers the alert. The alert I created checks that the previous bar is not green and is not red while at the same time the current bar is green.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on August 3, 2020 8:49 am