SMA and offset
Forums › ProRealTime English forum › ProScreener support › SMA and offset
- This topic has 4 replies, 3 voices, and was last updated 3 years ago by prorealtime.
-
-
09/05/2021 at 3:46 PM #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=0if ( (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
09/05/2021 at 6:42 PM #176830There you go:
1234sma3 = Average[3,0](close)sma200 = Average[200,0](close)crossedOver = summation[5](sma3 crosses over sma200)SCREENER [crossedOver]09/05/2021 at 7:27 PM #176833However, 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.
09/05/2021 at 8:06 PM #176836My 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.
09/06/2021 at 7:53 AM #176845Thank 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”
-
AuthorPosts