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 |

Indicator speed improvement using "islastbar"? Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
john99m
Posted : Thursday, July 8, 2010 9:40:51 PM
Registered User
Joined: 6/25/2008
Posts: 4

The following indicator attempts to determine just a single final number from any price chart (rather than a full bar-length curve).

It just tells me where the 200day moving average is right now on today's bar (as a percentage of the high and low for the past year).

QUESTION:  Is the speed of this routine improved by putting the formula inside the "islastbar" statement the way I have done?   As I understand it, this indicator is called once for every bar in the chart.  (So I figured the "islastbar" if-statement would cause the formula to be calculated only once rather than for every bar in the chart.) 
(My layout has several similar realcode indicators in it, and although it works, it's rather slow.  When I added the if statement to each indicator, I didn't seem to get any noticeable improvement.)

Dim hi1yr As Single, lo1yr As Single
'# Cumulative
'# MA200 = chart.MovingAverage

If islastbar Then
            hi1yr = MA200.MaxHigh(300)
            lo1yr = MA200.MinLow(300)
            plot = (MA200.value - lo1yr) / (hi1yr - lo1yr)
End If

Kuf
Posted : Friday, July 9, 2010 9:45:05 AM


Administration

Joined: 9/18/2004
Posts: 3,522
No this will not improve any speed. If you only need to be called once, you should look into RealCode classes. Your code will only be called once and it's up to you to build the output from there. This will give you significant performance increases.

Additionally, using #Cumulative will drastically slow down your code when they are used in scans and filters as it has to calculate for all the history instead of the minimum required to perform your calculation.

Ken Gilb (Kuf)
Chief Software Engineer - Worden Brothers Inc.
Try/Catch - My RealCode Blog
john99m
Posted : Friday, July 9, 2010 12:57:34 PM
Registered User
Joined: 6/25/2008
Posts: 4
Thanks.

By the way, I tried eliminating the #Cumulative statement.  Now, however, my watchlist  columns (based on rules developed from the indicators) no longer display any colors.

I had to add the #Cumulative statement back in to fix this
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.