Alert when SMA within x percent of another SMA


0
0

I use TOS. To be specific, I would like to know how to ‘write’ being alerted when the 9 EMA is within a certain dollar amount of the 200 EMA. For example, writing a condition alert for EUR/USD I’d like to know when the 9 EMA is within .001 from the 200 EMA. The only actions it gives me is crosses above, below….greater than, less than…. equal to. Can’t seem to find how to write what I want specifically.

Sorry if I was redundant !!!! PLEASE HELP !!!

THANKS

RESOLVED
Marked as spam
Posted by (Questions: 5, Answers: 2)
Asked on June 15, 2020 6:21 pm
147 views
0
Private answer

I updated the title of your question so its easier for other viewers to find this post using the search function. I have also moved this out of the Chart Studies topic and into the Alerts and Notifications topic, since you included "Study Alerts" in your list of tags.

I have not taken the time to test this. But it should work. Be sure to let us know.

input withinPercent = 0.1;
input maLengthOne = 9;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 200;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def upperBound = maTwo * (1 + withinPercent * 0.01);
def lowerBound = maTwo * (1 - withinPercent * 0.01);
plot signal = maOne > lowerBound and maOne < upperBound;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 15, 2020 9:59 pm
0
Would their happen to be a simpler way to write this? or even a way to learn this type of code (on this website)? Im not sure whether or not im supposed to input the 'inputs' in the "defs". Any help would be greatly appreciated as I am only familiar with the basic condition wizard. Thanks
( at June 16, 2020 8:44 pm)
0
The code I provided simply gets copied into the Study Alert. Every thing is setup precisely according to your specifications. No changes are required. But if you do want to adjust thing those are in the first seven lines of code and those lines begin with the word "input".
( at June 16, 2020 8:50 pm)