#### Rate of Annual Return (ROAR)

Posted By jimbob 9 Years Ago

## Rate of Annual Return (ROAR)

 Message Posted Saturday December 26 2009 I am trying to convert this indicator to RE and it is proving to be a bit hard. I have the code in AmiBroker but RE/.Net seam to be missing Linear Regression functions. Or the ones that are supplied by RE only seams to accept an Iseries.Any ideas on an easy way to do this? Or at least the best way to do this?Thankshttp://forum.incrediblecharts.com/messages/9/316979.html// ROAR Version 1.0Period=52;X=Close;LinReg=( Period * Sum( Cum( 1 ) * X,Period ) -Sum( Cum( 1 ),Period) * Sum( X,Period) ) /(Period * Sum(Cum( 1 )^2,Period ) -Sum( Cum( 1 ),Period )^2 ) * Cum( 1 ) + (MA(X,Period) -MA( Cum(1 ),Period) * (Period * Sum( Cum( 1 ) * X,Period) -Sum( Cum( 1 ),Period ) * Sum( X,Period) ) / (Period *Sum( Cum(1 )^2 ,Period) - Sum( Cum( 1 ),Period )^2 ) );Graph1 = 200*(LinReg-Ref(LinReg,-26))/C;// RAOR Version 2.0TimeFrameSet(inWeekly);RAOR = LinearReg((C-Ref(C,-26))/C*200,4);Plot(raor,"RAOR",colorBlack,0); Posted Sunday December 27 2009 The LinearRegressionQueue class can be used to calculate a linear regression in RightEdge.Thanks,Daniel Posted Sunday December 27 2009 I looked throught the posts briefly on the forum that is the source of this. There is another post that has a simpler implementation, I think. Posted Sunday December 27 2009 Thanks guys. Does the below look correct?I do not have data to compare against to ensure it is correct so I am guessing a bit.` Dim ROAR As UserSeriesDim LinRegQ As LinearRegressionQueue   Public Overloads Overrides Sub Startup()      ' Perform initialization here ROAR = New UserSeries ROAR.ChartSettings.ChartPaneName = "ROAR" LinRegQ = New LinearRegressionQueue(26)   End Sub   Public Overloads Overrides Sub NewBar() ' Put your trading code here If Bars.Count < 30 Then Exit Sub For x As Integer = 0 To 26 LinRegQ.AddValue(Bars.LookBack(x).Close) Next If Int((5200 * LinRegQ.Slope / LinRegQ.Average)) > 20 Then ROAR.Current = Int((5200 * LinRegQ.Slope / LinRegQ.Average)) Else ROAR.Current = 0 End If End Sub` Posted Monday December 28 2009 At a glance, it looks correct. One tip though, we typically used Excel to get our baseline calculations. Here's a good tutorial on the linear regression functions inside of Excel. Posted Wednesday December 30 2009 I would change your NewBar code to the following:LinRegQ.AddValue(Bars.Current.Close)If LinRegQ.Full Then    ROAR.Current = Int((5200 * LinRegQ.Slope / LinRegQ.Average))Else    ROAR.Current = 0End IfBasically, on each new bar you should add a value to the queue.  It automatically includes the previous values you added to it in its calculations, so you only need to add the new value each bar.  The Full property will tell you if you have added enough values to it to "fill it up", in your case this would be 26 values.Daniel