Alert for a MA retest after MA crossover occurs


0
0

Howdy Pete, Glad you are on the mend.

I’m trying to find out how to generate an alert if price gets within 2 points of a MA after a crossover occured.  With a limit of seven bars after the crossover.  After the seven bars, it would not trigger until reset.  And it would only trigger once per crossover.  For example the 5 ema crosses below the 20 sma, and price gets within 2 points of the 20 sma within 7 bars after the crossover confirms.  The moving averages would be selectable, and maybe the 2 point range adjustable also.  Using for futures trading.

Thank you for your time.

Drew

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on July 30, 2020 9:24 am
260 views
0
Private answer

This is a great question. But the full solution is beyond the scope of what I can provide for no charge in the Q&A forum. I only get 15 min for each solution and this one is already over that limit.

Great screenshot, but please don't be so stingy next time. Include the full view of the chart so we can see the selected ticker symbol, time frame, price range and date/time range. You have omitted nearly all of the most essential data points by forcing us to examine and elephant through a pinhole.

Here is the code and the screenshot below shows what it looks like on a chart after adapting it for a chart study. The code below is strictly designed for Study Alerts, Conditional Orders and scan. This is because you posted this in the "Alerts and Notifications" topic instead of the "Chart Studies" topic.

input withinBars = 7;
input percentThreshold = 0.1;
input maLengthOne = 5;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 20;
input maTypeTwo = AverageType.SIMPLE;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def crossAbove = maOne[1] < maTwo[1] and maOne > maTwo;
def crossBelow = maOne[1] > maTwo[1] and maOne < maTwo;
def hasCrossedAbove = maOne > maTwo and !crossAbove and Highest(crossAbove[1], withinBars - 1) > 0;
def hasCrossedBelow = maOne < maTwo and !crossBelow and Highest(crossBelow[1], withinBars - 1) > 0;
# use this to scan for current price within x percent of sma from above
plot scan = hasCrossedAbove and (close <= maTwo * (1 + percentThreshold * 0.01) or low <= maTwo * (1 + percentThreshold * 0.01));
# use this to scan for current price within x percent of sma from below
#plot scan = hasCrossedBelow and (close >= maTwo * (1 - percentThreshold * 0.01) or close >= maTwo * (1 - percentThreshold * 0.01));

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on July 30, 2020 11:11 am
0
Oh thanks Pete. I did fail to put his question in the correct topic category. Would you be willing to share the chart study version you created for your screenshot above? If not, I understand. Thanks for your help.
( at July 30, 2020 12:38 pm)
0
All you have to do is change the first "plot scan" to "plot scan1" then change the "#plot scan" to "plot scan2". This will activate both plots without creating an error. From the study settings you then adjust the style of each plot to whatever Boolean style you want. For the screenshot above I set both to "Values: Boolean". Then I sent scan1 to "Draw as: Up Arrow @ Low" and scan2 to "Draw as: Down Arrow @ High".
( at July 30, 2020 3:24 pm)