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 |

Draw a line % from yesterdays close Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Nelane
Posted : Monday, September 27, 2010 2:11:06 PM
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.
Bruce_L
Posted : Monday, September 27, 2010 4:16:48 PM


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
Nelane
Posted : Tuesday, September 28, 2010 3:41:59 PM
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
Bruce_L
Posted : Tuesday, September 28, 2010 3:47:57 PM


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
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.