Price above 4 EMA and now at 20 EMA


Category:
0
0

Hi Pete, 

I’ve bee ntrying to create a scan for this condition but either I’m not getting results or getting results are way off in TOS. Much better luck in TradeStation. I know I’m doing something wrong using the condition wizard. This might need some code, wondering if you can help with a scan that can get results close to the one the attached image. 

– In the last 10 bars, the close is above 4, 9, 20 EMA for at least 6 bars and in the most recent bar, the price is within +2% and -2% of 20 EMA

Attachments:
Marked as spam
Posted by (Questions: 6, Answers: 10)
Asked on June 3, 2020 10:00 pm
109 views
0
Private answer

The following code performs exactly what you have requested but the results are not going to match the pattern you see on the chart. There is quite a bit more detail there then you described. But this is the code to do exactly what you specified:

input consecutiveBars = 6;
input percentThreshold = 2.0;
input maLengthOne = 4;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 9;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
input maLengthThree = 20;
input maTypeThree = AverageType.EXPONENTIAL;
input maPriceThree = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def maThree = MovingAverage(maTypeThree, maPriceThree, maLengthThree);
def stackedAverages = maOne > maTwo and maTwo > maThree;
def closeAbove = stackedAverages and close > maOne;
def countBarsAbove = Sum(closeAbove, consecutiveBars);
def withinPercent = close < maThree * (1 + percentThreshold * 0.01) and close > maThree * (1 - percentThreshold * 0.01);
plot scan = countBarsAbove >= consecutiveBars and withinPercent;

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on June 4, 2020 8:03 am