SMA and offset

Viewing 5 posts - 1 through 5 (of 5 total)
  • #176825

    Hello, I’m trying to find which stock had its sma3 crossing sma200 5 days ago. I came up with this simple code

    ————–

    sma3 = Average[3,0](close)
    sma200 = Average[200,0](close)
    offset=5
    crossedOver=0

    if ( (sma3[offset] crosses over sma200[offset]) ) then
    crossedOver=1
    endif
    SCREENER [crossedOver]

    ———–

    However, the stocks that are returned have their sma’s not crossed 5 days ago. Am I doing something wrong ?

    Another question, I’ve tried to make the offset incremented in a WHILE loop. I’m sure that the values are >0 and < 100, but I still got an error that my offset is negative or >250.

    Is the offset supporting a variable incremented in a WHILE loop ?

    Thanks in advance

    Patrick

    #176830

    There you go:

     

    #176833

    However, the stocks that are returned have their sma’s not crossed 5 days ago. Am I doing something wrong ?

    Another question, I’ve tried to make the offset incremented in a WHILE loop. I’m sure that the values are >0 and < 100, but I still got an error that my offset is negative or >250.

    Hello,

    By curiosity, did the sma crossed 6 days ago? If yes, it’s just because offset needs to be at 4. The code initial code looks good otherwise.

    Regarding the while, without the code it can be difficult to help. But with a limitation of 250 bars in screeners, I wouldn’t ask for an offset>50 when you use SMA200

    Fabrice

    1 user thanked author for this post.
    #176836

    My example was for crossovers in any day of the last 5 ones.

    Your code is correct for 5 days ago. [0]  is today, [1] is one day ago, etc…

     

    1 user thanked author for this post.
    #176845

    Thank you for your help. I also found another thing to fix: I missed the timeline definition, meaning that the results where not on my expected “daily timeline”

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login