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.

Early golden cross

[type = stock]
and [today's daily SMA(50) x today's daily SMA(200)]

How can I take this syntax and write for SMA(50) a percentage away from crossing? My goal is to catch the crossover early

Comments

  • This is the new script I wrote but I'm not getting any results

    [type = stock]
    and [ [exchange is NYSE] or [exchange is NASDAQ] ]
    and[ [Close >=SMA(50,close) *0.98] x [ SMA(200,close)]]
    and [[Close >=SMA(50,close) *1.02] x [ SMA(200,close)]]
  • markdmarkd mod
    edited September 2018
    You are smart not to look for the actual crossover, which would be a simple scan (50 MA x 200 MA), but getting what you want is more complicated. You've made a good start, so let's walk through it.

    You are not looking for the actual crossover in the scan, you are looking for the two MAs being close to each other. So, you can eliminate the "x" operator.

    Also, you probably don't care about where the close is because it's the MAs that cross in a golden cross. So you can eliminate references to the close.

    Also, as a point of syntax, you can not have more than one operator (>, <, =, x, etc.) for each "and [ ... ] " condition. A condition is (almost) always the word "and", the opening and closing brackets "[ ]", an operator (>, <, etc.) and the two terms compared by the operator, one on each side; for instance, in this condition "and [close > sma(10, close)]", close is a term, and sma(10, close) is a term.

    So this statement, even if it passes syntax, is wrong:

    and[ [Close >=SMA(50,close) *0.98] x [ SMA(200,close)]]

    You have the right number of brackets, and they are well placed, but assuming the "close" condition is true, this line says "true crosses above MA 200", which is not meaningful. If you think about it, how would the scan engine decide whether you want the close or the SMA crossing above the 200 MA? The syntax checker should flag this, but I'm guessing it doesn't, so don't feel bad.

    So, re-thinking things a little:


    What you need to know is the direction of the two MAs and whether they are close to each other.

    A golden cross happens when the 50 MA crosses above the 200 MA from below.

    So there are several tests that you need.

    One is that the 200 MA is falling. A way to test that is to scan for today's 200 MA less than the 200 MA some number of days ago (you decide how many).

    Then you need to test that the 50 MA is rising, or greater than it was some number of days ago.

    Now, if you want to catch the golden cross before it actually happens, you can test whether the 50 MA is some per cent less than the 200 MA. Probably the easiest way to do that is to test for 50 MA < 200 MA and 50 MA > 200 MA * .?? (.?? means some decimal fraction corresponding to the distance between them as a per cent; note: two separate statements, not one).

    If you want to catch it some time after, you can test whether the 50 MA is some per cent greater than the 200. In order to insure a crossover, you might want to test that the 50 was less than the 200 some number of days ago.

    Give that a try and if you get stuck, post what you have.

  • Another option to "catch the crossover early" is just to shorten the 50 to a lesser number, like 45. If the shortened MA crosses, then the longer one should be close.
  • Hey Mark,

    I was trying to create this same thing when I found this post. I have more to this but this is the "meat" of what I am looking for. I don't see why it isn't producing "a lot" of results? Note, I am also looking for stocks below the 200 MA. Essentially looking for the crossover lower than normal.

    and [[[1 day ago SMA(13) < 1 day ago sma(30)] and [0 days ago SMA(13) > 0 days ago sma(30)*0.98]]
    or [[2 days ago SMA(13) < 2 days ago sma(30)] and [1 day ago SMA(13) > 1 day ago sma(30)]]
    or [[3 days ago SMA(13) < 3 days ago sma(30)] and [2 days ago SMA(13) > 2 days ago sma(30)]]]

    I can obviously change my MA numbers but I use 13/30 most of the time.

    I have also gotten results where my shorter MA is crossing from above vs below, any thoughts to that? Sorry to hijack someone else's post!

  • If the scan is getting the results you expect, but just too few of them, then it's probably due to the state of the market at the time you are running the scan. The number of results for any scan will vary depending on whether the general market is rising or falling. For instance, if the index 200 MA (or other MA) is rising, most stocks will above the MA, not below it. Obviously, some will be below it, but not that many.

    To test this, look at an index chart, find dates when the market is rising (in an up leg) and falling (in a down leg), and run the scan on those dates. The number of results should vary noticeably.

    Another possibility for too few results is that your additional conditions not shown are too restrictive in some way.
Sign In or Register to comment.