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.

Trying to create 2 custom scans

Having trouble figuring out 2 scans, trading over and trading under an EMA, also using a specific chart type and color, any help appreciated...

Scan All: S&P 500 stocks
Chart Type: Heikin-Ashi
Stocks Trading Under 15 day EMA
Up Color: Green

Scan All: S&P 500 Stocks
Chart Type: Heikin-Ashi
Stocks Trading Over 15 day EMA
Up Color: Green

Thanks, Jimmy

Best Answer

  • markdmarkd mod
    edited September 2016 Answer ✓
    Your scans pass syntax and run so they are OK. But a more conventional form would be:

    [group is SP500]

    // close is above the 15 day ema
    and [close > EMA (15,close) ]

    Typically, it's best to put the stocks you are looking at first (things like group or market cap, country or exchange, average volume, max and/or min price, etc.). It's clearer and makes the scan run a little faster because the scan engine has to look at only those stocks, not the whole 10,000 or so.

    In your scan, the [Close] statement passes syntax, but it doesn't do anything, so you can take it out.

    It doesn't matter whether "close" or "ema" comes first with ">" or "<" comparison operators, as it does with "x". It seems more intuitive to put "close" first, but that's your call.

    It's a good idea to put in a comment above (or beside) every line, even if it's obvious, just to get in the habit. As you write more complex scans, it will a.) remind you what you wanted to do when you come back to it later and b.) make it easier to spot errors, as in, hey, that line doesn't do what the comment says it does...

    Now to tweaks:

    You may want to specify whether the ema is rising or falling. Take some period shorter than the ema and compare to today's ema.

    // ema is rising
    and [ema(15, close) > 5 days ago ema(15,close)]

    // ema is falling
    and [ema(15,close) < 5 days ago ema(15,close)]

    I just chose 5 days as an example. You could experiment with longer or shorter periods.

    Also, you might want to add something about a longer trend. Do you want to be above or below a rising or falling intermediate trend, like 50 or 63? Conventional wisdom is, trades work better in the direction of the next larger time frame's trend.

    For rising or falling longer trend, just substitute longer parameters for the 5 and 15 above.

    For above and below the longer trend, compare the 15 ema to the 63 (ema or sma) with > and <.

    If you get stuck, post what you have.


  • I assume you mean a 15 day MA of Heiken Ashi closes. There doesn't seem to be an option for HA-Close in the drop downs in the Scan Builder section of the Advanced Scan workbench. Unfortunately, the sma() and ema() functions cannot average a calculation, so you can't build a scan to average the HA-Close yourself. You could try an ema of the standard close. I would guess that most of the time the results will be the same. Crossovers might differ.

    You can build scans by selecting terms from the drop down windows in the Scan Builder section, then editing them as needed. If you get stuck on that, post what you have.

    It appears that if you choose the Heiken Ashi chart type, the MAs on the chart will be averages of Heiken Ashi closes.

    You can choose volume colors on the chart (if that's what you mean) in the Chart Attributes section of the Chart Workbench, under "Up Volume".
  • Thanks Mark, can still use the codes for scanning above and below 15 day MA. I did figure out how to run general scans.
  • After looking over some of the other posts (yours too) and materials I came up with the following:

    and [EMA (15,close) > close]
    and [group is SP500]

    and [EMA (15,close) < close]
    and [group is SP500]

    Can you recommend any more tweaking as I am looking for the best results?

    Thanks, Jimmy
  • Great, thanks
Sign In or Register to comment.