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.

CROSSOVER ANYTIME WITHIN X-Number Days Ago?

edited December 2016 in Scanning
I've read everything that the search box on this site returns for the word "within". But have not been able to answer my question as per below. My reason for asking this question is out of frustration when building and trying to test some of my more complex scans. My current approach when building and testing my builds frequently causes the scan engine to either run slowly or returns a time out and "try again later". I often have to strip out some of my statements to get the scan engine to process those more complex and lengthy testing queries.

QUESTION: Is there a more efficient way to capture a CROSSOVER "Anytime within the past 40 days, 50 days, 60 days or any other desired number of days?" Currently I am using the following syntax:
  • And [[today (technical indicator or oscillator) is >= 1 day ago (technical indicator or oscillator)]
  • OR [1 day ago (technical indicator or oscillator) is >= 2 days ago (technical indicator or oscillator)]
  • OR [2 days ago (technical indicator or oscillator) is >= 3 days ago (technical indicator or oscillator)]
  • OR -----AND I KEEP REPEATING THIS UNTIL DAY 40 OR DAY 60 OR WHATEVER PERIOD OF DAYS I am targeting.]]
The other part of the query is in the opposite direction....
  • AND [1 day ago (technical indicator or oscillator) is < = 2 days ago (technical indicator or oscillator)]
  • OR [2 days ago (technical indicator or oscillator) is < = 3 days ago (technical indicator or oscillator)]
  • OR -----AND I KEEP REPEATING THIS UNTIL DAY 40 OR DAY 60 OR WHATEVER PERIOD OF DAYS I am targeting.]]

As usual, thank you in advance. This forum totally ROCKS!!

Comments

  • markdmarkd ✭✭✭
    edited December 2016
    @8Asteroids8 , I admire your diligence, but I can see why the scan engine would have trouble. You are probably bumping up against the number of operations it can handle (not data, but manipulations of the data).

    A crossover suggests that at some time in the past, element "a" was below element "b", but now "a" is above "b", or vice versa.

    So a test for that would be:

    // 40 days ago, the shorter ma was below the longer ma
    and [40 days ago sma(50, close) < 40 days ago sma(200, close)]

    // today, the shorter ma is above the longer ma
    and [sma(50,close) > sma(200, close)]

    That doesn't tell us WHEN the crossover happened, or whether it happened more than once. But we do know it must have happened AT LEAST once for both conditions to be true.
    You would change the > and < to look for a cross below.

    You can narrow or widen the scope of the search by adjusting the "days ago" parameters. You can also use the calendar tool to adjust the start date of the scan to a month ago, or whenever. For instance, if you wanted know how many 50/200 ma crossovers occurred in, say, July, you could write:


    and [21 days ago sma(50, close) < 21 days ago sma(200, close)]
    and [sma(50,close) > sma(200, close)]

    And then set the scan date on the calendar drop down to the last trading day in July.

    If it's important to know that probably only one crossover occurred during the interval you are interested in, you would probably want to adjust the "days ago" parameters to "match", or "suit" the indicator you are querying. Some indicators cross rarely, so long parameter intervals are OK. Other cross more often, so you would shorten the interval for those.
  • Mark'd...thank you. Helpful, as usual. Thx.
Sign In or Register to comment.