Shift Moving Average to the left
Forums › ProRealTime English forum › ProBuilder support › Shift Moving Average to the left
- This topic has 9 replies, 3 voices, and was last updated 6 years ago by robertogozzi.
-
-
07/06/2018 at 5:13 PM #75489
Hello,
I look for instruction to shift moving avg to the left ( not to the right).
i mean if i have 5 days : day1 day2 day 3 day4 and day 5
the value for the 5 day moving average shifted by 2 on the LEFT is for the day 3 :
value(day3 ) = 1/5 *(close(day1) + close( day 2) + close(day3) + close(day4 ) + close(day 5))
as i have only 5 days, and as i shift by two on the left the value is undefined for day 4 and day 5 and nothing is displayed:
value(day4) : blank
value(day5) : blank
this can be done with ‘shift horizontal’ property in moving average configuration box, but cannot be done programtically for the moment : how do it ?
after this i will use other coefficients than 1/5 in my summations ( with some negative coefficients )
Thierry Brémard
07/06/2018 at 5:29 PM #75490Moved to the English forum.
07/06/2018 at 5:50 PM #75492While you can easily draw something that happened in the past, like that
12ma = average[20,0](close)return ma,ma[1],ma[2]the same is not allowed for the future.
You could do that by making an indicator that computes the average itself within a FOR…NEXT loop, but it would require so many loops, especially if you should use multiple MAs crossovers and, even if ProBuilder would allow you to do it, well… it would require such a long time at every new candlestick to make you hate it!
07/06/2018 at 8:29 PM #75505Hello Roberto,
thank you for your fast answer.
i am annoyed because i understand that you suggest that it is not possible,
but I can parameter the moving average to do this. attached you see in blue the 21 moving average shifted to the left by 10 units.
pro builder should have instruction like this no ? maybe a meta instruction or meta parameter for indicator like “shift all result to -x units on the left” ?
as you are partner with pro real time can you ask them how they do this with their own moving average ?
or could you ask them to give the user possiblity to use their moving average mechanism with a custom module to specify exactly the value of the coeficcients ( user specifiy 21 values for a 21 moving average)
Regards
07/06/2018 at 10:27 PM #75511That’s was not as difficult as I thought, if I understood your question (a screenshot is better than lots of words):
Left Shifted MA12345678// ONCE BarShifting = 26// OMCE Period = 20// ONCE AvgType = 0 (0=sma)Ma = Average[Period,AvgType](close)IF BarIndex >= BarShifting THENDRAWSEGMENT(BarIndex-BarShifting-1,Ma[1],BarIndex-BarShifting,Ma) coloured(255,140,0,255)ENDIFRETURNFrom the attached screenshot you can see the same SMA[20] on the chart displayed normally and left-shifted 26 bars (I wrote 26 thinking about Ichimoku, but it has nothing to do with that). You can change the shifting, period and type as you prefer (for colors take a look at https://www.prorealcode.com/wp-content/uploads/2015/09/P1jHlnG.jpg).
As for my partnership with PRT, I admit I would be glad to have one, but It is not the case for me and, as far as I know, for all other moderators. Even Nicolas, the Admin, is not a partner of PRT. He, living closer to PRT has for sure more chances to know something a bit earlier than anyone else here, but nothing else. AS being a moderator, well… Nicolas asked me as he saw I was frequently online and was answering many posts and questions, being a moderator simply means I can edit/move/cancel posts NOT getting paid!
Me, as many other active members have suggested PRT (Nicolas set up this topic for that purpose) through https://www.prorealcode.com/topic/centralization-of-queries-and-suggestions-on-prorealtime/. And some suggestions are about to be integrated, so if you have some, feel free to post there!
07/07/2018 at 1:59 PM #7552707/07/2018 at 4:26 PM #75538Hello,
thank you for the help, i validate the code below:
5 unit Moving average shifted to the left by 2123456789N = 5filtered = 1/N*CLOSE[0]+ 1/N*CLOSE[1]+ 1/N*CLOSE[2]+ 1/N*CLOSE[3]+ 1/N*CLOSE[4]BarShifting = (N-1)/2xStart = BarIndex-BarShifting-1yStart = filtered[1]xStop = BarIndex-BarShiftingyStop = filteredDRAWSEGMENT(xStart, yStart,xStop, yStop) coloured(100,100,100,255)returnI was speaking about partnership because i called the pro real time help friday (french office ). i called them first to have answer to my question and suggested me to try on this forum , i replied i wanted to speak to editor only, they replied to this that you were partner and in closed relation between pro real time and pro real code.
Regards
07/07/2018 at 4:34 PM #7553907/07/2018 at 4:39 PM #75540is there a way to create an array ?
i need to instanciate an array of coefficient at start of code then aplying coefficients to close with a for loop:
coefficients = (1/N 1/N 1/N 1/N 1/N)
what is the syntax ? i tried brakets and parenthesis and do not see any array section in their manual
07/07/2018 at 8:17 PM #75546Unfortunately arrays are not supported.
Many of us can’t wait to have them, but we must be patient and do without at present.
-
AuthorPosts
Find exclusive trading pro-tools on