Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Condition or Indicator... Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jimmyg
Posted : Wednesday, December 8, 2010 1:24:57 PM
Registered User
Joined: 11/10/2010
Posts: 54
I'd like to create a indicator or condition... not sure which, but here's what I want....

First, I'm using 5 minute charts... intraday platinum....

I want to be able to sort the watchlist (intraday) for stocks where the volume and price are both moving up during the day.

I think what I really want to create is a buy score indicator...  so far I've been creating some RC conditions to go on my charts, but I haven't gotten into indicators yet.

I'd like to use volume surge (VS.last > 2) etc... to accumulate a POINT SCORE... MY point score.

Then use the point score to sort the watchlist with... 

What are your thoughts?

Thanks, 

Jimg

Bruce_L
Posted : Wednesday, December 8, 2010 1:48:38 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jimmyg)
I want to be able to sort the watchlist (intraday) for stocks where the volume and price are both moving up during the day.

This reads like Conditions being used in a Filter.

Filtering Lists
Creating Conditions
Writing Conditions in RealCode

QUOTE (jimmyg)
I think what I really want to create is a buy score indicator...  so far I've been creating some RC conditions to go on my charts, but I haven't gotten into indicators yet.

I'd like to use volume surge (VS.last > 2) etc... to accumulate a POINT SCORE... MY point score.

Then use the point score to sort the watchlist with...

This reads like a RealCode Indicator being used as a Sort.

Sortable Columns from Indicators
RealCode for Real People: Indicators

You could add as many Conditions as you want to create something like the following and assign your own values to add for each Condition.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Point Score
'|******************************************************************
'# VS = indicator.Library.Volume Surge
Dim PointScore As Single = 0
If VS.Value > 2 Then PointScore += 1
Plot = PointScore

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Wednesday, December 8, 2010 2:03:11 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce, 

Thanks!    That's what I was looking for... I'll work on it...

Many Thanks.

Jimg
jimmyg
Posted : Wednesday, December 8, 2010 7:13:08 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce, 

Let's say I want a running total... an accumulator that starts the day at zero... and accumulates points thru the day....  is that possible?  

I'd like to limit the bars to look at just today in order to calculate... and each time one of my chart conditions (buy signals) pops on the chart, accumulate points for that signal....

I can see how to copy the "condition code" to add points, so ...
? 1.  how to accumulate from 1 bar to the next???
? 2.  How to just look at today's bars for the process as a whole... for both speed and accuracy.

Thanks in advance,

JimG
jimmyg
Posted : Wednesday, December 8, 2010 8:29:25 PM
Registered User
Joined: 11/10/2010
Posts: 54
I got ? 1.  with the Static declaration.. now how to start at today's first bar hopefully to avoid many un-needed iterations of code???????

Again, Thanks in advance,

JimG
Bruce_L
Posted : Thursday, December 9, 2010 8:30:25 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You can reset your PointScore by checking for a change in the date and setting PointScore to 0 when this happens. If you output Single.NaN until you are sure you are at the start of a day, the WatchList Columns will only use one day of data in their calculations.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Cumulative Point Score with Reset
'|******************************************************************
'# VS = indicator.Library.Volume Surge
Static PointScore As Single
If isFirstBar Then
    PointScore = Single.NaN
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
    PointScore = 0
End If
If VS.Value > 2 Then PointScore += 1
Plot = PointScore

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Thursday, December 9, 2010 3:36:02 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce, 

Many Thanks!!!   This is the kind of structure I'm looking for.

I'm concerned about efficiency though....

Is there a " system.date.today"  function that could be used to skip calculations on days past?

JimG
jimmyg
Posted : Thursday, December 9, 2010 3:52:54 PM
Registered User
Joined: 11/10/2010
Posts: 54

Perhaps, I need to get a book.  I think I'm wanting to start the calculations on the "Computer Date".... 

Also want to do some special test for the 1st, 2nd and 3rd bars of TODAY.

Your Help is greatly appreciated!!!!

Thanks,

JimG

Bruce_L
Posted : Thursday, December 9, 2010 4:05:01 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I suppose you could check for the Date and only Plot the most recent Date:

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Cumulative Point Score Last Day Only
'|******************************************************************
'# VS = indicator.Library.Volume Surge
Static PointScore As Single
Static Last As Integer
If isFirstBar Then
    PointScore = 0
    Last = Price.Bar.Count - 1
End If
If Price.DateValue.Date = Price.Bar.DateValue(Last).Date Then
    If VS.Value > 2 Then
        PointScore += 1
    End If
    Plot = PointScore
Else
    Plot = Single.NaN
End If

I don't know how much difference it will make on the Chart however and I don't think it is going to normally work as a WatchList Column without using the following line:

'# Cumulative

This would force it to use all of the data however and probably make it slower when used as a WatchList Column than the version provided initially.

You could use manual looping in the Class tab by setting AutoLoop = False (check out the RealCode Reference) to loop from the end towards the beginning of the find the Start of the Day and then loop forward from there to avoid the AutoLoop through all of the Bars, but this is more complicated from a programming standpoint.

The built in AutoLoop synchronizes any imported Indicators with Price and Volume even if they have a different number of Bars. Working outside the AutoLoop means you would need to manually synchronize any imported Indicators with Price and Volume yourself. And the extra work won't necessarily get around needing to use '# Cumulative to get it to work correctly as a WatchList Column.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Thursday, December 9, 2010 5:16:03 PM
Registered User
Joined: 11/10/2010
Posts: 54

Bruce, 

AGAIN,  Thanks for your help!

I must keep in mind, that I mainly need (i think) to use this as a watchlist column to sort stocks with the highest point score to the top of the watchlist.... as early in the day as possible.  

So, I'm not at all interrested in looking at a "MY Score Indicator"  as a pane on my chart..... that would be a "PAIN".... pun intended.....

So, as I go on developing my daily point score calculation.... pointscore +=1  .....   I'm wondering what the best construct is to use as a watchlist column.....

Maybe I need to go to CLASS... pun both intended and not intended...

So,  would a class object be what I really want to use in the watchlist to sort by?

Also, please recommend further reading than the RealCode Reference document.... if possible.   Is there a realcode Programming Manual available???


Thanks,

JimG

Bruce_L
Posted : Friday, December 10, 2010 9:04:16 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The RealCode Programmers Reference and RealCode API together comprise the documentation of the StockFinder specific elements of RealCode. They have examples of programs, but they aren't intended to teach programming or document Visual Basic .NET as a whole.

The two RealCode videos refenced in my first response in this topic can also be useful (especially for non-programmers).

Learning about VB beyond the RealCode specific stuff could be quite useful however. There are books, websites and even classes that you can take about VB.NET that might help you write better RealCode.

Programming in the Class tab is a good skill to have. It allows you to avoid the AutoLoop and use your own looping structures that may not need to access every Price Bar in their calculations. This can also avoid some of the overhead created by the AutoLoop doing synchronization and other tasks for you to make writing Code tab RealCode a bit easier for the non-programmer than writing Class tab RealCode.

Keeping both all of that and the fact that I am not a programmer in mind, the RealCode structure provided in my Thursday, December 09, 2010 8:30:25 AM ET post might still be the more efficient route (although you could create a similar structure in the Class tab with manual looping if you are will to do your own synchronization). As stated in that response, the WatchList Columns will only use one day of data in their calculations because we return Single.NaN instead of a Value until the calculations are valid (well there might be a small pad added, but not much).

This is because the WatchList Columns attempt to automatically determine the minimum amount of data required in order to make their calculations more efficient. They do so by checking for the number of bars required before the Indicator or Condition returns an actual result. If an Indicator returns Single.NaN or a Condition uses SetIndexInvalid to avoid returning either True or False, the WatchList Column interprets this as meaning there isn't enough data for the result to be valid.

This allows you to create an Indicator or Condition that can dynamically communicate to the WatchList Columns the amount of data required for its calculations.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Friday, December 10, 2010 1:13:07 PM
Registered User
Joined: 11/10/2010
Posts: 54

Bruce,

Thanks for your help!!!!  

Please take a look at the following....

'|******************************************************************
'|*** Indicator:My Buy Score TEST Indicator
'|***
'|******************************************************************
'# VS = indicator.Library.Volume Surge

Static PointScore As Single
Static BARNUM As Single

If isFirstBar Then
 PointScore = Single.NaN
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 PointScore = 0
 BARNUM = 0
End If
BARNUM += 1

'=============  FIRST BAR CALCULATIONS  ======================
If BARNUM = 1

 '..... ONLY GIVE POINTS TO STOCKS THAT ARE GOING UP IN PRICE FROM YESTERDAY
 If PRICE.Last > PRICE.LAST(1) Then
  POINTSCORE += 1
  
  '...VOLUME SURGE POINTS....
  If VS.Value > 1 Then PointScore += VS.Value
  
 End If
End If
'END OF FIRST BAR CALCULATIONS ===============================


BARNUM += 1
Plot = PointScore

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I have this indicator on a 5 min chart ...     and this code (I think) should only prioduce results for the first 5 min. bar for today...

I'm trying to verify the numbers ...
Let's look at symbol DHX....

First bar values in the data box :

Volume Surge                               26.9x
MovAvg30                                          1.7x

My 1st 5min Indicator value        57.40

I am puzzled...    Looking at the code and the values, I would expect to see an indicator value of 27.9...

Where am I off here????

Thanks,

jimg
   

Bruce_L
Posted : Friday, December 10, 2010 1:33:31 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I suspect you have different settings for the Volume Surge on your Chart (which you appear to have changed) and the Volume Surge being used in your RealCode (which appears to be using the default settings). I say this because the Volume Surge settings I get on the Chart are 56.4x for the 12/10/2010 9:35 AM Bar when I do not adjust its settings.

You could link the Indicator to the Chart by Dragging and Dropping the Charted Indicator into the RealCode Editor to create the '# VS = line. This would allow you to adjust the settings on the Chart and have the other Indicator match. The current version uses a Library version of Volume Surge which is independent of the Chart. Since they are not linked, you need to manually make sure the settings match.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Friday, December 10, 2010 2:34:05 PM
Registered User
Joined: 11/10/2010
Posts: 54
AWESOME..... 

I was up till 3:00 AM this morning trying to figure this out....

SOooo ,  the code is good... but somehow, I had the Volume Surge Indicator messed up on my chart....

At least I know I'm on the right track.... Look at DHX    NOW

AndAlso....   the concept of "linked to the chart" sounds like something I'd want to avoid in future RC indicators that I might construct....   

I do have those Pivot Points of the chart though, and I'd like to be able to test values against them... PP.value, R1.value.... etc....     When I tried to use those last night, I WAS WARNED by the compiler, and I crashed the SF 5 pgm.   Ended up deleting the indicator file from the C: drive and re-wrote it as above.  

Any thoughts on this?


Your help is GREATLY APPRECIATED!!!!!!!

Thanks,

JIMG


Bruce_L
Posted : Friday, December 10, 2010 3:04:02 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
There are lots of different Pivot Point Indicators available. If you are using a version that draws straight lines across the the entire Chart based on yesterday's Prices, it is great for visualization, but bad for things like backtesting or including in another Indicator. The Indicator is "psychic" and uses future data for everything except the current Bar.

What you would want to use is an Indicator that is "moving" and produces different Values for each day.

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Pivot Point
'|******************************************************************
Static DayHigh(1) As Single
Static DayLow(1) As Single
Static DayClose(1) As Single
If isFirstBar Then
    For i As Integer = 0 To 1
        DayHigh(i) = Single.NaN
        DayLow(i) = Single.NaN
        DayClose(i) = Single.NaN
    Next
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
    DayHigh(1) = DayHigh(0)
    DayHigh(0) = Price.High
    DayLow(1) = DayLow(0)
    DayLow(0) = Price.Low
    DayClose(1) = Price.Last(1)
Else
    DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
    DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
End If
Plot = (DayHigh(1) + DayLow(1) + DayClose(1)) / 3

It should probably be noted that the Pivot Point calculations require an extra day of data compared to what you are calculating currently. I don't know the exact details of what you are trying to create, but this might mean you want to delay the output of your Indicator by an extra day as well. You might even consider incorporating the Pivot Point calculations into the Indicator directly instead of creating a Pivot Point Indicator and then importing it (this would reduce the number of passes through the data).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Monday, December 13, 2010 12:12:30 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce,

Here's what I have envisioned.... At the first of the day, during the 1st 30 minutes of trading....  I want to isolate stocks based on whatever I can program into this THING.... (THING being a condition, indicator, or class... etc.)..

The only way I know of... to isolate these stocks is through manipulating a watchlist.  So whatever this THING is,... It has to be able to work consistently with a watchlist.   I'm using the Russell 2000.

Please Correct me If I'm wrong so far.... I want to manipulate watchlists to isolate stocks that exhibit some behavior.  And as always with programming, Speed is of major concern.

So, to isolate these stocks, I'd like to be able to use whatever data is available... 

So far, I've been constraining this to 5 min bars of (today's) data, which is ok... so far... but I do need access to yesterday's data to do pivot points... etc.

This brings into context the idea of Daily Data Bars.... And my code (and I) get lost here....in this indicator.
EX: I need yesterday's high, low, close, and open... values to do calculations for variables PP, R1, etc.

Of course, there are lots and lots of other things that might factor into this Score Value, that I am trying to assign to each stock in the watchlist....   So the watchlist has to be able to use the code that I give it (creating a data column) with consistency and speed.

What are your thoughts so far? ...
  

 
Bruce_L
Posted : Monday, December 13, 2010 12:50:48 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jimmyg)
The only way I know of... to isolate these stocks is through manipulating a watchlist.  So whatever this THING is,... It has to be able to work consistently with a watchlist.   I'm using the Russell 2000.

Please Correct me If I'm wrong so far.... I want to manipulate watchlists to isolate stocks that exhibit some behavior.  And as always with programming, Speed is of major concern.

That why you want to use the structure that outputs Single.NaN until the data is valid.

QUOTE (jimmyg)
So far, I've been constraining this to 5 min bars of (today's) data, which is ok... so far... but I do need access to yesterday's data to do pivot points... etc.

This brings into context the idea of Daily Data Bars.... And my code (and I) get lost here....in this indicator.
EX: I need yesterday's high, low, close, and open... values to do calculations for variables PP, R1, etc.

The RealCode Indicator in my Friday, December 10, 2010 3:04:02 PM ET post calculates Daily Bars using any Intraday Bar Interval as its base. The Pivot Point is Daily if the Bar Interval is 5-Minutes or 1-Hour, it doesn't matter.

This RealCode uses the same basic structure that was used to reset the Indicator at the start of each Day to calculate the Daily Values used in the calculation of the Pivot Point. A version of the RealCode provided in my Thursday, December 09, 2010 8:30:25 AM ET post that also stores the Open, High, Low and Close of both the previous Day and up until the currently calculating Bar in the current Day could be written as (it doesn't actually use these Values, they are just stored for whatever use to which you wish to put them):

'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Cumulative Point Score
'|******************************************************************
'# VS = indicator.Library.Volume Surge
Static PointScore As Single
Static DayOpen(1) As Single
Static DayHigh(1) As Single
Static DayLow(1) As Single
Static DayClose(1) As Single
Static DayCount As Integer
If isFirstBar Then
    PointScore = Single.NaN
    For i As Integer = 0 To 1
        DayOpen(i) = Single.NaN
        DayHigh(i) = Single.NaN
        DayLow(i) = Single.NaN
        DayClose(i) = Single.NaN
    Next
    DayCount = 0
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
    PointScore = 0
    DayOpen(1) = DayOpen(0)
    DayOpen(0) = Price.Open
    DayHigh(1) = DayHigh(0)
    DayHigh(0) = Price.High
    DayLow(1) = DayLow(0)
    DayLow(0) = Price.Low
    DayClose(0) = Price.Last
    DayClose(1) = Price.Last(1)
    DayCount += 1
Else
    DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
    DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
    DayClose(0) = Price.Last
End If
If DayCount >= 2 Then
    If VS.Value > 2 Then
        PointScore += 1
    End If
    Plot = PointScore
Else
    Plot = Single.NaN
End If

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Monday, December 13, 2010 2:08:35 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce,

In this last example... I would start building my point score inside the ....

If DayCount >= 2 Then

            Do PointScore calculation here...
            Plot PointScore

Else
    Plot = Single.NaN
End If
   
So... Questions:

1.  Wouldn't this calculate for each day of data in the data base...   If so, I think we need to limit to...

If DayCount =   ????? today

2.  Would this (indicator) update the score for each stock in the Watchlist if it was an existing watchlist column at the beginning of the day?

3.  If I bring up another watch list and add this indicator as a data column, (1)  would it populate the values for each stock correctly,  and (2) would the watchlist be able to sort based on the data column?


I'm also starting to read about Classes and wondering if I need to be incorporating this logic into a class object .... If it would work better....  

What do you think?


Bruce_L
Posted : Monday, December 13, 2010 2:58:41 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jimmyg)
Wouldn't this calculate for each day of data in the data base...

On the Chart, yes, as a WatchList Column no.

The WatchList Columns use the fact that PointScore isn't output until it is Valid to determine the minimum amount of data required.

QUOTE (jimmyg)
If so, I think we need to limit to...

If DayCount =   ????? today

No. Seriously don't.

If you start returning data at the first place where the data is valid, the WatchList Columns can correctly calculate the minimum amount of data required.

If you start returning data just on the last day, the WatchList Columns will think you need all of the data to calculate the result because they assume that everything prior to the last day didn't output results because there wasn't enough data for the results to be valid (and they probably won't calculate correctly at all as WatchList Columns).

QUOTE (jimmyg)
Would this (indicator) update the score for each stock in the Watchlist if it was an existing watchlist column at the beginning of the day?

Yes, as the WatchList Column will use the most recent data available every time it is calculated.

QUOTE (jimmyg)
If I bring up another watch list and add this indicator as a data column, (1)  would it populate the values for each stock correctly,  and (2) would the watchlist be able to sort based on the data column?

The WatchList Column (and any Sorts based on the WatchList Column) will use whatever WatchList is being displayed and will re-calculate if you change WatchLists.

QUOTE (jimmyg)
I'm also starting to read about Classes and wondering if I need to be incorporating this logic into a class object .... If it would work better....

If you can synchronize any Indicators or Conditions imported into the RealCode more efficiently in your Class tab based RealCode than is done automatically in Code tab based RealCode, then yes, it would be better (as in quicker). If you synchronization is less efficient however, it would probably be worse (slower).

My attempts as a non-programmer to synchronize the two seems to be decidely less efficient than the built in AutoLoop on my computer (but you may be able to do better). Replace everything below the Inherits line in the Class tab of a RealCode Indicator with the following to give it a try on your computer.

    Sub New
        AutoLoop = False
        '# VS = indicator.Library.Volume Surge
    End Sub
    Public Overrides Function Plot() As System.Single
        If Price.Bar.DateValue(Price.Bar.Count - 1) = _
            VS.Line.DateValue(VS.Line.Count - 1) Then
            Dim Offset As Integer = Price.Bar.Count - VS.Line.Count
            Dim PointScore As Single = Single.NaN
            Dim DayOpen(1) As Single
            Dim DayHigh(1) As Single
            Dim DayLow(1) As Single
            Dim DayClose(1) As Single
            Dim DayCount As Integer = 0
            For i As Integer = System.Math.Max(1, Offset) To Price.Bar.Count - 1
                If Price.Bar.DateValue(i).DayOfYear <> _
                    Price.Bar.DateValue(i - 1).DayOfYear Then
                    PointScore = 0
                    DayOpen(1) = DayOpen(0)
                    DayOpen(0) = Price.Bar.OpenValue(i)
                    DayHigh(1) = DayHigh(0)
                    DayHigh(0) = Price.Bar.HighValue(i)
                    DayLow(1) = DayLow(0)
                    DayLow(0) = Price.Bar.LowValue(i)
                    DayClose(1) = Price.Bar.Value(i - 1)
                    DayClose(0) = Price.Bar.Value(i)
                    DayCount += 1
                Else
                    DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
                    DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
                    DayClose(0) = Price.Last
                End If
                If DayCount >= 2 Then
                    If VS.Line.Value(i - Offset) > 2 Then
                        PointScore += 1
                    End If
                    AddToOutput(Price.Bar.DateValue(i), PointScore)
                End If
            Next
        End If
    End Function
End Class

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Monday, December 13, 2010 3:50:52 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce, 

Thanks for the guidance!!!!!       
    Per Question 1:
           I really don't want this thing on a chart screen if I know it works.... As I've been testing though, it's been helpful.

    Per Question 2:
            I'm having visions of grandure....  IE:  This thing should work!!!!!!    (if my code doesn't cause it to blow up...)

    Per Question 3:

So, I can set....   AutoLoop = False       'OR True.......
to have the watchlist (do it's work) either way... 

AndSo...
 synchronization of conditions is a concern....EX:  pivot point calculation using yesterday's values

Here's where I think my code needs some "Class" added....

Say I have this condition called "Up2InARow"  that I use on a Daily chart  beside my 5 min chart, and I want to incorporate that condition into this indicator... 

Would that in and of itself mean that I need to go to a Class Object, or could I still just use an indicator...


Bruce_L
Posted : Monday, December 13, 2010 4:03:02 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jimmyg)
I really don't want this thing on a chart screen if I know it works.... As I've been testing though, it's been helpful.

Then you don't need to worry about it using more data than required if you don't start outputting data until the results are valid.

QUOTE (jimmyg)
So, I can set....   AutoLoop = False       'OR True.......
to have the watchlist (do it's work) either way...

The AutoLoop is the built in loop through all of the data in the symbol. It doesn't have anything to do with the WatchList. If AutoLoop is True and you manually create Loop as well, it will execute your manually constructed loop once for each bar of data being calculated.

If you have AutoLoop = True (the default), you will generally not want to create a loop manually.

if you have AutoLoop = False (normally used in the Class tab), you will almost always need to create your own loop manually.

QUOTE (jimmyg)
AndSo...
 synchronization of conditions is a concern....EX:  pivot point calculation using yesterday's values

Synchronization is a concern with any imported Conditions or Indicators (you can have different numbers of Bars of data available even if the Bar Interval is the same). It is just more complicated if the Bar Interval being used by the imported Condition or Indicator is different from the Bar Interval being used in the RealCode.

QUOTE (jimmyg)
Here's where I think my code needs some "Class" added....

Say I have this condition called "Up2InARow"  that I use on a Daily chart  beside my 5 min chart, and I want to incorporate that condition into this indicator... 

Would that in and of itself mean that I need to go to a Class Object, or could I still just use an indicator...

You don't need to use the Class tab for this. If you import the Condition, it would be much easier to let the Code tab do both the loop and synchronization for you.

Then again, you may be better of recreating the Condition within the Indicator than importing it.

Are you interested in the most recent two days including the current ay or the two days prior to the current day? Are you interested in the days being up at least two days in a row or exactly two days in a row? Is an day "up" based on its Net Change from Close to Close or the difference between the Close and the Open?

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Monday, December 13, 2010 5:40:21 PM
Registered User
Joined: 11/10/2010
Posts: 54
Yes to any ... maybe....

I also use a weekly chart... with the same "Up2InARow" condition that I Plot on my daily chart as just a special color price bar... Some other conditions that I've programmed onto the charts use colored arrows to plot... 

Right now I can see myself using 4 charts to view a stock...  
My layout has: 
(1) The "Main Chart" which is set to 1 or 2 minutes...
(2) The second Tabbed Chart (5 Minute) is what I'm really using as my main viewing chart... with conditions to paint some arrows and/or color the bars...  I've been doing all my development here from this chart...  so far....
(3)  The Third chart I use is just a Daily... so far with just the "Up2InARow"  condition painting the bars...
(4)  Chart 4 is just the Weekly version of #3.

This gives me a pretty good picture of where this stock has been.....   I rarely look at the "Main Chart" which is the 1 or 2 minute chart.

Any direction on the layout will be appreciated....

So Here's the results of the trial run .....

The code compiled, and plotted on my 5min chart....after creating a realcode indicator as instructed....  I called it "First Class".....

Then I go to the watchlist (Russ 2000) and "add a data column"  for the FirstClass indicator....   it seems to populate rather quickly.... but the values don't match the chart.... So, I edit the column to a bar interval of 5 min... and it takes off recalculating.....  Again, seemingly fairly fast as I see it recalculating down the column...         When I sorted on the data column, though...  That took about 5 minutes to recalculate...

So I've set the sort frequency to "ONCE". 

It DID WORK!!!!!     Encouraging to say the least.....  But, I have to incorporate my other calculations, so I'm wondering if that is going to slow it down (how much) further.....   I'll be tinkering to see...

I guess I'm wondering about the watchlist updating... and sorting at the first of the day when the data stream comming in is high and TIME IS Of the Essence....

In my logic, I'm testing for "IF 1st bar"  do something, and IF 2nd Bar.... add/or/subtract ... etc.

so I'm wondering about the SORT execution "synchronization"  in the watchlist along with the CODE execution "synchronization"  that my computer will perform......  SO MUCH SYNCHRONIZING.....  Almost mind boggling!!

It all seems to me to boil down to TWO speed concerns.....   The data stream comming in.... and the speed at which my computer can execute the code and sort the watchlist.....

If I assume that at 9:36 the data stream has updated the data base up through 9:35, would I be wrong???

And If the data is there in the database, I assume that I could get a faster computer to run the code???? if needed.

What do you think???

As always, thanks for your help!

JimG




jimmyg
Posted : Monday, December 13, 2010 6:02:51 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce,
Your Quote"

Then again, you may be better of recreating the Condition within the Indicator than importing it.

""""" 

I think this is the method (no pun intended...) that I've been using (or wanting to use) when I'm coding this so far as a first 30 minutes of the day indicator......... five minutes to a bar, each bar executing it's own code...

Anyway, I think the theory is well worth pursueing.

I'll tinker tonight....

Thanks again!!!!
Bruce_L
Posted : Tuesday, December 14, 2010 9:22:40 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
My first thought is that incorporating the Up2InARow Condition from the Daily Chart directly into the calculations probably isn't problematic (we can probably do it by just adding a single Bar of intraday data if it is the most recent two days including today).

That said, incorporating the Up2InARow into the intraday calculations requires a lot of extra bars of intraday data and could slow things down considerably. It is probably better to Import the Weekly version (or calculate it using the PriceData method).

The data normally streams in at realtime speeds for me. That could vary depending on the speed of your internet connection.

As far as the speed of Sort goes, adding complexity to the Indicator will probably slow it down, but by how much depends on what is added and if the calculations are actually a limiting factor. The calculation speed is affected by more than just the complexity of the calculations and the power of your computer, but by the speed of your data storage as well. I have seen many instances where the CPU isn't being used to its fullest capacity because the Hard Drive can't deliver the data quickly enough (a Solid State Drive can help with this).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Tuesday, December 14, 2010 12:24:08 PM
Registered User
Joined: 11/10/2010
Posts: 54

Bruce,

Very Good Analysis / discussion!

It looks like the PriceData method is just what I've been concerned about....

Also, on my first test, my FirstClass seemed to run slower than just an indicator that did the same thing...

SOooo,  Please look at the following to tell me if I'm on the right track here....

Static PointScore As Single
Static BARNUM As Single
Static YDRANGE As Single
Static DayOpen(1) As Single
Static DayHigh(1) As Single
Static DayLow(1) As Single
Static DayClose(1) As Single
Static DayCount As Integer

' PIVOT POINTS
Static PP As Single
Static R1 As Single
Static R2 As Single
Static R3 As Single
Static S1 As Single
Static S2 As Single
Static S3 As Single


If isFirstBar Then
 PointScore = Single.NaN
 For i As Integer = 0 To 1
  DayOpen(i) = Single.NaN
  DayHigh(i) = Single.NaN
  DayLow(i) = Single.NaN
  DayClose(i) = Single.NaN
 Next
 DayCount = 0
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 PointScore = 0
 BARNUM = 0
 DayOpen(1) = DayOpen(0)
 DayOpen(0) = Price.Open
 DayHigh(1) = DayHigh(0)
 DayHigh(0) = Price.High
 DayLow(1) = DayLow(0)
 DayLow(0) = Price.Low
 DayClose(0) = Price.Last
 DayClose(1) = Price.Last(1)
 DayCount += 1
 
 '... PIVOT POINTS STATIC VARIABLE VALUES....
 PP = (DayHigh(1) + DayLow(1) + DayClose(1)) / 3
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  PP = " + PP.ToString())

 ' R1 = (PP * 2) - YDL
 R1 = (PP * 2) - DayLow(1)
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  R1 = " + R1.ToString())

 ' R2 = PP + (YDH - YDL)
 R2 = PP + (DayHigh(1) - DayLow(1))
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  R2 = " + R2.ToString()) 
 
 ' R3 = PP + ((YDH - YDL) * 2)
 R3 = PP + ((DayHigh(1) - DayLow(1)) * 2)
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  R3 = " + R3.ToString()) 

 ' S1 = (PP * 2) - YDH
 S1 = (PP * 2) - DayHigh(1)
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  S1 = " + S1.ToString())

 ' S2 = PP - (YDH - YDL)
 S2 = PP - (DayHigh(1) - DayLow(1))
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  S2 = " + S2.ToString()) 

 ' S3 = PP - ((YDH - YDL) * 2) 
 S3 = PP - ((DayHigh(1) - DayLow(1)) * 2)
 Me.Log.Info(“Symbol: " + CurrentSymbol + "  S3 = " + S3.ToString())  
 
Else
 DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
 DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
 DayClose(0) = Price.Last
End If
If DayCount >= 2 Then
 'MY STUFF GOES HERE

 BARNUM += 1
 
 '=============  FIRST BAR CALCULATIONS  ======================
 If BARNUM = 1


  
  '..... ONLY GIVE POINTS TO STOCKS THAT ARE GOING UP IN PRICE FROM YESTERDAY
  If PRICE.Last > PRICE.LAST(1) Then
   POINTSCORE += 1
  
   '...VOLUME SURGE POINTS....
   If VS.Value > 1 Then PointScore += VS.Value
  
   '... POINTS FOR OPENING LOWER AND COMING BACK UP
   '  If PRICE.Open < PRICE.Close(1) Then POINTSCORE += 1

  
  End If
 End If
 'END OF FIRST BAR CALCULATIONS ===============================

 
 
 
 'TO HERE
 Plot = PointScore
Else
 Plot = Single.NaN
End If

=================================================================

I'm not sure if I put the PP calcs in the right place.....  When I first ran the above.... with just the PP calculation active and writing to the log... It produced about 5 different log entries....

Multiple log entries for 1 value don't make me feel good about this.... Am I doing something wrong???

I did get it to work though, and it did verify all the PP values on my 5 min chart... except R3 and S3... which appear to have some other formula calculating them on the chart.... I'd like to fix (resolve ) that.

But, ALL SAID SO FAR, this looks promissing!

I just want to verify (or correct) the structure of the code above so I can continue building the PointScore...

As Always, Thanks for your help!!

Jimg

Bruce_L
Posted : Tuesday, December 14, 2010 12:52:14 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (jimmyg)
Also, on my first test, my FirstClass seemed to run slower than just an indicator that did the same thing...

Have you tried just dragging and dropping that Indicator to the WatchList to use as a Sort? On another note, logging can really slow things down.

QUOTE (jimmyg)
I'm not sure if I put the PP calcs in the right place.....  When I first ran the above.... with just the PP calculation active and writing to the log... It produced about 5 different log entries....

Multiple log entries for 1 value don't make me feel good about this.... Am I doing something wrong???

The optimization used to determine how much data to use in a WatchList requires running the the calculations multiple times for at least one symbol to determine the minimum amount of data that can be used.

QUOTE (jimmyg)
I did get it to work though, and it did verify all the PP values on my 5 min chart... except R3 and S3... which appear to have some other formula calculating them on the chart.... I'd like to fix (resolve ) that.

R3 is R1 + (YDH - YDL) not PP + 2 * (YDH - YDL)
S3 is S1 - (YDH - YDL) not PP - 2 * (YDH - YDL)

QUOTE (jimmyg)
I just want to verify (or correct) the structure of the code above so I can continue building the PointScore...

Keeping in mind that I am not a programmer, I don't see anything obvious wrong with it.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Tuesday, December 14, 2010 1:32:48 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce,

Quote:
The optimization used to determine how much data to use in a WatchList requires running the the calculations multiple times for at least one symbol to determine the minimum amount of data that can be used.

I was hoping that you would say something like that!!!     

So Far, So Good !!!!

I'll go back to tinkering....

Thanks again for ALL your help!

jimg
Bruce_L
Posted : Tuesday, December 14, 2010 1:34:14 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Tuesday, December 21, 2010 12:21:28 AM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce, 
I've been tinkering....with this indicator.
It really is exciting to work with....

Please consider the following (same indicator construct as above):
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Static PointScore As Single                    ' POINTSCORE - VALUE TO PLOT / (WC SORT)
Static BARNUM As Single                       ' BAR ITERATION COUNTER
Static YDRANGE As Single                     ' YESTERDAY'S PRICE RANGE
Static DayOpen(1) As Single                  ' ????
Static DayHigh(1) As Single                   '  THESE DAYxxx  ARRAY VARIABLES
Static DayLow(1) As Single                    '  ARE??? NOT PFA (PULLED FROM AIR)
Static DayClose(1) As Single                 '
Static DayCount As Integer                     '????   WHAT DO YOU CALL THESE   ?????
                                                                     '

' PIVOT POINTS
Static PP As Single                                   'MORE OF MY PFA VARIABLES......
Static R1 As Single
Static R2 As Single
Static R3 As Single
Static S1 As Single
Static S2 As Single
Static S3 As Single

?????'    DO MY PFA VARIABLES NEED TO BE INSTANCIATED BELOW....
'?????    LIKE THESE DAYxxx VARIABLES? 

If isFirstBar Then
 PointScore = Single.NaN
 For i As Integer = 0 To 1
  DayOpen(i) = Single.NaN
  DayHigh(i) = Single.NaN
  DayLow(i) = Single.NaN
  DayClose(i) = Single.NaN
 Next
 DayCount = 0
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
 PointScore = 0                                         ' AT THIS POINT IN EXECUTION OF THIS INDICATOR,
 BARNUM = 0                                            'WE ARE AT THE START OF TODAY....
 DayOpen(1) = DayOpen(0)                   '
 DayOpen(0) = Price.Open                     '
 DayHigh(1) = DayHigh(0)                      '
 DayHigh(0) = Price.High                        '
 DayLow(1) = DayLow(0)                        '
 DayLow(0) = Price.Low                          '
 DayClose(0) = Price.Last                      '
 DayClose(1) = Price.Last(1)                 '
 DayCount += 1                                         '  SO I INITIALIZE MY PP'S... ETC....
 
 '... PIVOT POINTS STATIC VARIABLE VALUES....
 PP = (DayHigh(1) + DayLow(1) + DayClose(1)) / 3
' Me.Log.Info(“Symbol: " + CurrentSymbol + "  PP = " + PP.ToString())

''''''''''''  END OF MY PFA VARIABLE SETTING....SETUP FOR TODAY'S EXECUTION ON THE WATCHLIST.

 Else
''''' I NEED TO UNDERSTAND THESE DAYxxx THINGS.... IS THIS INHERITANCE? FROM A ???????
''''  WHAT'S THE TERMINOLOGY THAT YOU USE TO DESCRIBE THESE?
 DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
 DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
 DayClose(0) = Price.Last
End If

If DayCount >= 2 Then         
  BARNUM += 1
 
' IT IS TODAY AND WE ARE "LIVE" IN THE WATCHLIST... SO 

'============= ALL BAR CALCULATIONS  ======================
 IF BARNUM >= 1 AND BARNUM < = 4          ' I'M ONLY WANTING THIS TO EXECUTE FOR THE FIRST 
           '''  INCREMENT  POINTSCORE            ' 20 MINUTES OF THE DAY AND ...
             IF POINTSCORE >= 999 
                      I AM LOGGING INFO DEBUG MESSAGES FOR THEORETICAL ORDERS.....
                      BARNUM, PRICE, TARGET, ETC.

             ENDIF
End If           'END OF ALL BAR CALCULATIONS =============================== 

 Plot = PointScore
Else
 Plot = Single.NaN
End If

 ========================================================================

SO, after the first 20 minutes of the day, this thing has done it's thing.... 
 
The values are listed in the watchllist column (WC) and the list is sorted.  VERY WELL!!!!

Actually, I am logging each time the watchlist sort is done on this WC.... so it's writing multiple orders as the pointscore is incremented above 999 on any particular pass (oops... BAR).
I'm wondering if there is some other type of variable that could be used for each symbol to say once is enough....  I think this is "persistance" or "global" or something... 
I'm still having trouble understanding how to manipulate variables... and the running of multiple passes in the watchlist.
Can you help me on this???  1.

I may be trying to do something that an indicator was not designed to do, but some more questions please...

2. Can I write text to another file (other than the debug log) during execution?

3. Can I read another file during execution.

4. Can I call other VB.NET gadgets from within this thing?   
           What Can and Can't  I do with this?  

5. Could this actually place an order at my broker (OE).

Possibilities seem endless....    What are your thoughts?

As Always,
Thanks for your help...

jimg






 

Bruce_L
Posted : Tuesday, December 21, 2010 9:47:17 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I think I've mentioned before that I'm not a programmer.

QUOTE (jimmyg)
Static DayOpen(1) As Single                  ' ????
Static DayHigh(1) As Single                   '  THESE DAYxxx  ARRAY VARIABLES
Static DayLow(1) As Single                    '  ARE??? NOT PFA (PULLED FROM AIR)
Static DayClose(1) As Single                 '
Static DayCount As Integer                     '????   WHAT DO YOU CALL THESE   ?????

They are PFA. I just chose the variable names to be descriptive of what they do. They calculate the Daily Price components from the Price components of the Intraday Bars.

QUOTE (jimmyg)
Else If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then

This line checks for the start of a new day and resets/moves variable values around so they are correct.

QUOTE (jimmyg)
''''' I NEED TO UNDERSTAND THESE DAYxxx THINGS.... IS THIS INHERITANCE? FROM A ???????
''''  WHAT'S THE TERMINOLOGY THAT YOU USE TO DESCRIBE THESE?
 DayHigh(0) = System.Math.Max(DayHigh(0), Price.High)
 DayLow(0) = System.Math.Min(DayLow(0), Price.Low)
 DayClose(0) = Price.Last

System.Math is the Class from which I am getting the Max and Min functions. Remember when I said I wasn't a programmer? Well I found these by searching the internet (on another note, you don't need to actually specify System. in SF5, but I put it there because it is required in SF4).

The RealCode documentation does include some non-RealCode specific stuff in its examples, but it is primarily designed to document only the RealCode specific aspects of RealCode. There is no way it could document every feature of Visual Basic.

QUOTE (jimmyg)
             IF POINTSCORE >= 999 
                      I AM LOGGING INFO DEBUG MESSAGES FOR THEORETICAL ORDERS.....
                      BARNUM, PRICE, TARGET, ETC.

             ENDIF

I'm not sure if this will limit it as much as you want, but you might also want to add If isLastBar to this so it doesn't log on each Bar, but only once for each symbol for each pass through the WatchList. So:

If isLastBar AndAlso POINTSCORE >= 999 Then

QUOTE (jimmyg)
Actually, I am logging each time the watchlist sort is done on this WC.... so it's writing multiple orders as the pointscore is incremented above 999 on any particular pass (oops... BAR).
I'm wondering if there is some other type of variable that could be used for each symbol to say once is enough....  I think this is "persistance" or "global" or something... 
I'm still having trouble understanding how to manipulate variables... and the running of multiple passes in the watchlist.
Can you help me on this???

Static variables will survive through multiple passes through the WatchList, so I'm sure a clever programmer could figure out exactly when a pass starts or ends. You could probably also have a variable for each symbol or an array that allows you to track each symbol so it is only logged once. That said, I'm not a programmer and such techniques are currently beyond me.

QUOTE (jimmyg)
Can I write text to another file (other than the debug log) during execution?

I do not know of a way to do so. If you just want to store something temporarily, you may want to take a look at the Global Variables/Memory section of the RealCode Programmers Reference.

QUOTE (jimmyg)
Can I read another file during execution.

It is possible to read external data from a text file using RealCode.

Market Data Reader Overview
RealCode File Reader Overview

QUOTE (jimmyg)
Can I call other VB.NET gadgets from within this thing?   
           What Can and Can't  I do with this?

I'm not sure what a gadget is, but you can access some .NET namespaces (but not all - the ability to write to external files is specifically limited because of licensing issues).

QUOTE (jimmyg)
Could this actually place an order at my broker (OE).

I do not know of a way to do so.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jimmyg
Posted : Tuesday, December 21, 2010 1:28:23 PM
Registered User
Joined: 11/10/2010
Posts: 54
Bruce,

Thanks for your thoughts!


So...
 
Static Variables are pfa......... Do they require the ...." = Single.NaN"  initialization? 

EX:

If isFirstBar Then
 PointScore = Single.NaN
 For i As Integer = 0 To 1
  DayOpen(i) = Single.NaN
  DayHigh(i) = Single.NaN
  DayLow(i) = Single.NaN
  DayClose(i) = Single.NaN
 Next
 DayCount = 0
Else.....................................................................

Another concern is house keeping related to this.... I want to make sure I'm not using more variables than needed, and that computer memory doesn't get used up by spawning storage spaces for pfa's and that it cleans the memory up well when execution is finished...


For someone who's " not a programmer " you sure seem to be "clevor" !!!!

As always,
Thanks in advance for your thoughts...

jimg

back to tinkerin....





Bruce_L
Posted : Tuesday, December 21, 2010 1:39:48 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I really can't tell you anything about garbage collection beyond the fact that StockFinder already does so to minimize memory usage.

The Single.NaN variable assignments were done in my Friday, December 10, 2010 3:04:02 PM ET post to avoid posting results before they were Valid without keeping track of a DayCount to explicitely determine if the results were Valid (because it would just output Single.NaN until that point).

This probably isn't necessary in a Condition that checks for DayCount >= 2 since these results should already be cycled out of the variables at that point (they are there as a result of merging the Pivot Point RealCode with the other RealCode). That said, I haven't stepped through the code to know for sure that this is true.

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