Moving AVerage Crossover for Multiple days
Forums › ProRealTime English forum › ProScreener support › Moving AVerage Crossover for Multiple days
- This topic has 5 replies, 3 voices, and was last updated 4 years ago by
ZionTrader.
-
-
07/28/2020 at 1:40 PM #140301
Good day,
I was wondering if anyone can assist with with a moving average cross for a number of days. For example below is the bearish moving average which shows all the instruments where its 50 day moving average crosses below its 200 moving average for today. However, I don’t want just today’s bearish Moving average crossover , but I want to see the last 5 days. If anyone can assist I would really appreciate it.
Bearish Moving Average Crossover12345678910111213141516REM Calculate a simple moving average over the last 50 daysma50 = AVERAGE[50]REM Calculate a simple moving average over the last 200 daysma200 = AVERAGE[200]REM Calculate the speed at which the short MA crosses under the long MAspeed = MOMENTUM(ma50-ma200) * 100 / CLOSEREM Display securities for which short MA has just crossed under long MA. Show the fastest crossings first.IF ma50 CROSSES UNDER ma200 THENSCREENER (speed AS "Speed")ENDIFThanks.
08/26/2020 at 5:35 PM #142631Hi, please find attached.
I have set the field “DayCount = 4” covering five days, change it to any number (e.g., changing it to 9 will give crossover in last 10 days).
Have fun …kaq52
Average crossover123456789101112131415161718192021222324252627//Author KAQ52//This screener finds crossover of two averages in last n daysDayCount = 4 //change it as appropriateREM Calculate a simple moving average over the last 50 daysma50 = AVERAGE[50]REM Calculate a simple moving average over the last 200 daysma200 = AVERAGE[200]REM Calculate the speed at which the short MA crosses under the long MAspeed = MOMENTUM(ma50-ma200) * 100 / CLOSECrossover=0 //flag for detecting crossoverFor i = 0 to daycountif (ma50[i] crosses over ma200[i]) or (ma50[i] crosses under ma200[i]) thenCrossOver=1breakendifnextREM Display securities for which short MA has just crossed under long MA. Show the fastest crossings first.SCREENER [Crossover] (speed AS "Speed")08/26/2020 at 6:48 PM #142643Replace lines 17-22 with this ONE:
1CrossOver = summation[DayCount]((ma50 crosses over ma200) or (ma50 crosses under ma200))As for your FOR…NEXT iterations, 0 TO DAYCOUNT will check the last 5 periods, while summation 4 (the last 4, not 0 to 4).
1 user thanked author for this post.
08/27/2020 at 12:44 AM #142664Thanks RobertGozi, your solution looks much precise.
My understanding so far is that “for i = 0 to daycount” with daycount=4 loop will get below five values, thus covering five days(including current one). Is this understanding not correct please?
ma20[0] —current candle
ma20[1]
ma20[2]
ma20[3]
ma20[4]
1 user thanked author for this post.
08/27/2020 at 7:34 AM #142669Yes, that’s correct.
Summation, instead, with the same value for DayCount you’ll check one less bar, 0 to 3.
08/28/2020 at 10:28 AM #142798Thank you very much for assistance. Appreciated.
-
AuthorPosts
Find exclusive trading pro-tools on