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.

Help writing scan when MA's are a certain % above each other

How do you write a scan to scan for stocks when the 8ema is 1.2% above the 21ema and 1.5% above the 50MA and the 21ema is 0.32% above the 50MA? The reason behind this is because over the years I have put together a chart book and when the ma's above where close to the criteria I presented the stock took off.

Answers

  • For scanning, per cents are expressed in decimal fractions of 1.0. 1.0 is the same as 100 %.

    So, 90% is .9

    110% is 1.1

    10% is .10

    1% is .01

    One tenth of 1% is .01 x .1 or .001

    You always multiply to get a per cent result.

    When you want one amount below another, e.g. A is 25% below B, then you have to subtract the amount below from 1.0. In other words, 25 from 100 is 75%, or

    1.0 - .25 = .75

    A < B * .75


    When you want one amount greater than the other, you add amount to 1.0, e.g. A is 10% greater than B

    A > B * 1.1

    You would use the greater than operator (>) or less than operator (<) instead of the equals operator (=) because you are unlikely to get result for an exact amount, which the = operator requires.


    On the other hand, using just > or < can give you too many results that are likely to be not what you intended. For instance,

    A > B * 1.1

    will also return results that are twice or three times A.

    So, you probably want to specify a range, e.g. 8 ema > 21ema * 1.012 and 8ema < 21 ema * 1.019

    or whatever your research shows might be a reasonable range.





  • Thanks. But, can you write the actual script?
  • Anything on this markd?
  • Follow this model for each ema relationship:

    and [ema(8) > ema(21) * .012]
    and [ema(8) < ema(21) * .015]
  • Does this take into account the cross above the 50MA?
  • This is what I came up with. Not sure how this matches up to the following: How do you write a scan to scan for stocks when the 8ema is 1.2% above the 21ema and 1.5% above the 50MA and the 21ema is 0.32% above the 50MA?

    [type is stock]
    AND[country is US]
    AND [[exchange is NASDAQ]
    or [ exchange is nyse]
    or [ exchange is amex]]
    AND [name not contains 'Fund']
    AND [name not contains 'ETF']
    AND [name not contains 'ETN']
    AND [name not contains 'iShares']
    AND [name not contains 'PowerShares']
    and [ema(8) > ema(21) * .012]
    and [ema(8) < ema(21) * .015]
  • For 1.5 above 50, substitute 50 for 21 and .015 for .012 and .02 for .015

    For 21 abv 50, substitute 21 for 8, 50 for 21, and .0032 for .012 and .005 for .015
  • lmkwinlmkwin ✭✭
    You requested "Help writing scan", not write this scan for me.

    You will find "Help" here with the focus, speaking for myself, on helping and giving the building block logic that you can take and apply to suit your needs.

    The last two lines on your posted scan are looking for the EMA8 to be above the EMA21 by a percentage. Don't know if that is exactly 1.2% or just greater than but, if you want EMA8 to be 1.2% above EMA21, you need to convert that 1.2% into a decimal to multiply against the EMA21.

    1% above would be 1.01. 1.2% above would be 1.012.

    If you want the EMA8 to be above the EMA21 * 1.012. You can decide whether it's equal or greater than or equal.

    For example
    EMA8 = EMA21 * 1.012 or EMA8 >= EMA21 * 1.012
    You would select the EMAs from the Technical Indicators dropdown and format it to meet your needs.

    Here's the last part, where the EMA21 is in the vicinity of being 0.32% above the MA50. The code below is actually looking for the EMA to be between 0.31% and 0.33% above the MA. 0.32% should be in there.

    and [EMA(21,close) >= SMA(50,close) *1.0031]
    and [EMA(21,close) <= SMA(50,close) *1.0033]

    Try that on your chartbook names by putting a prior date in in the "Starting 0 trading days..." box for where you believe that the instance of this was and see if the scan produces a result for that.

    If you get stuck, post what you have for scan code for assistance in troubleshooting.
  • Still not sure if I'm doing this right? Here is what I have.
    [type is stock]
    AND[country is US]
    AND [[exchange is NASDAQ]
    or [ exchange is nyse]
    or [ exchange is amex]]
    AND [name not contains 'Fund']
    AND [name not contains 'ETF']
    AND [name not contains 'ETN']
    AND [name not contains 'iShares']
    AND [name not contains 'PowerShares']
    and [ema(8) > ema(21) * .012]
    and [ema(8) < ema(21) * .015]
    and [EMA(21,close) >= SMA(50,close) *1.0031]
    and [EMA(21,close) <= SMA(50,close) *1.0033]
  • lmkwinlmkwin ✭✭
    Are the results in the ballpark of what you were looking for? You will probably get zero results on most days as that last requirement is quite restrictive. Being almost exactly 0.32% above anything is going to to be a needle in a giant haystack. What is an example stock from your chart book and when was the pattern shown on that chart?
  • markdmarkd mod
    edited October 4
    You also specified ema 8 > ema 50 * 1.015. You need to add that.

    Also, I made an error on ema 8 vs ema 21; it should be ema 8 > ema 21 * 1.012 and ema 8 < ema * 1.015.

    Above means "greater than", so when you ask for 1.2% above, you are really saying ema 8 is greater than 101.2% of ema 21. 101.2% in scan language is 1.012, not .012.

    The way it reads now, it asks for ema 8 greater than 1.2% of (not "above" but "of") ema 21, which would be a very small number and likely always true.


    Sorry.

  • lmkwinlmkwin ✭✭
    "when the 8ema is 1.2% above the 21ema and 1.5% above the 50MA and the 21ema is 0.32% above the 50MA"

    //8ema is 1.2% above the 21ema
    and [ema(8) >= ema(21) * 1.012]

    //and 8ema is 1.5% above the 50MA
    and [ema(8) >= sma(50) * 1.015]

    //and the 21ema is 0.32% above the 50MA
    and [EMA(21,close) >= SMA(50,close) *1.0031]
    and [EMA(21,close) <= SMA(50,close) *1.0033]

    There is a very high probablity that there will be no securities that meet all of these requirements on a given day. Maybe set it up as an Alert to run and notify you of a 'hit' when it occurs. The last requirement is the reason that it is a really narrow possibility.

    If those 1st two requirements become = instead of >= then that will limit it down to an even narrower of narrow possibilities.


Sign In or Register to comment.