Register Login
Forums    February 9, 2012
TradersStudio Forums
Program to Calculate Fractal Dimension of Waveforms
Last Post 05-13-2007 10:26 AM by mur ang. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Frank Svarholt
New Member
New Member
Posts:6

--
05-13-2007 07:51 AM

    Hello

    Can somebody help me to see what is wrong in this code:i Get the message  line7:attempt to redeclare object member "FractalDim"

    Here is the Code Which is translated For Tradestation

    Function FDI(N) As BarArray
        Dim Diff As BarArray
        Dim Length As BarArray
        Dim PriceMax As BarArray
        Dim PriceMin As BarArray
        Dim PriorDiff As BarArray
        Dim Iteration As BarArray
        Dim FractalDim As BarArray

        If BarNumber=FirstBar Then
            Diff = 0
            Length = 0
            PriceMax = 0
            PriceMin = 0
            PriorDiff = 0
            Iteration = 0
            FractalDim = 0
        End If

        PriceMax = Highest(Close, N, 0)
        PriceMin = Lowest(Close, N, 0)
        Length = 0
        PriorDiff = 0
        For Iteration = 1 To N - 1
            If PriceMax - PriceMin > 0 Then
                Diff = (Close[Iteration] - PriceMin) /     (PriceMax - PriceMin)
                If Iteration > 1 and N <> 0 Then
                    Length = Length + Sqr(Sqr(Diff -       PriorDiff) + (1 / Sqr N)))
                End If
                PriorDiff = Diff
            End If
        Next
        If Length > 0 and N <> 0 Then
            FractalDim = 1 + (log(Length)+ log(2)) / log(2 * N)
        Else
            FractalDim = 0
        End If
        FDI = FractalDim
    End Function

    FS

    Norway

     

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    05-13-2007 08:44 AM

    FractalDim is already a keyword in TraderStudio , just change the name of your variable. For example MyFractalDim.

    Frank Svarholt
    New Member
    New Member
    Posts:6

    --
    05-13-2007 09:32 AM

    Thanks Murray

    Here is the Code-It seems to be ok but does not work in the strategy

     

     

     

    Function FDI(N) As BarArray
        Dim Diff As BarArray
        Dim Length As BarArray
        Dim PriceMax As BarArray
        Dim PriceMin As BarArray
        Dim PriorDiff As BarArray
        Dim Iteration As BarArray
        Dim MyFractalDim

        If BarNumber=FirstBar Then
            Diff = 0
            Length = 0
            PriceMax = 0
            PriceMin = 0
            PriorDiff = 0
            Iteration = 0
            MyFractalDim = 0
        End If

        PriceMax = Highest(Close, N, 0)
        PriceMin = Lowest(Close, N, 0)
        Length = 0
        PriorDiff = 0
        For Iteration = 1 To N - 1
            If PriceMax - PriceMin > 0 Then
                Diff = (Close[Iteration] - PriceMin) /     (PriceMax - PriceMin)
                If Iteration > 1 and N <> 0 Then
                    Length = Length + Sqr(Sqr(Diff -       PriorDiff) + (1 / Sqr (N)))
                End If
                PriorDiff = Diff
            End If
        Next
        If Length > 0 and N <> 0 Then
            MyFractalDim = 1 + (log(Length)+ log(2)) / log(2 * N)
        Else
            MyFractalDim = 0
        End If
        FDI = MyFractalDim
    End Function

     

    Here is The Code for the System

    Option Explicit

    Function FDI(N) As BarArray
        Dim Diff As BarArray
        Dim Length As BarArray
        Dim PriceMax As BarArray
        Dim PriceMin As BarArray
        Dim PriorDiff As BarArray
        Dim Iteration As BarArray
        Dim MyFractalDim

        If BarNumber=FirstBar Then
            Diff = 0
            Length = 0
            PriceMax = 0
            PriceMin = 0
            PriorDiff = 0
            Iteration = 0
            MyFractalDim = 0
        End If

        PriceMax = Highest(Close, N, 0)
        PriceMin = Lowest(Close, N, 0)
        Length = 0
        PriorDiff = 0
        For Iteration = 1 To N - 1
            If PriceMax - PriceMin > 0 Then
                Diff = (Close[Iteration] - PriceMin) /     (PriceMax - PriceMin)
                If Iteration > 1 and N <> 0 Then
                    Length = Length + Sqr(Sqr(Diff -       PriorDiff) + (1 / Sqr (N)))
                End If
                PriorDiff = Diff
            End If
        Next
        If Length > 0 and N <> 0 Then
            MyFractalDim = 1 + (log(Length)+ log(2)) / log(2 * N)
        Else
            MyFractalDim = 0
        End If
        FDI = MyFractalDim
    End Function

    Sub Fractal(Length, Length2, C1, C2)
        Dim Value1 As BarArray
        Dim Value2 As BarArray

        If BarNumber=FirstBar Then
            'Length = 70
            'Length2 = 10
            'C1 = 6
            'C2 = 67
            Value1 = 0
            Value2 = 0
        End If

        Value1=(FDI(Length))
        Value2=(WeightedMa(Value1,Length2,0))
        If Value1>Value2 and CCI(c1, 0)        Buy("", 1, Highest(high, 3, 0)+ 1*GetActiveMinMove(), Stop, Day)
        End If
        If Value1c2 and close        ExitLong("", "", 1, Lowest(close, 1, 0)- 1*GetActiveMinMove(), Stop, Day)
        End If
    End Sub

    mur ang
    Advanced Member
    Advanced Member
    Posts:525

    --
    05-13-2007 10:26 AM

    Please look at your If -Thens , They are wrong. In one your missing the Then and in the other your missing part of the condition.

     

    You are not authorized to post a reply.


     TradersStudio, Inc. ® Copyright 2004-2012 All Rights Reserved   Terms Of Use  Privacy Statement