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
|

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