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.

Searching for Weekly Conditions in the past

Hello all - I am trying to build a scan that will search for a condition that has been met in the past on different time frames.

For example - I want to find a weekly cross of the 20SMA crossing above the 50SMA in the past 10 weeks. And then add another condition to look for price closing under the 50SMA on the daily.

Is this possible?

Comments

  • lmkwinlmkwin ✭✭
    You can copy your scan to the forum for troubleshooting. What have you got so far on this scan?

    and [[weekly SMA(20,weekly close) x weekly sma(50,weekly close)]
    or [1 weeks ago weekly SMA(20,weekly close) x 1 weeks ago weekly sma(50,weekly close)]]

    would get you this week or last week where the 20 crossed above the 50

    your 2nd condition would need a little more defining. "price closing under" is vague, but you can select the SMA from the Technical Indicators drop down. It defaults into the workbench like this:

    and [SMA(50,volume) > 9999999]

    It's looking at the SMA50 of daily volume. You'd want to change the volume to your price of choice (high, low, open, close) and change the 99999 to your price of choice.

    If you get stuck, copy your code to the forum for assistance in troubleshooting.

  • Great feedback - thank you!

    Here's what I've come up with:

    [type is stock]
    and [ [group is SP500]
    or [group is SP400]
    or [group is SP600] ]
    and [ [7 weeks ago weekly SMA(18,close) x 7 weeks ago weekly SMA(40,close)]
    or [8 weeks ago weekly SMA(18,close) x 8 weeks ago weekly SMA(40,close)]
    or [9 weeks ago weekly SMA(18,close) x 9 weeks ago weekly SMA(40,close)]
    or [10 weeks ago weekly SMA(18,close) x 10 weeks ago weekly SMA(40,close)] ]


    and [Close > SMA(18,Close)]
    and [Close < SMA(40,Close)]
  • lmkwinlmkwin ✭✭

    [type is stock]
    and [ [group is SP500]
    or [group is SP400]
    or [group is SP600] ]

    // extra Left Bracket added to start enclosing the entire scan requirement
    and [ [ [7 weeks ago weekly SMA(18,close) x 7 weeks ago weekly SMA(40,close)]
    or [8 weeks ago weekly SMA(18,close) x 8 weeks ago weekly SMA(40,close)]
    or [9 weeks ago weekly SMA(18,close) x 9 weeks ago weekly SMA(40,close)]
    or [10 weeks ago weekly SMA(18,close) x 10 weeks ago weekly SMA(40,close)] ]


    and [Close > SMA(18,Close)]

    // extra right bracket added to end enclosing the entire scan requirement.
    and [Close < SMA(40,Close)] ]

    I added a couple brackets to make the scan engine treat the entire set of requirements as one.

    As you have this now, it doesn't match up with your original request, but your requirements may have changed.
    It's looking at 7 to 10 weeks ago for a weekly SMA 18 / 40 cross. AND a daily close that is greater than the daily SMA18 and that is less than the daily SMA40

    I'm not certain if you need to add weekly in front of the close in the SMA in the Crossing section, but I think you may. ex. 7 weeks ago weekly SMA(18,weekly close)

    Also, all the members of the SP500, 400, and 600 are stocks so the 1st line is redundant. It can stay in as that is a great first line for a scan looking for stocks vs other security types.

    Nice work there.
  • Unless you are writing a one-off scan, it might be easier to write the scan for a crossover in the current week, then run that with a date offset for prior weeks.

    Compile the results in a list and then run a simple scan for the second set of condition against the list.

    Just an idea. I know everyone works differently.
Sign In or Register to comment.