Re: Fractal Dimension Index (FDI)
Publicado: 24 Oct 2016 00:53
Una opinioncita sobre el FDI, con poca experiencia sobre él: vale más como estudio que como indicador.
¿Dudas sobre trading? Plantea tus cuestiones sobre el funcionamiento del mercado, descarga indicadores y sistemas de trading y comparte tus operaciones con otros traders.
https://www.x-trader.net/foro/
¿Por qué?¿A qué te refieres?Wikmar escribió:vale más como estudio que como indicador.
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.mascara escribió:¿Por qué?¿A qué te refieres?Wikmar escribió:vale más como estudio que como indicador.
Gracias!
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();
}
}
Quizás implementando la interfaz IDrawingIndicator: https://www.dukascopy.com/wiki/#IDrawin ... _interfaceXavi 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.
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_interfaceXavi escribió:- Y los niveles de levels tampoco se puede verdad?