Ok, so with this clarification of terms we can now proceed. To define a condition in which the current bar of the 9 ema is greater than the previous bar:
def ema9 = ExpAverage(close, 9);
def rising9EMA = ema9 > ema9[1];
From the original question we also have a condition that the price should be at or below the 6 ema. I forgot to ask if “price” should be the close of the bar or the high. And we don’t know if the intention is that prices should have been below the 6 ema of a number of bars, or just the current bar. So we’ll code this exactly as it was specified leaning towards the most conservative structure:
def ema6 = ExpAverage(close, 6);
def highBelow6EMA = high < ema6;
And we also have a new condition added. The stock should be down 20% on the month.
def highestMonthlyHigh = Highest(high, 21);#roughly 21 trading days in a month
def percentDownFromMonthlyHigh = 100 * (high / highestMonthlyHigh - 1);
def downTwentyPercentOrMore = percentDownFromMonthlyHigh <= -20.0;
Ok, the final step is to assemble our three TRUE/FALSE conditions and assign them to a “plot scan” statement:
plot scan = rising9EMA and highBelow6EMA and downTwentyPercentOrMore;
I just ran this scan and all that came up was a half dozen penny stocks. So I’m guessing these conditions are extremely rare, or there may be something about this structure that makes it very different to appear in the price action.
Breaking down piece by piece, here are the result for the individual conditions:
Down twenty percent on the month: 571 stocks
Rising 9 ema: 1,327 stocks
High below the 6 ema: 635
Rising 9 ema AND high below the 6 ema: 15 stocks
So I would suggest in order to have a rising 9 ema you are going to be hard pressed to find price action that is also below the 6 ema. If we modify the condition for high less than 6 ema to close less than 6 ema, the count for that last combo rises to 165 stocks. So you probably want to experiment with this and test out some alternatives.
Best of luck to you. Please be sure to up-vote any answers that best solve your question.
Is this correct?
close is less than or equal to MovAvgExponential(”length” = 6) and MovAvgExponential() is greater than MovAvgExponential() within 2 bars
Well, let’s try to get a more precise definition of ”when the 9 ema is increasing”. Does that mean if 9 ema is greater than the previous bar? Or does the 9 ema have to be higher over a specific number of bars? Or does the 9 ema have to have a specific slope over a given bars. There is lot left open for interpretation there.