MOving Average Daily
Forums › ProRealTime English forum › ProBuilder support › MOving Average Daily
- This topic has 10 replies, 3 voices, and was last updated 6 years ago by
marcara.
-
-
03/12/2019 at 10:46 PM #93488
Hi,
I am using the moving daily average inidicator (with 200 parameter) in an intraday chart https://www.prorealcode.com/prorealtime-indicators/moving-average-daily/ ; it is working perfectly.
The issue: The intraday chart need to load many intraday timeframes in order to calculate de moving daily average 200.
Is it possible to load the necessary bars in the indicator?
I have tried to use DEFPARAM CalculateOnLastBars = 200 but it is not working.
Here is the code:
1234567891011121314// Please note if you're using IG there's a smaller number of days you can use and the smaller the timeframe the small number of days you can useDEFPARAM CalculateOnLastBars = 200periods = p // daysLMA=0 // Loop MAFOR i = 0 TO periods-1 DO // Need -1 so the Result is the number of periods we actaully wantLMA = DClose(i) + LMA // Don't think this is possible CustomClose[(i)]NextLMAactual = (LMA / (periods))RETURN LMAactual AS "Daily MA"Thanks in advance
03/13/2019 at 9:22 AM #93502Remove the calculateonlastbars, otherwise the loop could not retrieve all the necessary bars to complete the daily MA calculation.
Depending of the intraday timeframe you use, it is possible that you need a lot of units displayed for a correct calculation. So just try to expand a lot the displayed units of the chart first.
03/13/2019 at 9:48 AM #93506This is interesting as I was just trying to code a volatility indicator but it kept giving me the too big loop error. Here is the basics of the code idea:
12345678910111213//defparam calculateonlastbars = 5000x = 157a = 0total = 0while total <= xtotal = total + range[a]a = a + 1wendreturn 0 - aIt simply counts how many bars it takes to reach or exceed a certain value of added together ranges. The more bars it takes the lower volatility is and the fewer bars it takes the higher volatility is. With the CALCULATEONLASTBARS set to 5000 I could not get it work with values for x any greater than 156 on the EURUSD which is about the total of 3 candles on average! If I remove the CALCULATEONLASTBARS then it works just fine even with massive values for x.
Seems a bit buggy as 5000 candles should be plenty to work with when just looking for candle ranges adding up to 157.
03/13/2019 at 10:13 AM #93510The infinite loop problem occurred more often with a WHILE/WEND loop, I think that you can get rid of the error with this version:
123456789101112131415161718x = 157//a = 0total = 0for a=0 to barindex dototal = total + range[a]if total>x thenbreakendifnext//while total <= x//total = total + range[a]//a = a + 1//wendreturn 0 - a03/13/2019 at 10:35 AM #9351903/13/2019 at 11:45 AM #93527Thank you very much,
The code is working properly.
The problem is that I need a lot of units displayed in the intraday chart so it takes a bkit to load the chart. I would like to avoid displaying a lot of units in the chart If I can only charge the units in the indicator code.
Thanks in advance
03/13/2019 at 1:10 PM #93533That’s not how it works, the calculation depends of the loaded history/units.
Another way to use other timeframes indicator on the current chart is to use a backtest with the GRAPHONPRICE instruction, look at these examples: MTF for indicators with GRAPHONPRICE
03/13/2019 at 6:11 PM #93554Thank you very much
I have tried to use it but it is giving an error. I added the GRAPHONPRICE in the Return instruction.
12345678910periods = p // daysLMA=0 // Loop MAFOR i = 0 TO periods-1 DO // Need -1 so the Result is the number of periods we actaully wantLMA = DClose(i) + LMA // Don't think this is possible CustomClose[(i)]NextLMAactual = (LMA / (periods))RETURN graphonprice LMA coloured(200,200,0) as "Daily MA"03/13/2019 at 10:21 PM #93564Please use the ‘Insert PRT Code’ button when posting code in your posts to make it more readable for others. I have tidied up your post for you 🙂
GRAPHONPRICE is an instruction that can only be used in strategy codes and not in indicator codes. However if we code a dummy strategy as per the link Nicolas provided then we can use it to create MTF indicators on price charts. This can overcome the fact the multi time frame is not currently available in indicator coding but still allows us to create MTF indicators on price charts. Just get rid of the positions window and reduce the equity curve to minimum size and we have MTF indicators on price charts. It is just a work around that makes your indicator much easier to code.
03/13/2019 at 10:56 PM #93566An example. Not tested:
123456789timeframe (daily, updateonclose)daily200ave = average[200](close) // daily 200 averagetimeframe(default)if average[2] = -1 then // dummy strategybuy at marketendifgraphonprice daily200aveRun as a strategy not an indicator.
1 user thanked author for this post.
03/14/2019 at 11:10 AM #93611 -
AuthorPosts
Find exclusive trading pro-tools on