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

Condition for Stocks in Trading Range Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
chrfiala76
Posted : Tuesday, August 24, 2010 8:04:32 AM
Registered User
Joined: 8/19/2010
Posts: 40
ok, so i am trying to convert my scanners from prorealtime to stockfinder, without any success.

logic is valid, worked before - so where is my programming error?

1) only do it on last bar = save cpu power
2) first for; calculate high(30) low(30) days
3) count touches of data to high and low, touches are only seperate with a retraction of 25%
4) pass when it touches at least one time (for testing purposes)

so this condition should be always true, why isnt it?

Dim TradingRange As Integer = 30
Dim Retraction As Integer = 0.25
Dim Fuzzy As Integer = 0.05

Dim High,Low As Single
Dim TouchHigh,TouchLow As Integer
Dim LastIsHigh,LastIsLow As Boolean

If isLastBar Then
    For i As Integer = 0 To TradingRange
        If Price.High(i) > High Then
            High = Price.High(i)
        End If
        If Price.Low(i) < Low Then
            Low = Price.Low(i)
        End If
    Next
   
    For i As Integer = 0 To TradingRange
       
        If (Price.High(i) < High * (1 + Fuzzy)) And (Price.High(i) > High * (1 - Fuzzy)) Then
            If LastIsHigh Then
                TouchHigh = TouchHigh + 1
            End If
            LastIsHigh = True
        End If
       
        If LastIsHigh And (Price.High(i) < High * (1 - Retraction)) Then
            LastIsHigh = False   
        End If
       
        If (Price.Low(i) < Low * (1 + Fuzzy)) And (Price.Low(i) > Low * (1 - Fuzzy)) Then
            If LastIsLow Then
                TouchLow = TouchLow + 1
            End If
            LastIsLow = True
        End If
       
        If LastIsLow And (Price.Low(i) > Low * (1 + Retraction)) Then
            LastIsLow = False   
        End If

    Next
   
    If TouchLow > 1 Or TouchHigh > 1 Then
        pass
    End If
       
End If
shamilton
Posted : Wednesday, August 25, 2010 4:54:52 AM
Registered User
Joined: 1/25/2005
Posts: 13

Hi chrfialia76,

This one is fairly easy to fix.  The reason that it's not calculation anything is because you have Dim'ed your Fuzzy and Retraction variables as Integer.  They should be Single as you are using decimals.   The way you have it they will be 0.

I don't completely understand everything you are doing but I do have a couple of other suggestions that might help:

#1) I don't think 'Low' is calculating a value.  When you initialize it using the Dim statement it will start off with a value of 0 and you can't get any lower than that with price.  

#2) The loop you use to calculate the high and low of the tradingrange can be replaced with the statement

High = Price.MaxHigh(Tradingrange)
Low = Price.MinLow(Tradingrange)

Now you can fix both #1 and #2  by using the following statements after the Dim statement for TradingRange:

Dim High as Single = Price.MaxHigh(TradingRange)
Dim Low as Single = Price.MinLow(TradingRange)


#3) To speed things up a bit you might want to calculate the fuzzy upper and lower limits outside the loop.  If you decide to use the suggestion above for High and Low then you can add the follow Dim statements right after (also after the Dim statement for Fuzzy):

Dim FHighUpper As Single = High * (1 + Fuzzy)
Dim FHighLower As Single = High * (1 - Fuzzy)
Dim FLowUpper As Single = Low * (1 + Fuzzy)
Dim FHighLower As Single = Low * (1 - Fuzzy)

You might want to do this for the Retraction calculation.

I pasted below what your second loop would look like if you use the above suggestion.  You may notice a few other minor things.  The "AndAlso" statement is used to speed things up a fraction.  It will not execute the remainder of the if statement if the first part is not true. Also, I assumed you only want to check 30 bars (tradingrange) therefore "i" should be from 0, which is the current bar, to 29 which is the 30th bar.

For i As Integer = 0 To TradingRange - 1
       
 If Price.High(i) < HighFuzzyUpper AndAlso Price.High(i) > HighFuzzyLower Then
  If LastIsHigh Then
   TouchHigh = TouchHigh + 1
  End If
  LastIsHigh = True
 End If
       
 If LastIsHigh And (Price.High(i) < High * (1 - Retraction)) Then
  LastIsHigh = False   
 End If
       
 If Price.Low(i) < LowFuzzyUpper AndAlso Price.Low(i) > LowFuzzyLower Then
  If LastIsLow Then
   TouchLow = TouchLow + 1
  End If
  LastIsLow = True
 End If
       
 If LastIsLow And (Price.Low(i) > Low * (1 + Retraction)) Then
  LastIsLow = False   
 End If

Next

Kind Regards,
Shawn

chrfiala76
Posted : Wednesday, August 25, 2010 10:28:53 AM
Registered User
Joined: 8/19/2010
Posts: 40
Hi Shamilton.

that is awesome help, ty, solved my problem.

the 0.25 as integer was obviously a loud "dooohhh"; good to know that i dont get errors from the ide when i do such stupid stuff.

2/3 is also very helpful, i was srsly wondering why i havent been able to find the .maxhigh function; and calculation the value just once and storing them is obv way faster. i even had this implemented in the last code.

thanks again
shamilton
Posted : Thursday, August 26, 2010 2:11:57 AM
Registered User
Joined: 1/25/2005
Posts: 13
Glad to help and you're welcome.

Take care,
Shawn
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.