Moving Averages with periodic shift
Forums › ProRealTime English forum › ProBuilder support › Moving Averages with periodic shift
- This topic has 8 replies, 4 voices, and was last updated 10 months ago by robertogozzi.
-
-
01/15/2024 at 12:13 AM #226337
Dear Pro Real Code Team,
I would like to know whether it is possible to shift moving average lines like EMA or TEMA in the price chart window via customizing.
I have seen this in other charting software and I see a great advantage in the visualization of trend reversals.
See also the example in the attachment.Many thanks and best regards.
01/15/2024 at 8:07 AM #226343Hi @Traderfox06
What you show in your screenshot is not a “shift” (Close[n+shift]) in the indicator but “fast” and “slow” averages…
In this indicator you can see how it works:
https://www.prorealcode.com/prorealtime-indicators/guppy-indicator/
01/15/2024 at 8:28 AM #22634401/15/2024 at 9:21 AM #226345I think it is a shift all right. But what @Traderfox06 will want to do, is not possible in code. It is possible with some indicators though (e.g. Hull Moving Average).
Shift in code is possible, but to “later”, while you’d want earlier.A description about this is written somewhere by Nicolas, but from the top of my head he talks about “shift to the right is not possible”. But … see below. What the mouse points at, would be shifted to the right. That *is* possible. But you would want to shift to the left, so the average etc. peaks as where reality happened. The right most line shown here would be reality. The others will have been shifted to the left.
I suppose the (e.g.) HMA indicator does that with a kind of repaint.
N.b.: I recall that if you try this in practice, the to the left shifted part is lacking at the right side of the chart (thus repaint ?).Add [xhiftamount] to the average commands at the right side. OK, here for SMA (from Nicolas) :
12X = 10 //you'll get the value of the SMA from 10 bars agosma20 = average[20](close)[X]… which means “10 bars too late” according to my interpretation.
01/15/2024 at 10:45 AM #226358Shifted to the left:
Left shifted MA123456789Periodi = 10 //10Tipo = 0 //0=smaShift = 1 //1 period shifted to the leftsrc = CustomCloseMyAvg = average[Periodi,Tipo](src)IF BarIndex > Shift THENdrawsegment(barindex - Shift - 1,MyAvg[1],barindex - Shift,MyAvg) coloured(139,69,19,255)ENDIFreturnShifted to the right (into the future):
123456789101112131415161718192021ONCE Periods = 10ONCE AvgType = 0ONCE Hshift = 1MyMA = Average[Periods,AvgType](close)Result = MyMAr = 0g = 0b = 255t = 0IF BarIndex > Periods THENIF Hshift = 0 THENt = 255ELSEx1 = BarIndex + (Hshift - 1)y1 = Result[1]x2 = BarIndex + Hshifty2 = ResultDrawSegment(x1,y1,x2,y2) coloured(0,128,155,255)ENDIFENDIFRETURN Result AS "MA" coloured(r,g,b,t)1 user thanked author for this post.
01/15/2024 at 11:47 AM #226362Roberto, I think this is great. It is about the first version of course (shift to the left).
Visually this works perfectly. Now it should return the MyAvg as a line which can be checked for crossing etc. (trend change). It requires a bit of staring for me on how to do that. But I suppose it can be done with this as the base.
01/15/2024 at 6:10 PM #226392Well, it works like CHIKOU (Ichimoku), which is the current price shifted 26 bars leftwards. Nobody could know, 26 bars ago what the price would have been now.
It’s of no practical use as is. We could try to forecast tomorrow’s price. This snippet returns both the regular SMA and the same one to which I added the average difference as a simplicistic way to forecast the next price:
1234567Periods = 10 //10Type = 0 //0=smasrc = CustomCloseMyAvg = average[Periods,Type](src)MyDiff = average[Periods,Type](MyAvg - MyAvg[1])MA = MyAvg + MyDiffreturn MA AS "Shifted SMA",MyAvg AS "Sma"1 user thanked author for this post.
01/16/2024 at 12:43 AM #226403Hello community,
thanks for all these helpful contributions.
I have tested and interestingly came to the conclusion, that the calculation is not
Average[21+1](Close) = Average[22](Close)
Average[21+2](Close) = Average[23](Close)
Average[21+3](Close) = Average[24](Close)like in the Guppy or Rainbow indicators, but
Average[21](Close)+1
Average[21](Close)+2
Average[21](Close)+3So no matter how you call it, but it is working with an increasing offset,
which makes the trend change better visible.And robertogozzi is right, it works like the Ichimoku.
Regarding the negative offset, I think this makes no sense, because a moving average with e.g. -4 periods can only be painted from the moment, the current period (candle) appears.
Will check the coding later.
Thanks and kind regards.
01/16/2024 at 12:11 PM #226419Well Traderfox06, I agree +1 is an offset, but it may not be what you want, as it’s a fixed price, with different effects:
- with indices it will add usually 1 to the current price and should not cause any inconvenience
- with FX pairs, say Eur/Usd, adding 1 to, say 1.0870, will make it 2.0870!!! that’s pretty undesired, I think
- with SHARES, it will add 1 to the current price; if it’s 1000+ that won’t make much difference, while if the stock price is, say 5 or 10, it will make a big difference.
If you want to use a price offset, I suggest that you use 1*PipSize, to let ProOrder do the necessary conversions, without the hassle of taking care of that nuisance.
-
AuthorPosts
Find exclusive trading pro-tools on