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.

Problem with fractal indicator
 Post subject: Problem with fractal indicator Post rating: 0   New post Posted: Thu 20 Oct, 2011, 19:57 
User avatar

User rating: 0
Joined: Thu 20 Oct, 2011, 19:50
Posts: 3
Location: Bulgaria, Bnakya
The following code gives me exception. Please help me
....
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateFrom = dateFormat.parse("01/08/2008 00:00:00");
Date dateTo = dateFormat.parse("31/08/2011 00:00:00");
Instrument instrument = Instrument.EURUSD;
long fromTime = dateFrom.getTime();
long toTime = dateTo.getTime();
double[][] fractal = indicators.fractal(instrument, Period.ONE_HOUR, OfferSide.ASK, 2, fromTime, toTime);
...

Exception thrown while running onMessage method: Interval from [2008.07.31 22:00:00 000] to [1969.12.31 23:00:00 000] GMT is not valid for period [Hourly]


 
 Post subject: Re: Problem with fractal indicator Post rating: 0   New post Posted: Fri 21 Oct, 2011, 10:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We were not able to reproduce the error. We tried with the following strategy:
package jforex.bugtests;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IEngine;
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;
import com.dukascopy.api.IEngine.OrderCommand;

public class FractalTest2 implements IStrategy {

   IIndicators indicators;
   IContext context;
   IConsole console;
   IEngine engine;
   
   @Override
   public void onStart(IContext context) throws JFException {
      
      indicators = context.getIndicators();
      this.context = context;
      console = context.getConsole();
      engine = context.getEngine();
      
      //submit an order just to cause onMessage to get called
      engine.submitOrder("order1", Instrument.EURUSD, OrderCommand.BUY, 0.001);
   }
   
   @Override
   public void onMessage(IMessage message) throws JFException {
      calcFractal();
   }
   
   private void calcFractal() throws JFException{
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
      dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
      Date dateFrom = null;
      Date dateTo = null;
      try {
         dateFrom = dateFormat.parse("01/08/2008 00:00:00");
         dateTo = dateFormat.parse("31/08/2011 00:00:00");
      } catch (ParseException e) {
         context.getConsole().getErr().println(e);
      }

      Instrument instrument = Instrument.EURUSD;
      long fromTime = dateFrom.getTime();
      long toTime = dateTo.getTime();
      
      double[][] fractal = indicators.fractal(instrument, Period.ONE_HOUR, OfferSide.ASK, 2, fromTime, toTime);
      context.getConsole().getOut().println(fractal[0][0]);
   }

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

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

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

   @Override
   public void onStop() throws JFException {}

}


Attachments:
FractalTest2.java [2.3 KiB]
Downloaded 300 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Problem with fractal indicator Post rating: 0   New post Posted: Fri 21 Oct, 2011, 20:24 
User avatar

User rating: 0
Joined: Thu 20 Oct, 2011, 19:50
Posts: 3
Location: Bulgaria, Bnakya
Thanks for answer, but I receive the exception. I found a working solution, when I move the code from onMessage to onTick it works properly.


 

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