Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 10/7/2004 Posts: 56
|
How do I go about creating a horizontal line that begins at today's time of open (i.e. the line does not go accross the whole pane), extending to the right end of my intraday chart
and
the value would be determined as a certain userinputted % away from yesterday's close.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Please try creating a RealCode Indicator and replacing everything below the Inherits line in the Class tab with the following:
RealCode for Real People: Indicators
Sub New
AutoLoop = False
'# Percent = UserInput.Single = 0
End Sub
Public Overrides Function Plot() As System.Single
Dim Start As Integer = Price.Bar.Count - 1
Dim Close As Single = Price.Bar.Value(Start)
While Price.Bar.DateValue(Start).DayOfYear = Price.Bar.DateValue(Start - 1).DayOfYear
Start -= 1
Close = Price.Bar.Value(Start - 1)
End While
For i As Integer = Start To Price.Bar.Count - 1
AddToOutput(Price.Bar.DateValue(i), Close * (1 + Percent / 100))
Next
End Function
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 56
|
Bruce, could you please comment on the code? It works perfectly, I'd just like to understand how and why.
I add my questions to the code:
Sub New
AutoLoop = False
'# Percent = UserInput.Single = 0
End Sub
Public Overrides Function Plot() As System.Single
Dim Start As Integer = Price.Bar.Count - 1
Dim Close As Single = Price.Bar.Value(Start)
While Price.Bar.DateValue(Start).DayOfYear = Price.Bar.DateValue(Start - 1).DayOfYear
Start -= 1 what does the "-" singn before the "=" sign mean? And what doeas this line do?
Close = Price.Bar.Value(Start - 1)
End While
For i As Integer = Start To Price.Bar.Count - 1 Can this be written as "... Start to Start - 1"? If yes then why it isn't written that way?
AddToOutput(Price.Bar.DateValue(i), Close * (1 + Percent / 100)) Close has been defined earlier in the code as: Dim Close As Single = Price.Bar.Value(Start) and then as: Close = Price.Bar.Value(Start - 1) Which Close is being used in this line?
Next
End Function
End Class
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (Nelane) Start -= 1 what does the "-" singn before the "=" sign mean? And what doeas this line do?
It subtracts 1 from Start. It is just a different way to write:
Start = Start - 1
QUOTE (Nelane) For i As Integer = Start To Price.Bar.Count - 1 Can this be written as "... Start to Start - 1"? If yes then why it isn't written that way?
No, it can't. Start has been incrementing backwards while searching for the first Bar of the most recent Trading Day. So once the While Loop is complete, Start is the first Bar of the Trading Day and Price.Bar.Count - 1 is the Last Price Bar available.
QUOTE (Nelane) AddToOutput(Price.Bar.DateValue(i), Close * (1 + Percent / 100)) Close has been defined earlier in the code as: Dim Close As Single = Price.Bar.Value(Start) and then as: Close = Price.Bar.Value(Start - 1) Which Close is being used in this line?
By the time it gets to this line it is using Close = Price.bar.Value(Start -1) where Start is the first Bar of the current Trading Day and Start - 1 is the last Bar of the previous Trading Day.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |