How can I plot different moving averages on Monthly/Daily/Weekly
Forums › ProRealTime English forum › ProBuilder support › How can I plot different moving averages on Monthly/Daily/Weekly
- This topic has 14 replies, 3 voices, and was last updated 7 years ago by prcolf.
-
-
06/12/2017 at 1:25 AM #38089
Hi
Could someone please tell me how to make an indicator that will recognise what timeframe I am viewing and plot different moving averages. I have tried the following formula but after a lot of googling I’m not sure if this is possible in ProBuilder.
12345678910111213Timeframe(month)RETURN ExponentialAverage[10](close)Timeframe(weekly)RETURN ExponentialAverage[40](close)Timeframe(daily)RETURN ExponentialAverage[10](close)RETURN ExponentialAverage[50](close)RETURN ExponentialAverage[200](close)06/12/2017 at 8:30 AM #38117Not possible to use “timeframe” in ProBuilder.
To automatically find on which timeframe you are on, you can try to use this code snippet, it will return the minutes quantity (120 for a 2 hours timeframe for instance).
find timeframe of the current chart1234567891011121314once NbBar = 1if BarIndex < NbBar+2 thenMyDay=opendaydayminutes = 1440*(MyDay-MyDay[1])MyHour=openhourhourminutes = 60*(MyHour-MyHour[1])MyMin=openminutebarminutes = MyMin - MyMin[1] + hourminutes + dayminutesbarminutes=abs(barminutes)Mybarminutes = lowest[NbBar](barminutes)[1]endifreturn Mybarminutes as "Timeframe"1 user thanked author for this post.
06/12/2017 at 8:50 AM #38120Hi Nic
Thanks for the help mate. I’ve only been using ProRealTime for a few days so I’m a bit green. I’m used to Amibroker and Metastock.
How can I start writing the conditions based on that formula? Do I place that at the beginning of the formula and then start referencing to Timeframe?
Alan
06/12/2017 at 11:00 AM #38129I use the following code to determine timeframe (daily/weekly/monthly)/ It is based on PRT’s time format: yyyymmdd (i.e. 20170612 for today) and bar-to-bar simple subtraction to detect the number of days between adjacent bars. The OR in each IF deal with weekends etc. This, of course, only work for swing trading
123456789101112131415If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndif06/13/2017 at 7:48 AM #38171Thanks Pinny
I’m still having a bit of trouble. How many times can you add “Return” to an indicator. I’m getting an error and I’m not sure what to do.
123456789101112131415161718192021222324252627282930313233If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a==100) ThenRETURN ExponentialAverage[10](close)Elsif (a==30) ThenRETURN ExponentialAverage[40](close)Else (a==1) ThenRETURN ExponentialAverage[10](close)RETURN ExponentialAverage[50](close)RETURN ExponentialAverage[200](close)EndIf06/13/2017 at 8:19 AM #38177You can only RETURN the variables once.
You should have coded it like this:
12345678910111213141516171819202122232425262728293031323334If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a=100) Thenema1= ExponentialAverage[10](close)Elsif (a=30) Thenema1= ExponentialAverage[40](close)Else (a=1) Thenema1= ExponentialAverage[10](close)ema2= ExponentialAverage[50](close)ema3= ExponentialAverage[200](close)EndIfreturn ema1, ema2, ema3Please test it and tell us if it works! 🙂
(there is not need to make double equal for testing like in other programming languages).
1 user thanked author for this post.
06/13/2017 at 8:27 AM #3817906/13/2017 at 8:40 AM #38182I think its a EndIf issue, the following works:
1234567891011121314151617181920212223242526272829303132333435If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a=100) Thenema1= ExponentialAverage[10](close)ElseIf (a=30) Thenema1= ExponentialAverage[40](close)ElseIf (a=1) Thenema1= ExponentialAverage[10](close)ema2= ExponentialAverage[50](close)ema3= ExponentialAverage[200](close)EndIfendIfendifreturn ema1, ema2, ema31 user thanked author for this post.
06/13/2017 at 8:43 AM #3818306/13/2017 at 9:25 AM #38189Looks like there is still a small problem. It wasn’t plotting on the weekly when using “a=30″ so I changed it to ” a=7″ and it plots fine. The monthly was plotting fine but now that the weekly is set to “a=7” the monthly no longer plots
06/13/2017 at 9:43 AM #3819306/13/2017 at 9:57 AM #38195Here is the whole formula. The monthly will not plot
12345678910111213141516171819202122232425262728293031323334If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a=100) Thenema1= ExponentialAverage[10](close)Elsif (a=7) Thenema1= ExponentialAverage[40](close)Elsif (a=1) Thenema1= ExponentialAverage[10](close)ema2= ExponentialAverage[50](close)ema3= ExponentialAverage[200](close)EndIfreturn ema1, ema2, ema3There is also a vertical line at the beginning of the ema. I use valuewhen in metastock to hide that but that doesn’t seem to be available in Probuilder. Is there a way to hide it?
12HideEMA1 = 0.9*valuewhen(1,ema1<>0,ema1)ShowEMA1=If(ema1=0, HideEMA1, ema1)06/13/2017 at 10:17 AM #38199Sorry, this is my documentation mistake – 1/daily, 7/Weekly, 30/Monthly, 100/Quarterly, 200/AnnualJust use a=30 and this will plot on the Monthly (tried it:-)If (date–date[1])=1 OR (date[1]–date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date–date[1])=7 OR (date[1]–date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date–date[1])=99 OR (date[1]–date[2])=99 Thena=30 // 30 signals Weekly timeframeEndifIf (date–date[1])=299 OR (date[1]–date[2])=299 Thena=100 // 100 signals Monthly timeframeEndifIf (date–date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a=100) Thenema1= ExponentialAverage[10](close)Elsif (a=7) Thenema1= ExponentialAverage[40](close)Elsif (a=1) Thenema1= ExponentialAverage[10](close)ema2= ExponentialAverage[50](close)ema3= ExponentialAverage[200](close)EndIfreturn ema1, ema2, ema31 user thanked author for this post.
06/13/2017 at 10:20 AM #3820012345678910111213141516171819202122232425262728293031323334If (date-date[1])=1 OR (date[1]-date[2])=1 Thena=1 // 1 signals Daily timeframeEndifIf (date-date[1])=7 OR (date[1]-date[2])=7 Thena=7 // 7 signals Weekly timeframeEndifIf (date-date[1])=99 OR (date[1]-date[2])=99 Thena=30 // 30 signals Monthly timeframeEndifIf (date-date[1])=299 OR (date[1]-date[2])=299 Thena=100 // 100 signals Quarterly timeframeEndifIf (date-date[1])>9500 Thena=200 // 200 signals Annual timeframeEndifIf (a=100) Thenema1= ExponentialAverage[10](close)Elsif (a=7) Thenema1= ExponentialAverage[40](close)Elsif (a=1) Thenema1= ExponentialAverage[10](close)ema2= ExponentialAverage[50](close)ema3= ExponentialAverage[200](close)EndIfreturn ema1, ema2, ema31 user thanked author for this post.
06/13/2017 at 10:46 AM #38201 -
AuthorPosts
Find exclusive trading pro-tools on