Platinum Customer
Joined: 8/12/2009 Posts: 8
|
Hello,
How to write real code based on weekly price/weekly chart? That is, I need to know weekly open, close, high and low price.
Thanks in advance!
Peter
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Any RealCode you write is normally going to use the Time Frame of the Chart. So if the Chart is set to 1-Week, the Open, High, Low and Close will be based on the 1-Week Bars.
In StockFinder 5, it is also possible to create a PriceScripting object using a specified Time Frame and Symbol.
New PriceData method. Get Pricing data for any symbol/timeframe
StockFinder 5.0 READ THIS FIRST
How to Download the BETA!
StockFinder 5.0 Changes from 4.0 - UPDATED
StockFinder Version 5 beta Documentation
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 8/12/2009 Posts: 8
|
Thanks Bruce.
I have StockFinder 5. Here is what I'm trying to do:
I write real code based on daily price, but I need to know the last week's low. For example:
If price.close<"last week's low" then pass
How to get the last week's low?
|
|
Registered User Joined: 10/7/2004 Posts: 886
|
petyu2000 - the condition code you want is:
If price.close < price.Low(1) Then pass
Be sure your chart time frame is set to "weekly."
price.close will give you the latest price for the current bar.
price.low(1) will give you the low of the previous bar. Since your chart is set to "weekly," that will be the low of last week.
Bob
|
|
Platinum Customer
Joined: 8/12/2009 Posts: 8
|
Hello Bruce and Bob,
My challenge is: I need to set my chart to "daily" since the OTHER conditions are based on daily price/volume. Bob noted that in 5.0, we could use a specified Time Frame, but I cannot find the manual for 5.0.
Logically, "last week's low" could be defined as "tf.weekly.price.low(1)", which can be used in codes under daily chart time frame. There must be something like this in 5.0.
Thanks
Peter
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (petyu2000) Bob noted that in 5.0, we could use a specified Time Frame, but I cannot find the manual for 5.0.
Reading my original reply and following the links would help you in this regard as the last referenced topic contains a link to the StockFinder 5 documentation (StockFinder Version 5 beta Documentation).
QUOTE (petyu2000) Logically, "last week's low" could be defined as "tf.weekly.price.low(1)", which can be used in codes under daily chart time frame. There must be something like this in 5.0.
Reading my original reply and following the links would help you in this regard as well as the first referenced topic covers the syntax for doing so using RealCode (New PriceData method. Get Pricing data for any symbol/timeframe).
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Close below Previous Weekly Low
'|******************************************************************
Static customSymbol As PriceScripting
If isFirstBar Then
Dim tf As New WeeklyTimeFrameProvider
tf.NumWeeks = 1
customSymbol = PriceData(CurrentSymbol, tf)
End If
If Price.Last < customSymbol.Low(1) Then Pass
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Platinum Customer
Joined: 8/12/2009 Posts: 8
|
Thank you very much, Bruce!
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce,
i'm trying to code an indicator consisting of two lines(weekly hi and lo) on an intraday chart from monday to friday.
thanks
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please try the following RealCode Indicator for the weekly high.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Weekly High
'|******************************************************************
Static WeeklyHigh As Single
If isFirstBar Then
WeeklyHigh = Single.NaN
Else If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
WeeklyHigh = Price.High
Else
WeeklyHigh = Math.Max(WeeklyHigh, Price.High)
End If
Plot = WeeklyHigh
And the following RealCode Indicator for the weekly low.
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Weekly Low
'|******************************************************************
Static WeeklyLow As Single
If isFirstBar Then
WeeklyLow = Single.NaN
Else If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
WeeklyLow = Price.Low
Else
WeeklyLow = Math.Min(WeeklyLow, Price.Low)
End If
Plot = WeeklyLow
Both indicators should work in daily and shorter time frames, but will probably not degrade gracefully in longer time frames.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce,
i get a continuous line is it possible to have the line begin on monday and end on friday this week only, with a zoom factor for looking back?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
So is the "zoom factor" the number of weeks you want to display?
Are the lines otherwise OK where it is plotting the high and low of the week so far, or do you want a straight line for the highs and lows of the week ever before the high or low was actually hit?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
ha ha...
I wish but thats not possible, here is a code you did for me a while back.
yesterday's high...
Unable to paste, but the idea is the same except the highest price starting from monday will be plotted until friday at which point the plot will shift to the folloing monday, same for the low.
The zoom factor, as i scroll back in time would plot the previous week.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Maybe the following for the Weekly High?
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Prev Weekly High
'|******************************************************************
Static WeeklyHigh(1) As Single
If isFirstBar Then
WeeklyHigh(0) = Single.NaN
WeeklyHigh(1) = Single.NaN
Else If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
WeeklyHigh(1) = WeeklyHigh(0)
WeeklyHigh(0) = Price.High
Else
WeeklyHigh(0) = Math.Max(WeeklyHigh(0), Price.High)
End If
Plot = WeeklyHigh(1)
And the following for the Weekly Low?
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Prev Weekly Low
'|******************************************************************
Static WeeklyLow(1) As Single
If isFirstBar Then
WeeklyLow(0) = Single.NaN
WeeklyLow(1) = Single.NaN
Else If Price.DateValue.DayOfWeek < Price.DateValue(1).DayOfWeek Then
WeeklyLow(1) = WeeklyLow(0)
WeeklyLow(0) = Price.Low
Else
WeeklyLow(0) = Math.Min(WeeklyLow(0), Price.Low)
End If
Plot = WeeklyLow(1)
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce, this the code(yesterday's low) you wrote for me a while back. I'm looking to modify to this weeks hi and lo.
Dim Start(1) As Integer
Start(0) = Price.Bar.Count - 1
Dim Low As Single While
Price.Bar.DateValue(Start(0)).DayOfYear = _
Price.Bar.DateValue(Start(0) - 1).DayOfYear _
AndAlso Start(0) > 0
Start(0) -= 1
End While
Start(0) -= 1
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
While Price.Bar.DateValue(Start(0)).DayOfYear = _
Price.Bar.DateValue(Start(0) - 1).DayOfYear _
AndAlso Start(0) > 0
Start(0) -= 1
If Price.Bar.LowValue(Start(0)) < Low Then
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
End If
End While
If Start(0) > 0 Then
For i As Integer = Start(1) To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), Low)
Next
End If
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please replace everything below the Inherits line in the Class tab with the following for the high.
Sub New
AutoLoop = False
End Sub
Public Overrides function Plot() as System.Single
Dim Start(1) As Integer
Start(0) = Price.Bar.Count - 1
Dim High As Single
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
End While
Start(0) -= 1
Start(1) = Start(0)
High = Price.Bar.HighValue(Start(0))
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
If Price.Bar.HighValue(Start(0)) > High Then
Start(1) = Start(0)
High = Price.Bar.HighValue(Start(0))
End If
End While
If Start(0) > 0 Then
For i As Integer = Start(1) To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), High)
Next
End If
End Function
End Class
And everything below the Inherits line ni the Class tab with the following for the low.
Sub New
AutoLoop = False
End Sub
Public Overrides function Plot() as System.Single
Dim Start(1) As Integer
Start(0) = Price.Bar.Count - 1
Dim Low As Single
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
End While
Start(0) -= 1
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
If Price.Bar.LowValue(Start(0)) < Low Then
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
End If
End While
If Start(0) > 0 Then
For i As Integer = Start(1) To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), Low)
Next
End If
End Function
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
thanks Bruce,
i'm getting the hi and lo from last friday is there any way to have the line start at this weeks hi and lo?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The first While loop is what skips the most recent week (or the most recent day in the code you posted). So you can just take it out.
This would leave the following for high.
Sub New
AutoLoop = False
End Sub
Public Overrides function Plot() as System.Single
Dim Start(1) As Integer
Start(0) = Price.Bar.Count - 1
Dim High As Single
Start(0) -= 1
Start(1) = Start(0)
High = Price.Bar.HighValue(Start(0))
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
If Price.Bar.HighValue(Start(0)) > High Then
Start(1) = Start(0)
High = Price.Bar.HighValue(Start(0))
End If
End While
If Start(0) > 0 Then
For i As Integer = Start(1) To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), High)
Next
End If
End Function
End Class
And the following for the low.
Sub New
AutoLoop = False
End Sub
Public Overrides function Plot() as System.Single
Dim Start(1) As Integer
Start(0) = Price.Bar.Count - 1
Dim Low As Single
Start(0) -= 1
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
While Price.Bar.DateValue(Start(0)).DayOfWeek >= _
Price.Bar.DateValue(Start(0) - 1).DayOfWeek _
AndAlso Start(0) > 0
Start(0) -= 1
If Price.Bar.LowValue(Start(0)) < Low Then
Start(1) = Start(0)
Low = Price.Bar.LowValue(Start(0))
End If
End While
If Start(0) > 0 Then
For i As Integer = Start(1) To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), Low)
Next
End If
End Function
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/5/2010 Posts: 185
|
Bruce,
Thanks for your help, works great !
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |