MA ribbon – calculation error
Forums › ProRealTime English forum › ProBuilder support › MA ribbon – calculation error
- This topic has 2 replies, 2 voices, and was last updated 4 years ago by JMat45.
Tagged: volumeadjustedaverage
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
01/27/2020 at 8:55 AM #117983
I know PRT has an in-built Moving Average Ribbon indicator, but you can’t define the MA type (strange of them not to think of including that), nor can you make the respective MAs Volume-adjusted, i.e. VWAP. So I tried to do it myself. The code below is simple enough and looks right, but results in a peculiar calculation error. Can anyone figure it out? I’m stuck. Thanks in advance.
Variables are: UseVolumeAdjusted = true (Boolean); MAtype = 1 (Exponential); BasePeriod = 8; PeriodIncrement = 2.
123456789101112131415161718192021222324252627282930313233343536Lookback1 = BasePeriodLookback2 = BasePeriod+(1*PeriodIncrement)Lookback3 = BasePeriod+(2*PeriodIncrement)Lookback4 = BasePeriod+(3*PeriodIncrement)Lookback5 = BasePeriod+(4*PeriodIncrement)Lookback6 = BasePeriod+(5*PeriodIncrement)Lookback7 = BasePeriod+(6*PeriodIncrement)Lookback8 = BasePeriod+(7*PeriodIncrement)Lookback9 = BasePeriod+(8*PeriodIncrement)Lookback10 = BasePeriod+(9*PeriodIncrement)IF UseVolumeAdjusted = 1 THENMyMA1 = VolumeAdjustedAverage[Lookback1](Close)MyMA2 = VolumeAdjustedAverage[Lookback2](Close)MyMA3 = VolumeAdjustedAverage[Lookback3](Close)MyMA4 = VolumeAdjustedAverage[Lookback4](Close)MyMA5 = VolumeAdjustedAverage[Lookback5](Close)MyMA6 = VolumeAdjustedAverage[Lookback6](Close)MyMA7 = VolumeAdjustedAverage[Lookback7](Close)MyMA8 = VolumeAdjustedAverage[Lookback8](Close)MyMA9 = VolumeAdjustedAverage[Lookback9](Close)MyMA10 = VolumeAdjustedAverage[Lookback10](Close)ELSIF UseVolumeAdjusted = 0 THENMyMA1 = Average[Lookback1,MAtype](Close)MyMA2 = Average[Lookback2,MAtype](Close)MyMA3 = Average[Lookback3,MAtype](Close)MyMA4 = Average[Lookback4,MAtype](Close)MyMA5 = Average[Lookback5,MAtype](Close)MyMA6 = Average[Lookback6,MAtype](Close)MyMA7 = Average[Lookback7,MAtype](Close)MyMA8 = Average[Lookback8,MAtype](Close)MyMA9 = Average[Lookback9,MAtype](Close)MyMA10 = Average[Lookback10,MAtype](Close)ENDIFRETURN MyMA1 COLOURED (255,255,0) AS "MA1", MyMA2 COLOURED (238,130,238) AS "MA2", MyMA3 COLOURED (64,224,208) AS "MA3", MyMA4 COLOURED (135,206,235) AS "MA4", MyMA5 COLOURED (255,0,0) AS "MA5", MyMA6 COLOURED (160,32,240) AS "MA6", MyMA7 COLOURED (218,112,214) AS "MA7", MyMA8 COLOURED (255,200,0) AS "MA8", MyMA9 COLOURED (255,0,255) AS "MA9", MyMA10 COLOURED (144,238,144) AS "MA10"1 user thanked author for this post.
01/27/2020 at 9:23 AM #117987It works with no error, if you include the calculation into a global condition checking if there is enough bars loaded.
12345678910111213141516171819202122232425262728293031323334353637383940414243UseVolumeAdjusted = 1MAtype = 1BasePeriod = 8PeriodIncrement = 2if barindex>BasePeriod+(9*PeriodIncrement) thenLookback1 = BasePeriodLookback2 = BasePeriod+(1*PeriodIncrement)Lookback3 = BasePeriod+(2*PeriodIncrement)Lookback4 = BasePeriod+(3*PeriodIncrement)Lookback5 = BasePeriod+(4*PeriodIncrement)Lookback6 = BasePeriod+(5*PeriodIncrement)Lookback7 = BasePeriod+(6*PeriodIncrement)Lookback8 = BasePeriod+(7*PeriodIncrement)Lookback9 = BasePeriod+(8*PeriodIncrement)Lookback10 = BasePeriod+(9*PeriodIncrement)IF UseVolumeAdjusted = 1 THENMyMA1 = VolumeAdjustedAverage[Lookback1](Close)MyMA2 = VolumeAdjustedAverage[Lookback2](Close)MyMA3 = VolumeAdjustedAverage[Lookback3](Close)MyMA4 = VolumeAdjustedAverage[Lookback4](Close)MyMA5 = VolumeAdjustedAverage[Lookback5](Close)MyMA6 = VolumeAdjustedAverage[Lookback6](Close)MyMA7 = VolumeAdjustedAverage[Lookback7](Close)MyMA8 = VolumeAdjustedAverage[Lookback8](Close)MyMA9 = VolumeAdjustedAverage[Lookback9](Close)MyMA10 = VolumeAdjustedAverage[Lookback10](Close)ELSIF UseVolumeAdjusted = 0 THENMyMA1 = Average[Lookback1,MAtype](Close)MyMA2 = Average[Lookback2,MAtype](Close)MyMA3 = Average[Lookback3,MAtype](Close)MyMA4 = Average[Lookback4,MAtype](Close)MyMA5 = Average[Lookback5,MAtype](Close)MyMA6 = Average[Lookback6,MAtype](Close)MyMA7 = Average[Lookback7,MAtype](Close)MyMA8 = Average[Lookback8,MAtype](Close)MyMA9 = Average[Lookback9,MAtype](Close)MyMA10 = Average[Lookback10,MAtype](Close)ENDIFendifRETURN MyMA1 COLOURED (255,255,0) AS "MA1", MyMA2 COLOURED (238,130,238) AS "MA2", MyMA3 COLOURED (64,224,208) AS "MA3", MyMA4 COLOURED (135,206,235) AS "MA4", MyMA5 COLOURED (255,0,0) AS "MA5", MyMA6 COLOURED (160,32,240) AS "MA6", MyMA7 COLOURED (218,112,214) AS "MA7", MyMA8 COLOURED (255,200,0) AS "MA8", MyMA9 COLOURED (255,0,255) AS "MA9", MyMA10 COLOURED (144,238,144) AS "MA10"1 user thanked author for this post.
01/27/2020 at 9:25 AM #117989 -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)