|
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.
ZigZag values |
lil
|
Post subject: ZigZag values |
Post rating: 0
|
Posted: Sat 28 Sep, 2013, 15:53
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
I'm having big troubles to get the same values of zigzag indicator in the api, compared to the ones drawn automatically in charts. many more values get returned below the images of my attempts using zigzag(..., shift) and zigzag(..., before, time, after)My goal was to get the last 3 zigzag values from current time, but using the API I get different values, from the ones in red. code: package jforex;
import com.dukascopy.api.*; import com.dukascopy.api.drawings.IChartObjectFactory; import com.dukascopy.api.drawings.IHorizontalLineChartObject; import com.dukascopy.api.drawings.IShortLineChartObject; import com.dukascopy.api.drawings.IVerticalLineChartObject;
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*;
public class Strategy5 implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IIndicators indicators; private IChartObjectFactory factory; private IChart chart; @Configurable("Instrument 1") public Instrument instrument1 = Instrument.EURUSD; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int lines=0; // for chart
public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.indicators = context.getIndicators(); df.setTimeZone(TimeZone.getTimeZone("GMT")); chart = context.getChart(instrument1); factory = chart.getChartObjectFactory();
}
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 {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (instrument==instrument1){ if( period==Period.TEN_SECS){ double[] z = getLast3Z(askBar.getTime()); //double[] z = getLast3ZZ(askBar.getTime()); //print(df.format(askBar.getTime()), z[0], z[1], z[2]); } } } public double getLastZZ(long t, int shift) throws JFException{ double zz = indicators.zigzag(instrument1, Period.TEN_SECS, OfferSide.BID, 20, 5, 3, shift); if (Double.isNaN(zz)) return getLastZZ(t, shift+1); else return zz; } public double[] getLast3Z(long t) throws JFException{
double z1 = 0, z2 = 0, z3 = 0;
double[] ar = indicators.zigzag(instrument1, Period.TEN_SECS, OfferSide.ASK, 20, 5, 3, Filter.ALL_FLATS, t-Period.THIRTY_MINS.getInterval(), t-Period.TEN_SECS.getInterval()); for (int i=0; i<ar.length-1; i++){ if (!Double.isNaN(ar[i])){ z1 = ar[i]; for (int j=i+1; j<ar.length-1; j++){ if (!Double.isNaN(ar[j])){ z2=ar[j]; for (int k=j+1; k<ar.length-1; k++){ if (!Double.isNaN(ar[k])){ z3=ar[k]; IHorizontalLineChartObject shortLine = factory.createHorizontalLine("line"+lines++, z1); chart.add(shortLine); IHorizontalLineChartObject shortLine2 = factory.createHorizontalLine("line"+lines++, z2); chart.add(shortLine2); IHorizontalLineChartObject shortLine3 = factory.createHorizontalLine("line"+lines++, z3); chart.add(shortLine3); return new double[]{z1, z2, z3}; } } } } } } return new double[]{z1, z2, z3}; } public double[] getLast3ZZ(long t) throws JFException{ int shift=0; double zz=Double.NaN, z1, z2, z3; while(Double.isNaN(zz)){ zz = indicators.zigzag(instrument1, Period.TEN_SECS, OfferSide.BID, 20, 5, 3, shift); shift++; } z1 = zz; long t1=t-shift*Period.TEN_SECS.getInterval(); zz=Double.NaN; while(Double.isNaN(zz)){ zz = indicators.zigzag(instrument1, Period.TEN_SECS, OfferSide.BID, 20, 5, 3, shift); shift++; } z2 = zz; long t2=t-shift*Period.TEN_SECS.getInterval(); IShortLineChartObject shortLine = factory.createShortLine("line"+lines++, t1, z1, t2, z2); chart.add(shortLine); zz=Double.NaN; while(Double.isNaN(zz)){ zz = indicators.zigzag(instrument1, Period.TEN_SECS, OfferSide.BID, 20, 5, 3, shift); shift++; } z3 = zz; long t3=t-shift*Period.TEN_SECS.getInterval(); IShortLineChartObject shortLine2 = factory.createShortLine("line"+lines++, t2, z2, t3, z3); chart.add(shortLine2); return new double[]{z1, z2, z3}; }
}   
Attachments: |
zz2.png [83.64 KiB]
Downloaded 588 times
|
zz2.png [35.82 KiB]
Downloaded 581 times
|
zz1.png [50.13 KiB]
Downloaded 552 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.
|
|
|
|
|
 |
tcsabina
|
Post subject: Re: ZigZag values |
Post rating: 1
|
Posted: Sat 28 Sep, 2013, 19:04
|
|
User rating: 164
Joined: Mon 08 Oct, 2012, 10:35 Posts: 676 Location: NetherlandsNetherlands
|
Hi, I had issues with ZigZag too in the past. This topic covers the solution for it. Take a look on it, there is also an example strategy which does what you want.
|
|
|
|
 |
lil
|
Post subject: Re: ZigZag values |
Post rating: 0
|
Posted: Mon 30 Sep, 2013, 02:40
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Thx tcsabina, I have cleared all cache from the settings and manually in the folder, jforex charts are using the same Filter (Weekend), I'm testing the two zigzag methods, and both keep all intermediate values which you can see being drawn in real-time when a zigzag line is in formation Ideally I'd like to get only the zigzag points drawn in chart. Thanks support package jforex;
import com.dukascopy.api.*; import com.dukascopy.api.IEngine.OrderCommand; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.IIndicators.MaType; import com.dukascopy.api.IOrder.State; import com.dukascopy.api.drawings.IChartObjectFactory; import com.dukascopy.api.drawings.IHorizontalLineChartObject; import com.dukascopy.api.drawings.IShortLineChartObject; import com.dukascopy.api.drawings.IVerticalLineChartObject;
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*;
public class Strategy5 implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IIndicators indicators; private IChartObjectFactory factory; private IChart chart; //@Configurable("Instrument 1") public Instrument instrument1 = Instrument.EURUSD; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int lines=0; // chart label int ords=0; // orders label IAccount account;
boolean isIntra = false; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.indicators = context.getIndicators(); df.setTimeZone(TimeZone.getTimeZone("GMT")); chart = context.getChart(instrument1); factory = chart.getChartObjectFactory();
}
public void onAccount(IAccount a) throws JFException { account = a; }
public void onMessage(IMessage m) throws JFException { } public void onStop() throws JFException { print("stop: ", account.getBalance(), account.getEquity()); } public void onTick(Instrument instrument, ITick tick) throws JFException { } List<Double> z1= new ArrayList<Double>(), z2= new ArrayList<Double>(); public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (instrument==instrument1){ if(period ==Period.ONE_HOUR){ df.getCalendar().setTimeInMillis(bidBar.getTime()); isIntra= df.getCalendar().get(Calendar.HOUR_OF_DAY)>=9 && df.getCalendar().get(Calendar.HOUR_OF_DAY)<=17;
} else if( period==Period.ONE_MIN){ if (isIntra){ for (int i=0; i<60; i++){ double zz= indicators.zigzag(instrument1, Period.ONE_SEC, OfferSide.BID, 200, 5, 3, i); if (!Double.isNaN(zz)) z1.add(0, zz); } double[] e= indicators.zigzag(instrument1, Period.ONE_SEC, OfferSide.BID, 200, 5, 3, Filter.WEEKENDS, 60, bidBar.getTime(), 0); for (double d : e){ if (!Double.isNaN(d)) z2.add(0, d); } print(df.format(bidBar.getTime())); print(z1); print(z2); } } } } public void print(Object... vals){ String s=""; for (Object v : vals) s+=v+", "; console.getOut().println(s) ; } public void print(double... vals){ String s=""; for (double v : vals) s+=v+", "; console.getOut().println(s) ; } public void print(List<?>... vals){ String s=""; for (Object v : vals) s+=v+", "; console.getOut().println(s) ; } } 
|
|
|
|
 |
lil
|
Post subject: Re: ZigZag values |
Post rating: 0
|
Posted: Tue 01 Oct, 2013, 00:10
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
I really hope for some help, zigzag indicator would be used in my strategy,
To summarize: the goal is to get the previous (or 2) segment exactly like the chart displays them, without extra values returned by indicators.zigzag api functions
|
|
|
|
 |
API Support
|
 |
Post subject: Re: ZigZag values |
Post rating: 0
|
Posted: Tue 01 Oct, 2013, 09:16
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
lil wrote: without extra values returned by indicators.zigzag api functions It's not API that returns "extra values", but your strategy which adds the values instead of replacing them when the trend does not change.
|
|
|
|
 |
lil
|
Post subject: Re: ZigZag values |
Post rating: 0
|
Posted: Tue 01 Oct, 2013, 10:38
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
API Support wrote: It's not API that returns "extra values", but your strategy which adds the values instead of replacing them when the trend does not change. yes thanks package jforex;
import com.dukascopy.api.*; import com.dukascopy.api.IEngine.OrderCommand; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.IIndicators.MaType; import com.dukascopy.api.IOrder.State; import com.dukascopy.api.drawings.IChartObjectFactory; import com.dukascopy.api.drawings.IHorizontalLineChartObject; import com.dukascopy.api.drawings.IShortLineChartObject; import com.dukascopy.api.drawings.IVerticalLineChartObject;
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*;
public class Strategy5 implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IIndicators indicators; private IChartObjectFactory factory; private IChart chart; //@Configurable("Instrument 1") public Instrument instrument1 = Instrument.EURUSD; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int lines=0; // chart label int ords=0; // orders label IAccount account; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.indicators = context.getIndicators(); df.setTimeZone(TimeZone.getTimeZone("GMT")); chart = context.getChart(instrument1); factory = chart.getChartObjectFactory();
}
public void onAccount(IAccount a) throws JFException { account = a; }
public void onMessage(IMessage m) throws JFException { } public void onStop() throws JFException { print("stop: "); double[] l= indicators.zigzag(instrument1, Period.ONE_SEC, OfferSide.BID, 200, 5, 3, Filter.WEEKENDS, from, to); for (int i=0; i<l.length; i++){ if (!Double.isNaN(l[i])){ //take first and loop with rest for (int j=i+1; j<l.length; j++){ if (!Double.isNaN(l[j])){ IShortLineChartObject shortLine = factory.createShortLine("line"+lines++, from + i*1000, l[i], from + j*1000, l[j]); chart.add(shortLine); i = j; } } } } } long from= 0L, to = 0L; public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if( period==Period.TEN_SECS){ if( instrument==instrument1){ to = bidBar.getTime(); if (from==0) from = bidBar.getTime(); } } } public void print(Object... vals){ String s=""; for (Object v : vals) s+=v+", "; console.getOut().println(s) ; } } the method with shift is retaining temporary values though
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|