Fractal Dimension Index (FDI)

Todo sobre el trading en los mercados financieros: funcionamiento, dudas, noticias, etc.
Avatar de Usuario
Wikmar
Mensajes: 3868
Registrado: 29 Sep 2010 00:01
Ubicación: Madrid

Re: Fractal Dimension Index (FDI)

Mensaje por Wikmar »

Una opinioncita sobre el FDI, con poca experiencia sobre él: vale más como estudio que como indicador.
            https://wikmar.wordpress.com
            Si quieres algo de privacidad, cuidado con las Nubes, que nadie ha conseguido todavía ponerles una puerta.
Avatar de Usuario
mascara
Mensajes: 344
Registrado: 18 Oct 2007 23:15

Re: Fractal Dimension Index (FDI)

Mensaje por mascara »

Wikmar escribió:vale más como estudio que como indicador.
¿Por qué?¿A qué te refieres?

Gracias!
Avatar de Usuario
Wikmar
Mensajes: 3868
Registrado: 29 Sep 2010 00:01
Ubicación: Madrid

Re: Fractal Dimension Index (FDI)

Mensaje por Wikmar »

mascara escribió:
Wikmar escribió:vale más como estudio que como indicador.
¿Por qué?¿A qué te refieres?

Gracias!
Porque el periodo que trae por defecto (30, creo recordar), o recomendado, me pareció correcto (menos periodo, da ruido en la indicación), pero, la indicación que da, describe marcadamente el pasado. Va con retraso probablemente por idiosincrasia del propio diseño.

Un saludo.
            https://wikmar.wordpress.com
            Si quieres algo de privacidad, cuidado con las Nubes, que nadie ha conseguido todavía ponerles una puerta.
Xavi
Mensajes: 27
Registrado: 04 May 2006 14:53

Re: Fractal Dimension Index (FDI)

Mensaje por Xavi »

Buenas.

Mascara comprobe el indicador para JForex y..casiiii :-D .
No daba los valores que debia.
Con tu permiso he cogido tu codigo y lo he modificado, ahora me da los mismos valores que en MT4.
Principalmente el bucle interno lo tenias incorrecto, la linea:
Diff = (inputs[0][idx] - PriceMin) / (PriceMax - PriceMin);
Solo tenias en cuenta idx que siempre era empezaba por 0 y te faltaba tener en cuenta sobre la i tambien:
Diff = (inputs[0][i-idx] - PriceMin) / (PriceMax - PriceMin);

Cogias siempre i y

Código: Seleccionar todo

package jforex;

import com.dukascopy.api.indicators.*;
import com.dukascopy.api.*;

import java.util.List;
import java.awt.*;
import java.math.BigDecimal;

public class FractalDimensionIndex implements IIndicator{
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos;
    
    private double[][] inputs  = new double[1][];    
    private double[][] outputs = new double[2][];
    
    private int timePeriod     = 14;
    private double FdiLinea    = 1.5;
    private IIndicator max;
    private IIndicator min;
    private Color Blue = new Color(64, 64, 225);

    private IHistory history; 
    private IConsole console; 
    
    public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("FDI", "Fractal Dimension Index", "My indicators",false, false, false, 1, 2, 2);
        
        inputParameterInfos = new InputParameterInfo[] {
            new InputParameterInfo("Input data", InputParameterInfo.Type.DOUBLE)
        };
        
        optInputParameterInfos = new OptInputParameterInfo[] {
            new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(14, 2, 100, 1)),

            new OptInputParameterInfo("FDILINEAI", OptInputParameterInfo.Type.OTHER, new DoubleRangeDescription(1.5, 0.0, 3.0, 0.05,1)), 
     
        };
        
        
        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("FDI", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
            
            new OutputParameterInfo("FDILINEA", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.DASH_LINE),   
                
                       
        };
       
        outputParameterInfos[0].setColor(Blue);
       
        IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
        max = indicatorsProvider.getIndicator("MAX");
        min = indicatorsProvider.getIndicator("MIN");
        
        console = context.getConsole();
    }

    public IndicatorResult calculate(int startIndex, int endIndex) {
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }        
        
        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }

        double[] outsMax = new double[outputs[0].length];
        double[] outsMin = new double[outputs[0].length];
        double Diff      = 0;
        double Length    = 0;
        double PriceMax  = 0;
        double PriceMin  = 0;
        double PriorDiff = 0;
        double FractalDI = 0;
        int i, j;
                     
        max.setInputParameter(0, inputs[0]);
        max.setOptInputParameter(0, timePeriod);
        max.setOutputParameter(0, outsMax);
        max.calculate(startIndex, endIndex);
       
        min.setInputParameter(0, inputs[0]);
        min.setOptInputParameter(0, timePeriod);
        min.setOutputParameter(0, outsMin);
        min.calculate(startIndex, endIndex);

       
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
       
            PriceMax = outsMax[i-timePeriod+1];
            PriceMin = outsMin[i-timePeriod+1];
            Length = 0 ;
            PriorDiff = 0 ;
            
            
            for (int idx = 0; idx  < timePeriod-1; idx++)   
            {
                if ( (PriceMax - PriceMin) > 0)
                {
                    Diff = (inputs[0][i-idx] - PriceMin) / (PriceMax - PriceMin);
                    if (idx > 0) {
                        Length = Length + Math.sqrt(  Math.pow(Diff - PriorDiff,2) + (1.0 / Math.pow(timePeriod,2) )    );
                    }                    
                    PriorDiff = Diff  ; 
                }
            }

            if (Length > 0) {
                FractalDI = 1 + ( Math.log( Length )+ Math.log( 2 ) ) / Math.log( 2 * timePeriod );
            }
            else FractalDI = 0 ;

             
            outputs[0][j] = Xround(FractalDI,4); 
            outputs[1][j] = 1.51234; //FdiLinea; 
            
            

        }       

        return new IndicatorResult(startIndex, j );

    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        if (index < inputParameterInfos.length) {
            return inputParameterInfos[index];
        }
        return null;
    }

    public int getLookback() {
     max.setOptInputParameter(0, timePeriod);
     min.setOptInputParameter(0, timePeriod);

     return Math.max(max.getLookback(), min.getLookback());       
    }

    public int getLookforward() {
        return 0;
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index) {
        if (index < optInputParameterInfos.length) {
            return optInputParameterInfos[index];
        }
        return null;
    }

    public OutputParameterInfo getOutputParameterInfo(int index) {
        if (index < outputParameterInfos.length) {
            return outputParameterInfos[index];
        }
        return null;
    }

    public void setInputParameter(int index, Object array) {
        inputs[index] = (double[]) array;
    }

    public void setOptInputParameter(int index, Object value) {
       if(index==0) timePeriod = (Integer) value;
       if(index==1) FdiLinea   = (Double) value;
    }

    public void setOutputParameter(int index, Object array) {
        outputs[index] = (double[]) array;
    }
    
    private static double Xround(double amount, int decimalPlaces) {
        return (new BigDecimal(amount)).setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
        
}


Avatar de Usuario
mascara
Mensajes: 344
Registrado: 18 Oct 2007 23:15

Re: Fractal Dimension Index (FDI)

Mensaje por mascara »

Muchas gracias por tomarte el tiempo y las molestias de probarlo y corregirlo!!! Voy a actualizarmelo :D

Xavi
Mensajes: 27
Registrado: 04 May 2006 14:53

Re: Fractal Dimension Index (FDI)

Mensaje por Xavi »

De nada ;)
Aunque en realidad es que lo necesitaba tambien y no lo encontraba por ningun sitio.

Estoy migrando a Jforex y la verdad que comparando con MQL y Mt4 es una maravilla, lo que me estraña es que la use tan poca gente, supongo que por aquello del marqueting.
O A parte de que solo conozco Dukascopy que la use, supongo que al ser propia no la quedran abrir a otros brokers o a saber.
Una pena porque creo que le da mil pataditas a MT4.

Por cierto un par de dudas:
- Sabes si se puede programar en el indicador que si supera por ejemplo la linea del 1.5 cambie de color? por lo que veo no.
- Y los niveles de levels tampoco se puede verdad?

Saludos.
Avatar de Usuario
mascara
Mensajes: 344
Registrado: 18 Oct 2007 23:15

Re: Fractal Dimension Index (FDI)

Mensaje por mascara »

Xavi escribió:- Sabes si se puede programar en el indicador que si supera por ejemplo la linea del 1.5 cambie de color? por lo que veo no.
Quizás implementando la interfaz IDrawingIndicator: https://www.dukascopy.com/wiki/#IDrawin ... _interface
Xavi escribió:- Y los niveles de levels tampoco se puede verdad?
Si te refieres a la escala que aparece a la derecha, sé que se puede definir el máximo y el mínimo, pero no he mirado mucho más allá. Se hace implementando la interfaz IMinMax https://www.dukascopy.com/wiki/#IMinMax_interface

Saludos,
paulriver
Mensajes: 1
Registrado: 06 Sep 2018 22:09

Re: Fractal Dimension Index (FDI)

Mensaje por paulriver »

Buenas noches,
He "corregido un poco" el código anterior. Ahora si los resultados son iguales que el indicador FDI incluido en Prorealtime.


ONCE FDI=UNDEFINED

N=30
diff=0
length = 0
pdiff = 0
FDI=0
HH = HIGHEST[N](CLOSE)
LL = LOWEST[N](CLOSE)


IF BARINDEX >= N-1 THEN
FOR period = 0 TO N-1 DO
IF (HH - LL) > 0 THEN
diff = (CUSTOMCLOSE[Period] - LL) / (HH - LL)
IF period > 0 THEN
length = length + SQRT(SQUARE(diff - pdiff) + (1 / SQUARE(N)))
ENDIF
pdiff = diff
ENDIF
NEXT


IF length > 0 THEN
FDI = 1 + (LOG(length) + LOG(2)) / LOG(2 * (N))
ELSE
FDI = 0
ENDIF
ENDIF

RETURN FDI AS "Fractal Dimension Index"





Salu2!
Si te ha gustado este hilo del Foro, ¡compártelo en redes!


Responder

Volver a “Trading en General”