Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

JFException on Fractal indicator with filter ALL_FLATS
 Post subject: JFException on Fractal indicator with filter ALL_FLATS Post rating: 0   New post Posted: Fri 24 Jan, 2014, 14:40 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Hi,

Instead of using the simple fractal indicator, I am trying to us the one who's filtering candles, but get an exception.

Quote:
com.dukascopy.api.JFException: "to" parameter can't be greater than time of the last formed bar for this instrument


I realy don't understand, because there in no "to" parameter in this indicator call (from the javadoc : public double[][] fractal(Instrument instrument, Period period, OfferSide side, int barsOnSides, Filter filter, int numberOfCandlesBefore, long time, int numberOfCandlesAfter))

Simple :
fractal = indicators.fractal(instrument, period, OfferSide.BID, barsOnSide, i);


Filtering :
fractal = indicators.fractal(instrument, period, OfferSide.BID, barsOnSide, com.dukascopy.api.Filter.ALL_FLATS, i, bar.getTime(), 0);



The code I am using to get the last min of max fractals.

 private double getLastSwing(String __orderDirection, Instrument instrument, Period period, int barsOnSide, int nbFractalsBack) throws JFException {

        double lastFractalMax = Double.NaN;
        double lastFractalMin = Double.NaN;
        int i = 1;
        int fractalCount = 0;

        IBar bar = history.getBar(instrument, period, OfferSide.BID, 1);
       
        //fractalCount ++;
        if (__orderDirection.equals("Buy")) {

            while (fractalCount < nbFractalsBack) {
                double[][] fractal = null;
                try {

                   // fractal = indicators.fractal(instrument, period, OfferSide.BID, barsOnSide, i);
                    fractal = indicators.fractal(instrument, period, OfferSide.BID, barsOnSide, com.dukascopy.api.Filter.ALL_FLATS, i, bar.getTime(), 0);
                } catch (JFException ex) {
                    printOut.print("msg : " + ex);
                }
                if (!Double.isNaN(fractal[1][0])) {
                    lastFractalMin = fractal[1][0];
                    fractalCount++;
                }
                i++;
            }
            return lastFractalMin;

        } else {

            while (fractalCount < nbFractalsBack) {
                double[][] fractal = null;
                try {
                   // fractal = indicators.fractal(instrument, period, OfferSide.ASK, barsOnSide, i);
                    fractal = indicators.fractal(instrument, period, OfferSide.ASK, barsOnSide, com.dukascopy.api.Filter.ALL_FLATS, i, bar.getTime(), 0);
                } catch (JFException ex) {
                    printOut.print("msg : " + ex);
                }
                if (!Double.isNaN(fractal[0][0])) {
                    lastFractalMax = fractal[0][0];
                    fractalCount++;
                }
                i++;
            }
            return lastFractalMax;
        }
    }


Thanks for the help


 
 Post subject: Re: JFException on Fractal indicator with filter ALL_FLATS Post rating: 0   New post Posted: Tue 11 Feb, 2014, 16:14 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Did someone have this issue ?

Dukaskopy support may have an answer ?

Thanks


 
 Post subject: Re: JFException on Fractal indicator with filter ALL_FLATS Post rating: 0   New post Posted: Wed 12 Feb, 2014, 10:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Our developer did investigate on this. The Fractal indicator has a positive lookforward and the reason for the exception is interval validation on the side of IHistory.


 
 Post subject: Re: JFException on Fractal indicator with filter ALL_FLATS Post rating: 0   New post Posted: Wed 12 Feb, 2014, 10:33 
User avatar

User rating: 5
Joined: Fri 02 Sep, 2011, 10:08
Posts: 157
Location: FranceFrance
Quote:
The Fractal indicator has a positive lookforward and the reason for the exception is interval validation on the side of IHistory.


So how should I modify my code in order to make this work ?

Thanks


 
 Post subject: Re: JFException on Fractal indicator with filter ALL_FLATS Post rating: 0   New post Posted: Fri 14 Feb, 2014, 10:30 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You should make sure that the barsOnSides parameter which is a look-forward parameter does not correspond to a bar which has not started forming yet. Consider the following example strategy:
package jforex.requests;

import java.util.Arrays;

import com.dukascopy.api.Filter;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;

public class FractalsFlats implements IStrategy {

    private IIndicators indicators;
    private IConsole console;

    @Override
    public void onStart(IContext context) throws JFException {
        indicators = context.getIndicators();
        console = context.getConsole();
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (instrument != Instrument.EURUSD || period != Period.TEN_SECS) {
            return;
        }
        for (int barsOnSides = 2; barsOnSides < 5; barsOnSides++) {
            for (int shift = 1; shift < 5; shift++) {
                try {
                    double[][] fractals = indicators.fractal(instrument, period, OfferSide.BID, barsOnSides, Filter.ALL_FLATS, 3,
                            bidBar.getTime() - (shift - 1) * period.getInterval(), 0);
                    console.getOut().format("shift=%s barsOnSides=%s 0th=%s 1st=%s", shift, barsOnSides, Arrays.toString(fractals[0]), Arrays.toString(fractals[1])).println();
                } catch (JFException e) {
                    console.getErr().format("shift=%s barsOnSides=%s %s", shift, barsOnSides, e).println();
                }
            }
        }

    }

    @Override
    public void onMessage(IMessage message) throws JFException {
    }

    @Override
    public void onAccount(IAccount account) throws JFException {
    }

    @Override
    public void onStop() throws JFException {
    }

}

thus, barsOnSides should never exceed shift.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com