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 |

StockFinder calculation Time Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
jimirak
Posted : Saturday, November 6, 2010 4:36:42 PM
Registered User
Joined: 3/6/2005
Posts: 25

Below is a simple program that calculates a higher trading range bar in a certain way. The code runs and gives me the results I expect.

The issue is how long it takes to calculate this simple condition for a given watch list.

For example, if I drop this condition into a filter and run the filter, it takes 10 minutes to filter a watchlist of 3529 symbols. This seems ridiculous because in Telechart, I have many conditions, and a number of them more complex than this, and the update PCF's for approximately 7600 items takes very little time. I can see where a scan would take more time because every bar in the chart must be evaluated, but if I understand a filter correctly, it is only evaluating the last bar on the chart, as does Telechart. Actually, the filter might take as long to complete as does the scan.

I am running on a new fast Imac and I use Parallels as my windows emulator. I have over 7 gigibytes of memory assigned to the virtual windows machine. Even now, when I am playing with Stockfinder with larger watchlists from Telechart, I sometimes get a message that there are no more resources available and then the windows start to become corrupted.

Over the years I tried Stockfinder (or Blocks) twice on a trial basis and declined it based on it bringing my computer to its knees, and this still may be happening. Something must be fundamentally wrong with my current setup. I have all kinds of uses for Stockfinder now so I hope I can get past this critical problem.

Dim range As Single, maxrange As Single, rangetoday As Single
Dim i As Integer, toprange As Single, range4 As Single

rangetoday = PH.value - open.value
toprange = 0
maxrange = 0

For i = 1 To 2
 range = PH.Value(i) - open(i)
 If range >= toprange Then toprange = range
Next i

If rangetoday >= toprange Then toprange = rangetoday
range4 = PH.value(3) - open.value(3)

For i = 4 To 23
 range = PH.Value(i) - open(i)
 If range >= maxrange Then maxrange = range
Next i

If  range4 >= maxrange And range4 > toprange _
 And PH.Value <= high.Value(3) And low.Value >= low.Value(3) _
 Then pass

jas0501
Posted : Sunday, November 7, 2010 8:38:28 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

Your code is looping every bar. Try instead to write the routine using static variables. This will eliminate the need to loop every bar. You will only need to loop if and when  the bar(24) contains the max value. Thus the max has expired and then you need look at 23 bars to find the new max, unless todays value establish the new max.

QUOTE (possible solution)
Static maxRange as single
dim range           as single
dim range4         as single
dim topRange     as single

topRange = max(PH.value(1)-Open(1),PH.value(2)-Open(2))
range4 = PH.value(3) – Open(3)
if range4 >= maxRange then
   maxRange = range4
else if maxRange = PH.value(24) – Open(24) then

  expired maxRange, need to establish new maxRange value

    dim I as integer
    maxRange = 0
    for I = 23 to 4 step -1
       range = PH.value(i) – open(i)
       if range > maxRange then
          maxRange = range
      end if
    next i
end if

If PH.value <= High.value(3) and
   low.value >= low.value(3) and
   range4 > topRange and
   range4 >= maxRange then
   pass
end if

 

 

jas0501
Posted : Sunday, November 7, 2010 8:41:02 PM
Registered User
Joined: 12/31/2005
Posts: 2,499

code needs

if isfirstbar the
    maxRange = 0
end if

since maxRange s now static and need to be reset between symbols.

jas0501
Posted : Sunday, November 7, 2010 8:55:46 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
slight optimization moving topRange calc inside if to avoid unneeded calculations

QUOTE (modified solution)

Static maxRange as single
dim range           as single
dim range4         as single
dim topRange     as single

If isfirstBar then
   maxRange = 0
end if

range4 = PH.value(3) – Open(3)
if range4 >= maxRange then
   maxRange = range4
else if maxRange = PH.value(24) – Open(24) then

  expired maxRange, need to establish new maxRange value

    dim I as integer
    maxRange = 0
    for I = 23 to 4 step -1
       range = PH.value(i) – open(i)
       if range > maxRange then
          maxRange = range
      end if
    next i
end if

If PH.value <= High.value(3) andalso
   low.value >= low.value(3) then
   topRange = max(PH.value(1)-Open(1),PH.value(2)-Open(2))

   if range4 > topRange andalso
      range4 >= maxRange then
        pass
   end if
endif

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.