Dukascopy
 
 
Wiki JStore Search Login

bug in zigzag
 Post subject: bug in zigzag Post rating: 0   New post Posted: Wed 20 Mar, 2013, 10:37 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
The following strategy generates wrong zigzag values in the Historical Tester.
Timeperiod: 30 mins
instrument: EUR/USD
tested interval: from 2011/01/01

package jforex.strategies.indicators;
 
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
 
 
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.MaType;
import com.dukascopy.api.indicators.IIndicator;
 
/**
 * The strategy finds the last not null zigzag value unless it is more than
 * [previousValueArraySize] candles in the past
 */
 
public class ZigZag implements IStrategy {
   private IConsole console;
   private IIndicators indicators;
   private IChart chart;
   
   @Configurable("Instrument")
   public Instrument instrument = Instrument.EURUSD;
   @Configurable("Period")
   public Period selectedPeriod = Period.TEN_MINS;
   
   //Zigzag parameters
   private int extDepth = 12;
   private int extDeviation = 5;
   private int extBackstep = 3;
   private int previousValueArraySize = 50;
   
   private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
   public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.indicators = context.getIndicators();
      this.chart = context.getChart(instrument);
 
      sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
       
      print("start " + this.getClass().getSimpleName());
   
      //uncomment to plot the indicator on the chart - this slows down the historical testing
      //chart.addIndicator(indicators.getIndicator("ZIGZAG"), new Object[]{extDepth, extDeviation, extBackstep });
   
   }
 
 
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
 
      if (!instrument.equals(this.instrument) || !period.equals(selectedPeriod))
         return;
       
      //the current zigzag value
      double zigzag = indicators.zigzag(instrument, period, OfferSide.BID, extDepth, extDeviation, extBackstep, 1);
      //the last [previousValueArraySize] values
      double[] zigzagArray = indicators.zigzag(instrument, period, OfferSide.BID, extDepth, extDeviation, extBackstep,
            Filter.NO_FILTER, previousValueArraySize, bidBar.getTime(), 0 );
 
      double zigzagLastNotNull = Double.NaN;
      int zigzagLastNotNullIndex = -1;
      //find the latest not null zigzag value (newest values are at the end of the value array)
      for(int i = previousValueArraySize -1 ; i > -1 ; i--){
         if (!Double.valueOf(zigzagArray[i]).isNaN()){
            zigzagLastNotNull = zigzagArray[i];
            zigzagLastNotNullIndex = i;
            break;
         }
      }
       
      print(sdf.format(bidBar.getTime()) + " last zigzag=" + zigzag
             + "; last not null zigzag=" +zigzagLastNotNull  +" canldes back: " +  (previousValueArraySize - zigzagLastNotNullIndex)
            + "; last " +previousValueArraySize+ " values: " + arrayToString(zigzagArray)            );
 
   }
   
   private void print(Object message) {
      console.getOut().println(message);
   }
   
   public static String arrayToString(double [] arr){
      String str = "";
      for (int r=0; r<arr.length; r++) {
             str += " [" + r + "]" + (new DecimalFormat("0.000000")).format(arr[r]) + ", ";
          }
      return str;
   }
 
   public void onAccount(IAccount account) throws JFException {   }
   public void onMessage(IMessage message) throws JFException {   }
   public void onStop() throws JFException {   }
   public void onTick(Instrument instrument, ITick tick) throws JFException {   }
}


As visible on the screenshot, the strategy calculates valid zigzag values at 00:00, 00:30, 01:00 and at 01:30 on 2011/01/04.
However the zigzag indicator on the chart shows valid zigzag values at 16:00 on 2011/01/03 and at 01:30 on 2011/01/04.

And this is not the only timeframe when the strategy generates valid zigzag values for consecutive bars. For example:
From 2011/01/05 00:00 there are 4 consecutive bars with `valid` zigzag value.
From 2011/01/05 07:00 there are 4 consecutive bars with `valid` zigzag value.
From 2011/01/06 07:00 there are 2 consecutive bars with `valid` zigzag value.
and so on...


Note: This strategy was provided by support here: viewtopic.php?f=6&t=38916
By the way, why is that topic locked?

Image


Attachments:
File comment: screenshot with the problem
Untitled.jpg [531.25 KiB]
Downloaded 949 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: bug in zigzag Post rating: 0   New post Posted: Wed 20 Mar, 2013, 15:34 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Why does this topic moved to platform bugs? Is the indicator on chart calculates wrong values, and the strategy (which calls indicators.zigzag()) calculates the correct values? In this case it is a bug in the indicator on the chart. But I think it is the other way around, and the used indicators.zigzag() calculates wrong values.

Please let me know what is going on as I am struggling with this since a week (1st bug was reported on the 13th).


 
 Post subject: Re: bug in zigzag Post rating: 0   New post Posted: Thu 21 Mar, 2013, 13:41 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Another day is about to pass by, without a single word from Support.

This ain`t good...


 
 Post subject: Re: bug in zigzag Post rating: 0   New post Posted: Mon 25 Mar, 2013, 08:54 
JForex Master
User avatar

User rating:
Joined: Wed 16 Sep, 2009, 18:23
Posts: 1054
Location: Geneva, Switzerland
You need to filter the weekend flats on the chart in the preferences. Plus, the data on the chart looks to be incomplete as well (notice the flat candles besides the weekend). Remove the EURUSD price data in the platform cache, and try to load it again by opening the same period on the chart.

The picture attached shows the results on our end.
Image


Attachments:
ZigZag.png [189.53 KiB]
Downloaded 839 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: bug in zigzag Post rating: 0   New post Posted: Mon 25 Mar, 2013, 10:58 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Ahh, finally a reply :). You made my Monday morning!

I followed the guidelines and now it seems to work fine.
Thank you so much!


 

Jump to:  

cron
  © 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