Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

A LR Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
thnkbigr
Posted : Friday, September 3, 2010 3:22:16 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
Bruce,

This is the Auto LR that plots the upper and lower channel at a certain Standard deviation from the mean.

Rather than calculating the SD from the mean how can I adjust this so that it calculates how far the High of each bar deviates from the middle line and plot the upper and lower ch using that SD?

'# Width = UserInput.Single = 1
Static Count(5) As Single
Static Sum(3) As Single
Static Slope(1) As Single
Static SD(1) As Single
Static EndPoint(1) As Single
Static LowSince(1) As Single
If isFirstBar Then
 Count(0) = Single.NaN
 Count(1) = Single.NaN
 Count(2) = 0
 Count(3) = Single.NaN
 Sum(0) = Single.NaN
 Sum(1) = Single.NaN
 Sum(2) = Single.NaN
 LowSince(0) = Single.NaN
 LowSince(1) = Single.NaN
 Slope(1) = Single.NaN
 SD(1) = Single.NaN
 EndPoint(1) = Single.NaN
Else If Price.High > Price.MaxHigh(62, 1) Then
 Count(0) = 1
 Count(1) = 1
 Count(2) = 1
 Count(3) = 1
 Sum(0) = Price.High
 Sum(1) = Price.High ^ 2
 Sum(2) = Price.High
 LowSince(0) = Price.Last
 LowSince(1) = Price.Last
Else
 Count(0) += 1
 Sum(0) += Price.High
 Sum(1) += Price.High ^ 2
 Sum(2) += Count(0) * Price.High
 LowSince(0) = System.Math.Min(LowSince(0), Price.Low)
 LowSince(1) = System.Math.Min(LowSince(1), Price.Last)
End If
If Count(0) >= 2 Then
 Slope(0) = (Sum(2) - ((Count(0) + 1) / 2 * Sum(0))) / (Count(0) * (Count(0) ^ 2 - 1) / 12)
 SD(0) = Width * (((Sum(1) - Sum(0) ^ 2 / Count(0)) / Count(0)) ^ .5)
 EndPoint(0) = Sum(0) / Count(0) + (Count(0) - 1) * Slope(0) / 2  
 If Price.Low = LowSince(0) OrElse _
  Price.Last = LowSince(1) Then
  Count(1) = 0
  Count(2) = 0
  Count(4) = 0
  Count(5) = 0
  Count(3) = Count(0)
  Slope(1) = Slope(0)
  SD(1) = SD(0)
  EndPoint(1) = EndPoint(0)
 Else
  EndPoint(1) += Slope(1)  
 End If
Else
 Slope(0) = 0
 SD(0) = 0
 EndPoint(0) = Price.High
 Slope(1) = 0
 SD(1) = 0
 EndPoint(1) = Price.High
End If
If Count(0) > -1 Then
 OpenValue = SD(1)
 HighValue = Count(0)
 LowValue = Slope(1) / (Sum(0) / Count(0))
 Plot = EndPoint(1)
Else
 OpenValue = Single.NaN
 HighValue = Single.NaN
 LowValue = Single.NaN
 Plot = Single.NaN
End If
Bruce_L
Posted : Friday, September 3, 2010 4:50:29 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I've played with the Indicator and I'm not getting a Plot with Upper and Lower Channels around a centerline. Are you saying you want the width to be based on the Average Deviation of the High from its Linear Regression at the time (what I am suspecting is the "middle line")?

'# Width = UserInput.Single = 1
Static Count(3) As Single
Static Sum(2) As Single
Static Slope(1) As Single
Static LRAD(1) As Single
Static EndPoint(1) As Single
Static LowSince(1) As Single
If isFirstBar Then
    Count(0) = Single.NaN
    Count(1) = Single.NaN
    Count(2) = 0
    Count(3) = Single.NaN
    Sum(0) = Single.NaN
    Sum(1) = Single.NaN
    Sum(2) = Single.NaN
    LowSince(0) = Single.NaN
    LowSince(1) = Single.NaN
    Slope(1) = Single.NaN
    LRAD(1) = Single.NaN
    EndPoint(1) = Single.NaN
Else If Price.High > Price.MaxHigh(62, 1) Then
    Count(0) = 1
    Count(1) = 1
    Count(2) = 1
    Count(3) = 1
    Sum(0) = Price.High
    Sum(1) = 0
    Sum(2) = Price.High
    LowSince(0) = Price.Last
    LowSince(1) = Price.Last
Else
    Count(0) += 1
    Sum(0) += Price.High
    Sum(2) += Count(0) * Price.High
    LowSince(0) = System.Math.Min(LowSince(0), Price.Low)
    LowSince(1) = System.Math.Min(LowSince(1), Price.Last)
End If
If Count(0) >= 2 Then
    Slope(0) = (Sum(2) - ((Count(0) + 1) / 2 * Sum(0))) / (Count(0) * (Count(0) ^ 2 - 1) / 12)
    EndPoint(0) = Sum(0) / Count(0) + (Count(0) - 1) * Slope(0) / 2
    Sum(1) += System.Math.Abs(Price.High - EndPoint(0))
    LRAD(0) = Width * Sum(1) / Count(0) 
    If Price.Low = LowSince(0) OrElse _
        Price.Last = LowSince(1) Then
        Count(1) = 0
        Count(2) = 0
        Count(3) = Count(0)
        Slope(1) = Slope(0)
        LRAD(1) = LRAD(0)
        EndPoint(1) = EndPoint(0)
    Else
        EndPoint(1) += Slope(1) 
    End If
Else
    Slope(0) = 0
    LRAD(0) = 0
    EndPoint(0) = Price.High
    Slope(1) = 0
    LRAD(1) = 0
    EndPoint(1) = Price.High
End If
If Count(0) > -1 Then
    OpenValue = LRAD(1)
    HighValue = Count(0)
    LowValue = Slope(1) / (Sum(0) / Count(0))
    Plot = EndPoint(1)
Else
    OpenValue = Single.NaN
    HighValue = Single.NaN
    LowValue = Single.NaN
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Friday, September 3, 2010 5:00:27 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
Yes

The EndPoint(1) is plotting the Linear Reg which is the middle line

SD(1) is the standard deviation from the mean during the pull back. I like to change that to measure the standard deviation of the high's from the Linear Reg rather than the mean.

This indicator plots the Lin Reg and I plot the SD(1) by plotting the Open value of this indicator then I Plot the Upper and Lower channels as a separate indicator at 1, 1.5 and 2 SD from the EndPoint(1) which the Lin Reg.  
thnkbigr
Posted : Friday, September 3, 2010 5:16:46 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
I see what you did 

Sum(1)  adds all of the differences from the every bars high to the Lin Reg and then LTAD(0) plots some multiple of the avg diff 

Sum(1) += System.Math.Abs(Price.High - EndPoint(0))
    LRAD(0) = Width * Sum(1) / Count(0)  

I'll play with it

thx
Bruce_L
Posted : Friday, September 3, 2010 5:55:02 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
Yes. It's a Linear Regression Absolute Deviation (as opposed to either a Standard Deviation or a Mean Absolute (or Average) Devation) except that it is calculated based on the Linear Regression Endpoint at each point during the series as opposed to looping back through the series at each point to calculate the absolute deviation of each point from the current Linear Regression Line as a whole.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Thursday, September 16, 2010 1:58:24 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207

Bruce 

I need to make one adjustment for sure maybe two to this

You said
 
except that it is calculated based on the Linear Regression Endpoint at each point during the series as opposed to looping back through the series at each point 

This has to done backwards bc the position of the LR changes every time price makes a new low during the pull back. So from the lowest point reached during the pull back or the final low it needs to back and calculate the Absolute Deviation if the Highs from the LR. 

I think this is what we were doing initially when we were calculating the Standard Deviation from the mean.

Bruce_L
Posted : Thursday, September 16, 2010 2:19:25 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
It is going to loop at every Bar making it a lot slower.

'# Width = UserInput.Single = 1
Static Count(3) As Single
Static Sum(2) As Single
Static Slope(1) As Single
Static LRAD(1) As Single
Static EndPoint(1) As Single
Static LowSince(1) As Single
If isFirstBar Then
    Count(0) = Single.NaN
    Count(1) = Single.NaN
    Count(2) = 0
    Count(3) = Single.NaN
    Sum(0) = Single.NaN
    Sum(1) = Single.NaN
    Sum(2) = Single.NaN
    LowSince(0) = Single.NaN
    LowSince(1) = Single.NaN
    Slope(1) = Single.NaN
    LRAD(1) = Single.NaN
    EndPoint(1) = Single.NaN
Else If Price.High > Price.MaxHigh(62, 1) Then
    Count(0) = 1
    Count(1) = 1
    Count(2) = 1
    Count(3) = 1
    Sum(0) = Price.High
    Sum(1) = 0
    Sum(2) = Price.High
    LowSince(0) = Price.Last
    LowSince(1) = Price.Last
Else
    Count(0) += 1
    Sum(0) += Price.High
    Sum(2) += Count(0) * Price.High
    LowSince(0) = System.Math.Min(LowSince(0), Price.Low)
    LowSince(1) = System.Math.Min(LowSince(1), Price.Last)
End If
If Count(0) >= 2 Then
    Slope(0) = (Sum(2) - ((Count(0) + 1) / 2 * Sum(0))) / (Count(0) * (Count(0) ^ 2 - 1) / 12)
    EndPoint(0) = Sum(0) / Count(0) + (Count(0) - 1) * Slope(0) / 2
    Sum(1) = 0
    For i As Integer = 0 To Count(0) - 1
        Sum(1) += System.Math.Abs(Price.High(i) - EndPoint(0) + i * Slope(0))
    Next
    LRAD(0) = Width * Sum(1) / Count(0)
    If Price.Low = LowSince(0) OrElse _
        Price.Last = LowSince(1) Then
        Count(1) = 0
        Count(2) = 0
        Count(3) = Count(0)
        Slope(1) = Slope(0)
        LRAD(1) = LRAD(0)
        EndPoint(1) = EndPoint(0)
    Else
        EndPoint(1) += Slope(1) 
    End If
Else
    Slope(0) = 0
    LRAD(0) = 0
    EndPoint(0) = Price.High
    Slope(1) = 0
    LRAD(1) = 0
    EndPoint(1) = Price.High
End If
If Count(0) > -1 Then
    OpenValue = LRAD(1)
    HighValue = Count(0)
    LowValue = Slope(1) / (Sum(0) / Count(0))
    Plot = EndPoint(1)
Else
    OpenValue = Single.NaN
    HighValue = Single.NaN
    LowValue = Single.NaN
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Monday, September 20, 2010 2:48:56 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
Bruce,

I am gone continue that SD subject from the Rounding topic here if you don't mind.

Honestly I am lost. I had no idea there is so much to it but I will take a course on this bc I have to understand it. My appologies for the trouble.

All I was trying to do is to learn the steps as to how to plot SD.

If you look under this topic in the 1st  RC, SD(0) is plotting the SD of the Highs from the mean.

In the final RC LRAD(0) is plotting the Average Absolute Deviation of the Highs from the LR line.

I've spaced bar through a lot of stocks and there are number of pull backs that the RC's above don't do a good job.  

Below I have tried to plot the SD of the Absolute deviation(difference) from the Highs to the LR line. All of my adjustments are highlighted in blue.

I might be way off but at least I tried.  

SD(0) in blue is from what I understood from your original RC that I've pasted in Friday, September 03, 2010 3:22:16 PM in this post. The 1st RC when you are plottind SD of the highs from the Mean.

SD(2) in purple is from what I understood from your post on
Thursday, September 16, 2010 3:44:35 PM 
in the Rounding Topic.

Again my appologies for the trouble I had no idea there is so much to this.


'# Width = UserInput.Single = 1
Static Count(3) As Single
Static Sum(4) As Single
Static Slope(1) As Single
Static LRAD(1) As Single
Static SD(3) As Single
Static EndPoint(1) As Single
Static LowSince(1) As Single
If isFirstBar Then
 Count(0) = Single.NaN
 Count(1) = Single.NaN
 Count(2) = 0
 Count(3) = Single.NaN
 Sum(0) = Single.NaN
 Sum(1) = Single.NaN
 Sum(2) = Single.NaN
 Sum(3) = Single.NaN
 Sum(4) = Single.NaN
 LowSince(0) = Single.NaN
 LowSince(1) = Single.NaN
 Slope(1) = Single.NaN
 LRAD(1) = Single.NaN
 SD(3) = Single.NaN
 EndPoint(1) = Single.NaN
Else If Price.High > Price.MaxHigh(62, 1) Then
 Count(0) = 1
 Count(1) = 1
 Count(2) = 1
 Count(3) = 1
 Sum(0) = Price.High
 Sum(1) = 0
 Sum(2) = Price.High
 Sum(3) = 0
 Sum(4) = 0
 LowSince(0) = Price.Last
 LowSince(1) = Price.Last
Else
 Count(0) += 1
 Sum(0) += Price.High
 Sum(2) += Count(0) * Price.High 
 LowSince(0) = System.Math.Min(LowSince(0), Price.Low)
 LowSince(1) = System.Math.Min(LowSince(1), Price.Last)
End If
If Count(0) >= 2 Then
 Slope(0) = (Sum(2) - ((Count(0) + 1) / 2 * Sum(0))) / (Count(0) * (Count(0) ^ 2 - 1) / 12)
 EndPoint(0) = Sum(0) / Count(0) + (Count(0) - 1) * Slope(0) / 2
 Sum(1) = 0
 Sum(3) = 0
 Sum(4) = 0
 For i As Integer = 0 To Count(0) - 1
  Sum(1) += System.Math.Abs(Price.High(i) - EndPoint(0) + i * Slope(0))
  Sum(3) = System.Math.Abs(Price.High(i) - EndPoint(0) + i * Slope(0)) 
  Sum(4) += Sum(3) ^ 2
 Next
 LRAD(0) = Width * Sum(1) / Count(0)
 SD(0) = Width * (((Sum(4) - Sum(3) ^ 2 / Count(0)) / Count(0)) ^ .5)
 SD(2) = Width * ((Sum(4) - (Count(0) * LRAD(0) ^ 2)) / Count(0))
 If Price.Low = LowSince(0) OrElse _
  Price.Last = LowSince(1) Then
  Count(1) = 0
  Count(2) = 0
  Count(3) = Count(0)
  Slope(1) = Slope(0)
  LRAD(1) = LRAD(0)
  SD(1) = SD(0)
  SD(3) = SD(2)
  EndPoint(1) = EndPoint(0)
 Else
  EndPoint(1) += Slope(1) 
 End If
Else
 Slope(0) = 0
 LRAD(0) = 0
 SD(0) = 0
 SD(2) = 0
 EndPoint(0) = Price.High
 Slope(1) = 0
 LRAD(1) = 0
 SD(1) = 0
 SD(3) = 0
 EndPoint(1) = Price.High
End If
If Count(0) > -1 Then
 OpenValue = SD(1)
 HighValue = SD(3)
 LowValue = Slope(1) / (Sum(0) / Count(0))
 Plot = EndPoint(1)
Else
 OpenValue = Single.NaN
 HighValue = Single.NaN
 LowValue = Single.NaN
 Plot = Single.NaN
End If

jas0501
Posted : Monday, September 20, 2010 3:53:04 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
Bollinger bands plot standard deviation. So why not plot the value you want, then apply bollinger bands to it?

thnkbigr
Posted : Monday, September 20, 2010 4:15:11 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
BB has nothing to do with this

The Length of the Pull Back is diff from sttovk to stock which is measured by Count(0) in this RC. BB you have to put in a parameter.

BB is plotting the SD from the mean which is what the original RC does( The 1st RC in this topic) 

I am trying to plot the SD of the Absolute Difference from the High of each bar to the LR Line.   
Bruce_L
Posted : Monday, September 20, 2010 4:37:56 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
jas0501,
Because the SD Period varies.

thnkbigr,
If you really want the Standard Devation of the Absolute Devation from the Linear Regression of the High, then maybe the following (really it is getting way to complicated for me)?

'# Width = UserInput.Single = 1
Static Count(3) As Single
Static Sum(3) As Single
Static Slope(1) As Single
Static SDoADfLR(1) As Single
Static EndPoint(1) As Single
Static LowSince(1) As Single
If isFirstBar Then
    Count(0) = Single.NaN
    Count(1) = Single.NaN
    Count(2) = 0
    Count(3) = Single.NaN
    Sum(0) = Single.NaN
    Sum(1) = Single.NaN
    Sum(2) = Single.NaN
    LowSince(0) = Single.NaN
    LowSince(1) = Single.NaN
    Slope(1) = Single.NaN
    SDoADfLR(1) = Single.NaN
    EndPoint(1) = Single.NaN
Else If Price.High > Price.MaxHigh(62, 1) Then
    Count(0) = 1
    Count(1) = 1
    Count(2) = 1
    Count(3) = 1
    Sum(0) = Price.High
    Sum(1) = 0
    Sum(2) = Price.High
    LowSince(0) = Price.Last
    LowSince(1) = Price.Last
Else
    Count(0) += 1
    Sum(0) += Price.High
    Sum(2) += Count(0) * Price.High
    LowSince(0) = System.Math.Min(LowSince(0), Price.Low)
    LowSince(1) = System.Math.Min(LowSince(1), Price.Last)
End If
If Count(0) >= 2 Then
    Slope(0) = (Sum(2) - ((Count(0) + 1) / 2 * Sum(0))) / (Count(0) * (Count(0) ^ 2 - 1) / 12)
    EndPoint(0) = Sum(0) / Count(0) + (Count(0) - 1) * Slope(0) / 2
    Sum(1) = 0
    Sum(3) = 0
    For i As Integer = 0 To Count(0) - 1
        Sum(1) += System.Math.Abs(Price.High(i) - EndPoint(0) + i * Slope(0))
        Sum(3) += System.Math.Abs(Price.High(i) - EndPoint(0) + i * Slope(0)) ^ 2
    Next
    SDoADfLR(0) = Width * (((Sum(3) - Sum(1) ^ 2 / Count(0)) / Count(0)) ^ .5)
    If Price.Low = LowSince(0) OrElse _
        Price.Last = LowSince(1) Then
        Count(1) = 0
        Count(2) = 0
        Count(3) = Count(0)
        Slope(1) = Slope(0)
        SDoADfLR(1) = SDoADfLR(0)
        EndPoint(1) = EndPoint(0)
    Else
        EndPoint(1) += Slope(1)
    End If
Else
    Slope(0) = 0
    SDoADfLR(0) = 0
    EndPoint(0) = Price.High
    Slope(1) = 0
    SDoADfLR(1) = 0
    EndPoint(1) = Price.High
End If
If Count(0) > -1 Then
    OpenValue = SDoADfLR(1)
    HighValue = Count(0)
    LowValue = Slope(1) / (Sum(0) / Count(0))
    Plot = EndPoint(1)
Else
    OpenValue = Single.NaN
    HighValue = Single.NaN
    LowValue = Single.NaN
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
thnkbigr
Posted : Monday, September 20, 2010 6:14:29 PM
Platinum Customer Platinum Customer

Joined: 3/31/2006
Posts: 3,207
Thanks a TON

Bruce_L
Posted : Monday, September 20, 2010 7:16:40 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.