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
29 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: 3976)
Answered on January 4, 2023 11:22 am
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)
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)
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)
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)
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)
Ok..will work on it! Thank you again, ToS Thinkscript GOAT!
( at March 18, 2023 2:36 pm)