Platinum Customer
Joined: 1/30/2005 Posts: 135
|
I am using the following for 14 bar daily range. How do I convert to weekly?
'# Period = UserInput.Integer = 14
Static SumC As Single
If isFirstBar Then
SumC = 0
End If
SumC += Price.High - Price.Low
If CurrentIndex >= Period Then
SumC -= Price.High(Period) - Price.Low(Period)
End If
If CurrentIndex >= Period - 1 Then
plot = SumC / Period
Else
Plot = Single.NaN
End If
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You can just use your RealCode as is if the time frame is already set to weekly.
If the time frame is both shorter than weekly and evenly divisible into the calendar week, then you can use the following RealCode Indicator.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Weekly Range
'|******************************************************************
'# Period = UserInput.Integer = 14
Static sumRange As Single
Static weekHigh As New List(Of Single)
Static weekLow As New List(Of Single)
If isFirstBar Then
sumRange = 0
weekHigh.Clear
weekLow.Clear
End If
If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
weekHigh.Insert(0, Price.High)
weekLow.Insert(0, Price.Low)
If weekHigh.Count > 1 Then
sumRange += weekHigh(1) - weekLow(1)
If weekHigh.Count = Period + 1 Then
sumRange -= weekHigh(Period) - weekLow(Period)
weekHigh.RemoveAt(Period)
weekLow.RemoveAt(Period)
End If
End If
Else If weekHigh.Count > 0 Then
weekHigh(0) = System.Math.Max(weekHigh(0), Price.High)
weekLow(0) = System.Math.Min(weekLow(0), Price.Low)
End If
If weekHigh.Count = Period Then
Plot = (sumRange + weekHigh(0) - weekLow(0)) / Period
Else
Plot = Single.NaN
End If
If isLastBar Then
weekHigh.Clear
weekLow.Clear
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
Platinum Customer
Joined: 1/30/2005 Posts: 135
|
Thanks for your help Bruce.
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|