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 |

Multiple looping with Indicator/Rules Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jackmanjls
Posted : Friday, January 29, 2010 12:21:51 PM
Registered User
Joined: 9/28/2009
Posts: 135

I've noticed that  under the Code tab if I put the single statement, me.log.info("test"), in either a indicator or rule and run this code I get the buffer filled with "test". I set AutoLoop=false under the Class tab.

Ideally, what I would expect would be just one print of the "test" and that would be it. Why would I get so many prints?

Bruce_L
Posted : Friday, January 29, 2010 12:37:29 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
It is going to post to the log each time the RealCode runs (and generally for each symbol for which it runs in every place it used). I don't know of a way to force your RealCode to run just once.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
jackmanjls
Posted : Friday, January 29, 2010 4:26:14 PM
Registered User
Joined: 9/28/2009
Posts: 135
I agree with what you say but if I have a program that has a single line of me.log.info("test") shouldn't that just run one time. What is forcing it to loop so many times.

Also is there anyway to clear the debug log?
Bruce_L
Posted : Friday, January 29, 2010 4:41:25 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If the RealCode is used by the WatchList, your RealCode is going to get run at least once for each symbol during each pass (and possibly more than once as the WatchList attempts to optimize the data size used for example). If it is on the Chart, it is going to get run at least once when you change symbols and it is going to generally get run again every time there is new data available (which can be quite frequent if you have Streaming Real Time data running for example).

As stated previously, I don't know of a wy to force your RealCode to run just once. I'm not a programmer and I don't use the debug log, but you may wish to review the how to delete contents of debug.log? topic.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
SunriseMan
Posted : Sunday, January 31, 2010 1:36:51 PM
Registered User
Joined: 11/30/2009
Posts: 29
There is a bug where, if you're scanning the watchlist, StockFinder will run the rule's code for each bar on the chart. (That is, it rechecks the rule for the period ending on each visible chart bar.) That behavior would be necessary if the indicator were used on the chart, but StockFinder does it for watchlist scans too. I have verified this with debug logging.

It's unfortunate, since it makes scanning the watchlist take much, much longer than it should. I'm surprised this hasn't generated many comments before this point.
Bruce_L
Posted : Monday, February 1, 2010 10:27:54 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
SunriseMan,
No, it won't unless the following line is part of your RealCode or your RealCode relies on data from an Indicator that is already cumulative:

'# Cumulative

In StockFinder 4, the minimum amount of data used is 10 Bars, but StockFinder will attempt to determine if more data is required by checking for the amount of data needed before the Rule or Indicator outputs data. StockFinder 5 attempts to do the same thing, but the minimum amount of data used is larger because the Bubble Bar is also always calculating how many days ago the Condition was most recently True if the Condition is False (and by default, it looks back 50 Bars).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
SunriseMan
Posted : Monday, February 1, 2010 11:03:32 AM
Registered User
Joined: 11/30/2009
Posts: 29

Bruce -

Yes, I'm afraid it does, even without the '#Cumulative flag. It probably won't do it if you override Me.AutoLoop, but by default it does, even if all you do is scan the watchlist.

Here's an example rule I wrote:

Me.Log.Debug(Me.CurrentSymbol + ": " + Me.CurrentDate.ToShortDateString)
If Price.Close > 10 Then Pass

I put this on a weekly chart and scanned a watchlist that contained only one symbol, BAC. My debug log wound up with a couple of hundred messages:

BAC: 1/29/2010
BAC: 1/22/2010
BAC: 1/15/2010
...
BAC: 4/14/2006
BAC: 4/7/2006

This is using StockFinder 4.0.83.16914. If StockFinder used only 10 or so bars, it wouldn't be as massive of a performance hit.

Bruce_L
Posted : Monday, February 1, 2010 11:28:48 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
SunriseMan,
Seriously, you're wrong, it doesn't. Try your RealCode Rule on All US Items instead of a single symbol for example. Except for the Charted symbol and the multiple passes through the first symbol to determine the amount of data required, each symbol gets processed 19 times if it is a Daily only symbol and 20 times if it is a Realtime symbol (not sure why it is 19, it definitely used to be 10).

If you want it to be lot faster, stop writing to the log (or only do it for the last Bar at least). That's very resource intensive.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
SunriseMan
Posted : Monday, February 1, 2010 12:09:05 PM
Registered User
Joined: 11/30/2009
Posts: 29

Bruce -

Of course I don't use logging in my regular scans - I was just doing that to prove the point.

I tried it again, and you are correct that it does fewer iterations on symbols after the first symbol in a watchlist. The bug does occur every time you add a symbol to the watchlist, switch to a different chart, etc.

I modified the rule as follows to make the output easier to follow: 

If Me.isFirstBar Then _
  Me.Log.Debug(Me.CurrentSymbol + " First: " + Me.CurrentDate.ToShortDateString)
If Me.isLastBar Then _
  Me.Log.Debug(Me.CurrentSymbol + " Last: " + Me.CurrentDate.ToShortDateString)
If Price.Close > 10 Then Pass

Whenever I add a symbol, change charts, etc., with the rule scanning the watchlist, StockFinder iterates through the entire price history:

OSK Last: 1/29/2010
OSK First: 10/4/1985
JCP Last: 1/29/2010
JCP First: 1/6/1984
etc.

When I apply it anew to the watchlist, it performs as you suggest:

OSK Last: 1/29/2010
OSK First: 11/20/2009
JCP Last: 1/29/2010
JCP First: 11/20/2009

That explains why I found it so noticeable. On something computationally intensive, adding a new symbol with a 15-year price history can cause a noticeable delay.

Bruce_L
Posted : Monday, February 1, 2010 12:32:41 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (SunriseMan)
Of course I don't use logging in my regular scans - I was just doing that to prove the point.

There are legitimate reasons to output results to the debug log besides debugging. Customer's ask about it all the time.

QUOTE (SunriseMan)
The bug does occur every time you add a symbol to the watchlist, switch to a different chart, etc.

I don't know about adding a symbol to the WatchList, but when you are switching symbols, it is calculating for the entire history. The Charts always use all of the data.

As to it being a bug, the multiple iterations on the first symbol in the WatchList to determine the amount of data to use is by design and reduces the amount of data used for all of the other symbols in the WatchList.

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