SMA and offset

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #176825 quote
    prorealtime
    Participant
    New

    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 quote
    robertogozzi
    Moderator
    Master

    There you go:

    sma3 = Average[3,0](close)
    sma200 = Average[200,0](close)
    crossedOver = summation[5](sma3 crosses over sma200)
    SCREENER [crossedOver]
    #176833 quote
    Swingueur
    Participant
    Average

    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

    prorealtime thanked this post
    #176836 quote
    robertogozzi
    Moderator
    Master

    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…

    prorealtime thanked this post
    #176845 quote
    prorealtime
    Participant
    New

    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)
  • You must be logged in to reply to this topic.

SMA and offset


ProScreener: Market Scanners & Detection

New Reply
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by prorealtime
4 years, 5 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 09/05/2021
Status: Active
Attachments: No files
Logo Logo
Loading...