Tuesday, January 06, 2009     | Register
TradersStudio Forums
Subject: Program to Calculate Fractal Dimension of Waveforms

You are not authorized to post a reply.   
Author Messages
frasva
Posts:6

05-13-2007 7:51 AM Alert 

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

 

murray
Posts:435

05-13-2007 8:44 AM Alert 

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

frasva
Posts:6

05-13-2007 9:32 AM Alert 

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

murray
Posts:435

05-13-2007 10:26 AM Alert 

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.
Forums > TradersStudio 2.x > TradersStudio Basic > Program to Calculate Fractal Dimension of Waveforms



ActiveForums 3.6
TradersStudio® Copyright 2004-2009 All Rights Reserved   |  Privacy Statement  |  Terms Of Use