Include moving average value in crossover alert


Category:
0
0

In ToS, I have chart studies that have 5,20,50,200 days Moving averages (EMA) with alerts and I have scanner alert that I get notification for 5days crossing over 20days as example!

Is there a way I can get the actual number where these crossovers or crossunders are happening from the chart studies into my alert output or send it to a file or save this data somewhere or be able to get to it as alerts are happening!?

Thank you in advance

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 2, 2023 8:18 pm
111 views
0
Private answer

After trading a couple of emails with the author of this question I have some additional details. The value to capture is the value of the second moving average at the point the crossover occurs. The solution below is a chart study with alerts for both crossing events. The chart study plots the moving averages as well as the value of the most recent crossing event. The value of the second moving average is included within the text of the alert message, which is shown in the screenshot below.

input maLengthOne = 5;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 20;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
plot maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
plot maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def crossAbove = maOne[1] < maTwo[1] and maOne > maTwo;
def crossBelow = maOne[1] > maTwo[1] and maOne < maTwo;
rec trackCrossingLevel = if crossAbove or crossBelow then maTwo else trackCrossingLevel[1];
plot crossingLevels = trackCrossingLevel;
Alert(crossAbove, Concat("Cross Above Level: ", trackCrossingLevel), Alert.BAR, Sound.RING);
Alert(crossBelow, Concat("Cross Below Level: ", trackCrossingLevel), Alert.BAR, Sound.RING);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on January 4, 2023 11:22 am
0
I see it doing both cross over and cross below values in alert. I should be able to also get this working on scanner. Time to get to work! Thank you very much. rec trackCrossingLevel = if crossAbove or crossBelow then maTwo else trackCrossingLevel[1];
( at January 5, 2023 8:01 pm)
0
Is there anyway I can have the value of the maOne and maTwo every few minutes dumped somewhere or in an alert and not necessary an alert event of crossover!?
( at March 11, 2023 5:51 pm)
0
The only option is do exactly what we have provided here. The alert functionality is the only mechanism which can capture the value and report it. The alert messages cannot be exported in any way, shape or form. FYI, within these limits, it is possible to create a script which will trigger an alert at the close of every bar on the chart and yes, it can include the values of various plot elements as we have demonstrated in this solution.
( at March 11, 2023 6:01 pm)
0
I think a script to trigger at end of very bar will work for me to show the maOne and maTwo value or maybe every other bar or every few bars! If you can show me a script example then I can work on it and play with it and learn more. If you like we can separate that question from this original question in case it can help others looking for this. or if easier..just show me how to set alert syntax for end of bar or multiple bars and I can work on it. Thank you Dr. Hahn!
( at March 11, 2023 6:17 pm)
0
It's very simple to modify the existing solution to alert once for every bar on the chart. Change "crossAbove" to "yes". But you would only need to do that for one of the Alert() statements, then delete the other one. And you can update the text portion of the alert to whatever you need.
( at March 11, 2023 6:44 pm)
0
Ok..will work on it! Thank you again, ToS Thinkscript GOAT!
( at March 18, 2023 2:36 pm)
0
Ok, I got this to work in chart study and I see the alert in message center showing Cross Below Level: number or Cross Above level:number. Now, Can I get same alert with the level number in a ToS scanner alert, so I get it my email/txt?
( at April 2, 2023 10:49 am)
0
That part would not be possible in the current version of Thinkorswim. email/SMS notifications generated from custom scans will include the name of the saved scan and the ticker symbol. Nothing more. If you want to learn how to build these types of "dynamic alerts" you can find that demonstrated in the following video: https://www.hahn-tech.com/thinkorswim-scans-beginner-to-advanced/
( at April 2, 2023 11:24 am)
0
I see., Yea, I already have dynamic alerts from scanner studies , but  was looking for actual alert data from study in the email alerts not just tickers was added or removed! I think I will have to continue finishing doing own moving averages calculation/alert  in python!
( at April 2, 2023 11:51 am)