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.

Price near MA, Slope parameter, scan for a cross in a time range, and types

I have questions about four things, but they're all related to a scan I'm trying to build. Also, this is the second time I've typed this, but I'm pretty sure I inadvertently deleted the page before I could post it. So if it appears as well, my apologies in advance. :-)

I want to tell when price is above but descending to near a particular MA. Is it possible to phrase an argument to tell when price is a certain % or amount from the average? I already have the argument for price is above an MA.

To tell price is descending, I know I can do a few days < more days back. Does the Slope parameter also get used for that? Can Slope apply to MAs as well? Can Slope work on Volume?

If I want to set a scan range to tell that an MA cross happened within a certain amount of time prior, including "at least this far back"? (In case I want to know that the cross happened, say, in the last two months, but before two weeks ago)?

Didn't I see a page that lists what the possibilities for scan parameters are, such as what can be if using "type," what are the types that can be scanned for? Sometimes I want to specify ETFs, for instance.

Best Answers

  • markdmarkd mod
    edited February 2016 Answer ✓
    Hi @snyderk5 , Upper MA Envelope is an overlay you can put on your chart style, and you can scan for it, too. It's a selection available under the "Technical Indicators" drop down on the advanced scan page. You can read about how it works in Chart School

    https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_average_envelopes

    So for your set up it would something like:

    and [close < Upper MA Env(20,5)]
    and [close > ema(20, close)]

    The 20 specifies the length of the ema (ema appears to the default ma for scanning), the 5 is the width of the envelope around the ema, in per cents - so 5 is 5 per cent above. But the code you have should work, too.

    The number in the "Starting x days before" runs the scan as of the date you choose. So if you choose December 9, 2015, it runs the scan as if the data ended on the close of that day. In other words, December 9 becomes "today". It does not look for your condition in the range between the current date and the past date. Scans run as of one particular moment in time.

    (Note: the conditions themselves can cover a range of dates - like "and [min(21, close) > 5]" says there was no price below five in the last 21 days, including today as day 21. If you choose to run the scan as of December 9, it looks at the data for the 21 days ending December 9.)

    So one way to get a crossover in the past would be to write your scan for a crossover today (short ema x long ema) and run your scan some number of days in the past, then the next day, then the next day, etc. That keeps the scan simple, but the trade off is you have to run the scan a lot. Then you would run the ema proximity test (within 5 per cent above the long ema) on the results (after you save the results to a list, you can scan them - add the line [favorites list is ...] ), or just eyeball them for what you like, depending on how many results you get.

    If that's too time consuming, then you can spend time making the scan more complex so you don't have to run it as often. To find likely crossovers in some range of dates in the past, again, you would test for a change in their positions with respect to each other - so, 60 days ago, the short ema was below (less than) the long ema,

    and [60 days ago ema(13) < 60 days ago ema(34)]

    but 20 days ago the short ema was above the long ema,

    and [20 days ago ema(13) > 20 days ago ema(34)]

    and today the close is within 5 per cent (above) the long ema. Then you would run that scan as of today (starting 0 days ago). This is more likely to pick up junk I think, because a lot can happen in the interval, but try the two methods and see which is more efficient.

    I don't think there is a line limit, but there is a character limit of 8000. The advanced scan window has a counter at the upper right corner that keeps track for you.
  • markdmarkd mod
    edited February 2016 Answer ✓
    Just to clarify:

    This gets a crossover that occurred as of the end of the current week (Feb 26)

    and [weekly ema(13,weekly close) x weekly ema(50, weekly close)]

    So this scan looks at the most recent bar on the weekly chart (which, on Saturday Feb 27 you might think of as "last week", but really, it's "this week").


    This gets a crossover that occurred as of the end of the 1 week ago (last week) (Feb 19)

    and [1 week ago weekly ema(13,weekly close) x 1 week ago weekly ema(50, weekly close)]

    This ALSO gets a crossover that occurred as of the end of the 1 week ago (last week) (Feb 19)

    and [last week's weekly ema(13,weekly close) x last week's weekly ema(50, weekly close)]

    So, "1 week ago" and "last week's" are equivalent.

    Both of these scans look at the second most recent bar on the weekly chart.

    If one week ago was Feb 19, the two weeks ago was Feb 12, which is the third bar back on the weekly chart.

    The crossover on NEM on the weekly chart actually happened on the 1 week ago bar (bar 2 counting backwards). You can see this if you put up the weekly chart on the chart work bench and use select start/end date mode to move the chart bar by bar. Two weeks ago (Feb 12) it was just below, one week ago it was just above.

    Another point:

    The weekly scan only looks at weekly data. It doesn't know anything about daily data, So if the weekly scan indicates a 13/50 crossover, it means ONLY that. It doesn't say anything definitive about the daily data, because the daily data and the weekly data are different.

    Although the 13/50 scan and 50/200 scan cover roughly the same calendar period, the weekly data samples only one value each week, whereas the 50/200 samples 5 values each week. So the results of the calculations are going to be different. Over time, the resulting charts will look fairly similar - the lines for each average will be moving mostly in the same directions on both charts, but timing of specific, particular events will not perfectly coincide all the time.

    In the case of NEM, the weekly 13/50 (weekly ema) crossover was on the second bar back. On the daily chart, the 50/200 (daily ema) crossover was Feb 12, which on the weekly would have been on the third bar back. So in this instance, at least, the weekly was "late".

    A word about time frames: The larger the time frame you go with, the less precise your entries are going to be. You will tend to be late on entries and late on exits. "Late" means you will not get the first dollar on the trade or the last dollar. Larger time frame signals occur less frequently, but there is usually less whipsawing. But your stops have to be wider and so your positions should probably be smaller to account for that.

Answers

  • To test whether price is nearing an MA from above, you could test for price less than the Upper MA Envelope and greater than the MA. You would specify the per cent in the envelope.

    Regarding slope, try it and see. The scan engine allows you to add "volume" or "ema(20,close)" as a parameter, but I'm not sure how you would verify that the results are meaningful. Slope does not appear to be one the indicators available under advanced options (where you can put an indicator on an indicator).

    For crossovers in the past, you could just adjust the scan date. If you don't want to do that, you could try testing for the shorter ma above or below the longer ma x days ago, but below or above it y days ago.

    You can get to the scan support page from the support tab or from the instructions tab at the bottom of the advanced scan page.
  • Upper MA Envelope? Do you mean a set of arguments such as [price < EMA(13,close) * 1.05] and [price > EMA(13,close) * 1.01] (presuming a search for price between 5% above the line and 1% above the line), to form an upper and lower limit?

    I'm not sure how to set the scan date. Using the line that starts "Starting x trading days before the," the default is 0. That means it scans for just one day's data, but if I put 15, it looks for data in the last three trading weeks?

    How many lines can the scan have? It looks like a way to have certain criteria in a block of time in the past but not right up to the present (e.g., from 6 weeks ago up to 2 weeks ago), a series of "x/x+1/x+2/etc." weeks ago lines would work. I kinda want a bullish golden cross in the past, but not too far in the past, with price descending to retest the 13, which means it would have had to have been higher first. I think I understand the sentence ("testing for the shorter ma above or...," and will try that.
  • This has been very helpful. Thanks. It crossed my mind that using different time frames' criteria might be a way to detect a crossover earlier on. If I'm looking for a 50/200 crossover based on daily candles' EMA, it would be about the same as the 13/50 on the weekly, and looking for the crossover based on weekly candles means 1/5 the scan criteria since I'd just have to specify the weeks instead of each of the 5 days in those weeks. When I put

    "and [[Last week's EMA(13,close) x last week's EMA(50,close)] or [2 weeks ago EMA(13,close) x 2 weeks ago EMA(50,close)]]"

    in the scan, the goal is to get the 50/200 daily-candle crossover in the previous week and the week before that. The scan turned up NEM, for instance, and the crossover is the third week back. When I remove the 2 weeks ago part, it still turns up NEM in the scan. Should it not do that because the scan was only for the 2nd week back?

    I guess it would also be good to know how the scan machine interprets "last weeks" crossover. Does it mean that the 13/50 crossover on the weekly candles could have happened in any of the five days of two weeks ago, (meaning that the 50/200 crossover would have happened in those five days)?
Sign In or Register to comment.