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
|