| Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 4/22/2010 Posts: 9
|
Hi, I would like to create an indicator which calculates the normalized linear regression slope (LRS) of Exp moving avg of price (LRS as a % of EMA(price)).How can i do that in real code. I can import LRS into realcode, however cant seem to understand how to feed in EMA(price) as input for LRS calculation.Similarly I would like to create an indicator for normalized LRS of OBV (LRS as a % of OBV). How can i achieve this in Realcode.Thanks.
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (sagargv) Hi, I would like to create an indicator which calculates the normalized linear regression slope (LRS) of Exp moving avg of price (LRS as a % of EMA(price)).How can i do that in real code. I can import LRS into realcode, however cant seem to understand how to feed in EMA(price) as input for LRS calculation.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Linear Regression Slope
'|******************************************************************
'# Period = UserInput.Integer = 30
Static Den As Single
Static Fac As Single
Static Sum As Double
Static SlSum As Double
If isFirstBar Then
Den = Period * (Period ^ 2 - 1) / 12
Fac = (Period - 1) / 2
Sum = 0
SlSum = 0
End If
Sum += Price.Last
If CurrentIndex >= Period Then Sum -= Price.Last(Period)
SlSum += (Fac + 1) * Price.Last - Sum
If CurrentIndex >= Period Then SlSum += Fac * Price.Last(Period)
If CurrentIndex >= Period Then
Plot = 100 * SlSum / Den / Price.XAVGC(Period)
Else
Plot = Single.NaN
End If
QUOTE (sagargv) Similarly I would like to create an indicator for normalized LRS of OBV (LRS as a % of OBV). How can i achieve this in Realcode.Thanks.
No you don't. This would be meaningless both because OBV is a Cumulative Indicator and because OBV can cross through zero.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 4/22/2010 Posts: 9
|
Thanks. Is there a way to 'chain' indicators. For eg: Price -> Exp MA -> LRS : This would essentially give me LRS of Exp MA of Price. Thus I dont have to re-write library indicator code (as above) every time I need to customize further. Thanks again.
|
|
Registered User Joined: 4/22/2010 Posts: 9
|
I am trying to understand the code snippet above. Does this calculate the ExpMA of Price first and then calculate the LRS off the ExpMA? I am not able to spot the calculation of ExpMA of price in code. I can however see that you eventually divide the LRS value with the ExpMA of Price. Plz clarify. Thanks again.
|
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The easiest way to chain Indicators is to just do so on the Chart and then Drag and Drop the results into the RealCode Editor. For example if I took a Moving Average of Price, added Linear Regression Slope of Indicator to the Moving Average and then Dragged and Dropped them both into the Code tab of the RealCode Editor, it might look something like the first two lines of the following RealCode Indicator.
'# MA = chart.MovingAverage
'# LRS = chart.LinearRegressionSlope
Plot = LRS.Value / MA.Value
I had mistaken your intent. I had thought you wanted to use the Exponential Moving Average to normalize a Linear Regression Slope of Price. If the Linear Regression Slope is also of the EMA, I would probably also use a Dragged and Dropped EMA with the original RealCode looking more like the following (the first line is a Dragged and Dropped Moving Average from the Chart that has had the variable name manually changed from MA to Parent):
'# Parent = chart.MovingAverage
'# Period = UserInput.Integer = 30
Static Den As Single
Static Fac As Single
Static Sum As Double
Static SlSum As Double
If isFirstBar Then
Den = Period * (Period ^ 2 - 1) / 12
Fac = (Period - 1) / 2
Sum = 0
SlSum = 0
End If
Sum += Parent.Value
If CurrentIndex >= Period Then Sum -= Parent.Value(Period)
SlSum += (Fac + 1) * Parent.Value - Sum
If CurrentIndex >= Period Then SlSum += Fac * Parent.Value(Period)
If CurrentIndex >= Period Then
Plot = 100 * SlSum / Den / Parent.Value
Else
Plot = Single.NaN
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
|
Guest-1 |