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


  • 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.
Sign In or Register to comment.