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.

Check for the Market Trend

Hi,

I am running a scan which I would like it to return results only when SPY is above its 20 days moving average. Something like:
and ['SPY' close > 'SPY' sma(20,close)]
Does anyone know how to code this?

Thanks

Best Answer

  • markdmarkd mod
    edited April 23 Accepted Answer
    I am pretty sure you have to use a separate scan to determine if SPY meets your condition (or look at the chart).

    The scan would be:

    [symbol is 'SPY']
    and [close > sma(20, close)]

    The reason is, the scan engine returns a symbol only if it meets ALL conditions in the scan. Only SPY meets the condition [symbol is 'SPY'], so only SPY will be returned.

    But, you *might* be able to test for the opposite condition for SPY, using an 'or' statement, like this.


    // these lines should execute when SPY is below its SMA and return only symbol SPY
    // the favorites list code (second part of the 'or' condition') should not return anything (I think)

    [
    [symbol is 'SPY']
    and [close < sma(20, close)]
    ]

    or

    // these lines should execute when SPY > MA 20

    [
    [ favorites list is ??] // your list
    and [ some condition]
    and [ some condition]
    ]

    Make sure you include ALL the brackets. Sorry I don't have the time to test to be sure this will work. You have to find a day when SPY is below its MA 20, and list conditions are true.

Answers

Sign In or Register to comment.