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.
Options

Help with creating a scan

Hi. I am trying to write a scan for the following

-The last occurrence of the 3 period moving average crossing above the 20 period MA was greater than or equal to 7 trading days ago.
-The 5 day RSI crosses below 35 as of the last trading day close (that is "crosses below" NOT "is below"
- The stock market as measured by the SP500 index is above its own midpoint of the last 300 trading days. That is take the highest high within the last 300 trading days and the lowest low within the last 300 trading days and find the level halfway between those two points.

Comments

  • Options
    markdmarkd mod
    edited February 7
    Condition 1 - It's not clear what you want to compare
    - MA 3 at MA 3 x MA 20 versus MA 3 7 days ago,
    - the two closes on those days,
    - the MA 3 at MA 3 x MA 20 to the close 7 days ago;
    - do you mean 7 trading days ago from today, or 7 days prior to the crossover ?

    Also, since we don't know when the crossover occurred, you would have to test for every possibility from today back to some point in the past;

    But, you could try a different set of conditions that are less specific but might be good enough:

    and [sma(3,close) > 7 days ago sma(3,close)] // MA 3 higher than 7 days ago
    and [7 days ago sma(3, close) < 7 days ago sma(20,close)] // 7 days ago, MA 3 was below MA 20
    and [sma(3,close) > sma(20,close)] // today MA 3 is above MA 20

    So, MA 3 crossed MA 20 on one of the past six days (and possibly today).

    This doesn't directly compare MA 3 on the crossover day to MA 3 today, so you may get some duds, but you should get good hits, too.

    Condition 2 - this is pretty straightforward

    and [RSI(5) x 35] // x is the cross above operator; the left term always crosses above the right-hand term).

    Condition 3 - SP 500 above its 300 day midpoint.

    and [close > Middle Price Chan(300)]

    A scan returns symbols in your universe (e.g. [exchange is NYSE] ) that meet ALL conditions. So to $SPX would have to meet conditions 1 and 2 also (and be included in your universe, which would have to be a favorites list, since $SPX doesn't trade). But the others, if they meet conditions 1 and 2 would also have to meet condition 3.

    You may not want that. If not, run condition 3 as a separate scan against a list with only $SPX as a member. Or just look at the chart with a 300 price channel on it.




  • Options
    Hi Mark. Thank you for the reply. I am trying to create an alert to when the $SPX meets the above criteria and then I would trade the SPXW or futures. So it's not that I am trying to find new stocks it's really just to trade the SP500. It is something called the "Shift" strategy alerting me to when the market is setting up for a pullback
  • Options
    Looks like you are creating an Advanced Alert. Alerts and Scans are constructed in the same way.

    On your alert you would start with declaring your universe (what the alert is looking for).
    If only looking for specific symbols, you should select the Symbol from the Ticker Properties dropdown.

    Symbol defaults into the workbench like this

    and [symbol starts with 'A']

    As you are only looking for a specific symbol, $SPX, you would change this line to

    [symbol starts with '$SPX'] //this would return any symbol that starts with $SPX if scan/alert is true.

    or you can use

    [symbol = '$SPX'] //would return only symbol $SPX if scan/alert is true.

    then add the other lines to get your criteria and save the alert. When the alert triggers, you'll get a notification that you've set up when saving the Alert.

    I'd also recommend running/saving this code in the Scan workbench to test it out. You can use the calendar function to backdate the scan to see if it will actually return results. Crosses are very specific. Sometimes the cross happens on different periods than the other criteria so the cross is true but the MA's are false, but the setup is what you were looking for, it's just that the MA's required another day to move and by that time the cross is no longer valid. Just stuff to be aware of.

    You can work around this to a certain extent using the OR statement but that would be subject to your intention and requirement.
Sign In or Register to comment.