New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.

Writing a Scan for a backtest of the 9 EMA

I've written the below scan. I'm trying to write a scan that shows stocks that have broken out but are retesting their 9 ema and within 10% of their 1 year highs with volume over 500,000



[type = stock]
and
[exchange = nasdaq]
and
[close> 10]
and [close > ema (9,close)]
and
[close < .95 *max (365,high)]
and
[close > .85 * max(365, high)]
AND [RSI(14) > 60]
and [volume > 500000]

Comments

  • You pretty much have it.

    [type = stock]
    and [exchange = nasdaq]
    and [close> 10]
    and [volume > 500000]
    and [RSI(14) > 60]
    and [close > ema (9,close)]
    and [close > .90 * max(365, high)]

    I re-arranged things, but it doesn't affect the logic. The last line addresses the 10 per cent condition. You don't really need a condition to test for returning to the ema 9, but if you wanted one it might be something like

    and [close < max(3,close)]

    You could play with the "3" parameter.
  • Thank you Mark

    Can you please elaborate

    What does [close < max(3,close)] represent?

    How would I use my above scan to say stocks that are within 2% of their 9 ema?

    Thanks
  • is it something like this? [EMA(9,close) > EMA(9,close)*1.02]?
  • For your first question:

    [close < max(3,close)]

    This means today's close is less than the highest of the last 3 closes. It might be the second highest or the third highest (lowest) of the the last three, but it can't be the highest.

    Combined with the condition that the close is above the ema 9, it would capture a down close(s) in the most recent three days above the ema9, which could be a return move to the ema 9.

    For your second question, you want to compare the current close to the ema, not the ema to itself.

    So, if you want to get a close above the ema but within 2 % of it, it would be:

    and [close > ema(9, close)]
    and [close < ema(9,close) * 1.02] // note - close is LESS than, not greater

    If it's ok for the close to be above OR below the ema, but still within 2 %, then:

    and

    [

    [close < ema(9,close) * 1.02]

    or

    [close > ema(9,close) * .98]

    ]



  • Thanks a bunch Mark. Have a great day
Sign In or Register to comment.