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 |

14 bar weekly range Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
maljester
Posted : Friday, March 2, 2018 2:27:12 PM
Platinum Customer 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
Bruce_L
Posted : Friday, March 2, 2018 4:13:36 PM


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
maljester
Posted : Friday, March 2, 2018 4:42:52 PM
Platinum Customer Platinum Customer

Joined: 1/30/2005
Posts: 135

Thanks for your help Bruce.

Bruce_L
Posted : Monday, March 5, 2018 10:14:58 AM


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.