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.

Zig zag values in array
 Post subject: Zig zag values in array Post rating: 0   New post Posted: Mon 24 Oct, 2011, 10:24 

User rating: 0
Joined: Mon 17 Oct, 2011, 14:46
Posts: 5
Location: PL
Hello. Is it possible to fetch array of none null values of the zig zag indicator. I mean, I would like to have in array exactly what I see on the screen. actualized tick by tick . If not, is it possible to modify indicator code to do that? Could You give me a hint?


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Mon 24 Oct, 2011, 11:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See the following example:
https://www.dukascopy.com/wiki/index.php ... ing_values
Instead of MAX, use ZIGZAG and move the printing logic to onTick method. In addition, apply tick filtering, see:
https://www.dukascopy.com/wiki/index.php ... Ticks/Bars


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 07:50 

User rating: 0
Joined: Mon 17 Oct, 2011, 14:46
Posts: 5
Location: PL
I wrote this:
package jforex.test;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IIndicators.MaType;

/**
 * The following strategy demonstrates how to log the most commonly used
 * values and arrays of values in in JForex API
 *
 */
public class LoggingValues implements IStrategy {
   
   private IConsole console;
   private IHistory history;
   private IIndicators indicators;
        private double[] maxArr ;
       
   @SuppressWarnings("serial")
   public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") {
      {
         setTimeZone(TimeZone.getTimeZone("GMT"));
      }
   };
   public static DecimalFormat df = new DecimalFormat("0.00000");

   
   public void onStart(IContext context) throws JFException {
      console = context.getConsole();
      history = context.getHistory();
      indicators = context.getIndicators();
      
      IBar prevBar = history.getBar(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, 1);
      long time = prevBar.getTime();
      
      
      
      //log 1-dimensional array
       maxArr = indicators.zigzag (Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, 12, 5, 3, Filter.NO_FILTER, 500, time, 0);
      
      
      
      context.stop();
   }
   
   

   
   public void onTick(Instrument instrument, ITick tick) throws JFException {
            if (!instrument.equals(Instrument.EURUSD)) return;
            print("1-dimensional zigzag indicator result array: " + arrayToString(maxArr));
        }

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

   
   public void onMessage(IMessage message) throws JFException {}

   
   public void onAccount(IAccount account) throws JFException {}

   
   public void onStop() throws JFException {}
       
       
       
       
        /********************************************************************************************************/
       
       
        private void print(Object o){
      console.getOut().println(o);
   }
   
   public static String arrayToString(double[] arr) {
      String str = "";
      for (int r = 0; r < arr.length; r++) {
         str += "[" + r + "] " + df.format(arr[r]) + "; ";
      }
      return str;
   }
}


The problem is, i don't see any messages, but i think i should.


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 09:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This stops the strategy before any onTick call happens:
context.stop();


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 10:27 

User rating: 0
Joined: Mon 17 Oct, 2011, 14:46
Posts: 5
Location: PL
Sorry for bodering, but i try to use this call for zigzag indicator, and i don't know what date format should i use. (ofcourse i suppose "from" , and "to" are arguments that indicates date(i am wondering why "from" and "to" are long type )


double[] zigzag(Instrument instrument,
Period period,
OfferSide side,
int extDepth,
int extDeviation,
int extBackstep,
long from,
long to)
throws JFException


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 11:02 

User rating: 0
Joined: Mon 17 Oct, 2011, 14:46
Posts: 5
Location: PL
Maybe I will describe more precisely, what I want to achieve. I want an Array with values of the „tops” and „bottoms” which show zigzag indicator. I want exactly, what I see on the screen. The problem is that when I fetch a table with ZigZag values I receive values actualized over a chosen period. For example, when I use this in onTick() method

zigZagArray = indicators.zigzag (Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, 5, 5, 5, Filter.NO_FILTER, 100, time, 0);

I receive an array on every tick, but this array changes only once per 10 second, what is problematic because I do not get last correct value of zigzag indicator (I can say it is not recalculating)

On the other hand, on the screen, last value of the indicator is changing on almost every tick (it is recalculating I think)

I see second problem. Output of the Zigzag indicator don't show top and bottoms but every value, and i don't know if it is final value(top or bottom)


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 12:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
NewPlayer wrote:
I see second problem. Output of the Zigzag indicator don't show top and bottoms but every value, and i don't know if it is final value(top or bottom)
This is as designed - the indicator just connects the low and high points, the others are Double.NaN.
NewPlayer wrote:
I receive an array on every tick, but this array changes only once per 10 second, what is problematic because I do not get last correct value of zigzag indicator (I can say it is not recalculating)
Please try the following strategy:
package jforex.test;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import com.dukascopy.api.*;

/**
 * The following strategy demonstrates how to log Zig zag values -
 * both the current value and an array of last values
 *
 */
public class LoggingValuesZigZag2 implements IStrategy {
   
   private IConsole console;
   private IHistory history;
   private IIndicators indicators;
   
   @Configurable("period")
   public Period period = Period.TEN_SECS;
   @Configurable("instrument")
   public Instrument instrument = Instrument.EURUSD;
   @Configurable("offer side")
   public OfferSide side = OfferSide.BID;
   @Configurable("value count")
   public int valueCount = 50;
   @Configurable("extDepth")
   public int extDepth = 2;
   @Configurable("extDeviation")
   public int extDeviation = 5;
   @Configurable("extBackstep")
   public int extBackstep = 3;   
   
   @SuppressWarnings("serial")
   public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") {
      {   
         setTimeZone(TimeZone.getTimeZone("GMT"));
      }
   };
   public static DecimalFormat df = new DecimalFormat("0.00000");

   @Override
   public void onStart(IContext context) throws JFException {
      console = context.getConsole();
      history = context.getHistory();
      indicators = context.getIndicators();
   }
   
   private void print(Object o){
      console.getOut().println(o);
   }
   
   public static String arrayToString(double[] arr) {
      String str = "";
      for (int r = 0; r < arr.length; r++) {
         str += "[" + r + "] " + df.format(arr[r]) + "; ";
      }
      return str;
   }
   
   @Override
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      if(instrument != this.instrument){
         return;
      }
      double zigZag = indicators.zigzag(instrument, period, side, extDepth, extDeviation, extBackstep, 0);
      print ("Zig zag current value: " + df.format(zigZag));
   }

   @Override
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {      
      if(period!= this.period || instrument != this.instrument){
         return;
      }
      
      long time = bidBar.getTime();
      //log 1-dimensional array
      double[] zigZagArr = indicators.zigzag(instrument, period, side, extDepth, extDeviation, extBackstep, Filter.NO_FILTER, valueCount, time, 0);      
      print("zig zag result array: " + arrayToString(zigZagArr));

      //print non-empty values
      List<IBar> bars = history.getBars(instrument, period, side, time - (valueCount - 1)  * period.getInterval(), time );
      for (int i = 0; i< zigZagArr.length; i++){
         if ( !Double.isNaN( zigZagArr[i]) ){
            print (sdf.format(bars.get(i).getTime()) + " - " + df.format(zigZagArr[i]) + " " + Double.isNaN( zigZagArr[i]));
         }
      }
      
   }

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

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

   @Override
   public void onStop() throws JFException {}

}


 
 Post subject: Re: Zig zag values in array Post rating: 0   New post Posted: Tue 25 Oct, 2011, 12:49 

User rating: 0
Joined: Mon 17 Oct, 2011, 14:46
Posts: 5
Location: PL
Thank You very much for Your help.


 

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