|
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.
Using indicators API |
[darlu72]
|
Post subject: Using indicators API |
Post rating: 0
|
Posted: Sat 02 Oct, 2010, 07:33
|
|
User rating: 0
Joined: Thu 19 Aug, 2010, 13:53 Posts: 62
|
Hi,
I want use for example this method from IIndicators which is supposed to calculate Fibonacci :
double[] array = fibPivot(Instrument instrument, Period period, OfferSide side, int timePeriod, long from, long to) throws JFException
It retuns an array of doubles like most of other inddicators. Where do I found info/ how do I know what represents returned values in the array, eg array[0], array[1], etc Also the same question for the input arguments, what they are, eg. long from, long to.
For example, for
double[] stoch(Instrument instrument, Period period, OfferSide side, int fastKPeriod, int slowKPeriod, IIndicators.MaType slowKMaType, int slowDPeriod, IIndicators.MaType slowDMaType, int shift) throws JFException
I managed to deduct that returned array value at index 0 is main line and index 1 is signal line. But for other indicators how can I know ? I have failed to find such info in the documentation and forum.
Thank you.
|
|
|
|
 |
API Support
|
Post subject: Re: Using indicators API |
Post rating: 0
|
Posted: Mon 04 Oct, 2010, 13:04
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, Please have a look a the following JForex Wiki articles: https://www.dukascopy.com/wiki/index.php ... s#Overviewhttps://www.dukascopy.com/wiki/index.php ... tochasticsAlso, have a look at the fibPivot indicator source code located here: viewtopic.php?f=6&t=8379For the moment, please use the calculateIndicator() methods for the fibPivot indicator, as fibPivot() methods return only one value, this will be fixed ASAP. For example, indicators.calculateIndicator(Instrument.EURUSD, Period.ONE_HOUR, new OfferSide[] {OfferSide.ASK}, "FIBPIVOT", new AppliedPrice[] {}, new Object[]{5}, 0);
|
|
|
|
 |
[darlu72]
|
Post subject: Re: Using indicators API |
Post rating: 0
|
Posted: Wed 06 Oct, 2010, 19:58
|
|
User rating: 0
Joined: Thu 19 Aug, 2010, 13:53 Posts: 62
|
Hi,
Ok. One more question: Is there any built-in divergence indicator ? If yes, which is its name ? Thank you.
|
|
|
|
 |
API Support
|
Post subject: Re: Using indicators API |
Post rating: 0
|
Posted: Thu 07 Oct, 2010, 09:14
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, we have indicators like MACD, RSI etc. on which you can try to wrote your divergence indicator. Unfortunately we don't have a built in ones.
|
|
|
|
 |
cyberalgo
|
Post subject: Re: Using indicators API |
Post rating: 0
|
Posted: Mon 04 Apr, 2011, 12:16
|
|
User rating: 1
Joined: Tue 28 Jun, 2011, 20:38 Posts: 18 Location: United StatesUnited States
|
Hello! Below I posted a code to retrieve fibonacci pivot points returned by either "calculateindicator" and "fibPivot" API interface. I also calculate them "manually" on the onBar method as the formula is quite simple (also shown below) and use for that matter the "history.getBar" to retrieve the HLC (High Low Close) values on the 5 minute time-frame which other then the Fibonacci percentiles (0.618 and 0.382 ) is all you need to calculate pivots points. See below the formula and the input parameters used in the interfaces. I used the same 5 minute time-frame in both interfaces. Additionally in both interfaces and in the getBar method I use "shift=1" or the previous closed candle to be sure I use a completed candle with definite HLC values. When comparing the pivot points returned i.e S3,S2,S1,Pivot,R1,R2,R3 from the interfaces and the one calculated "manually" I would expect they return the same values but they do not match. So I was wondering if you could please provide the formula you use to calculate Fibonacci pivots or which Fibonacci percentiles you use in the API interface "fibPivot" ? I tried the link above but it did not work!? Also could you please explain what the parameter "timeperiod=5" means in the "calculateindicator" interface in the previous post? I have pasted the results returned by all three methods and included the complete code further down in case you would like to have a look or try it out. Thank you, cyberalgo Fibonacci pivots calculation formula using (0.618 and 0.382 ) percentiles and HLC of the previous candle (shift=1) in the getBar method : ...
IBar Bar = history.getBar(instrument,testPeriod,OfferSide.BID,1); double O = Bar.getOpen(); double H = Bar.getHigh(); double L = Bar.getLow(); double C = Bar.getClose(); print("Open: " + O + " High: " + H + " Low: " + L + " Close: " + C,instrument); // Fibonacci pivot points - benchmark method double Pivot = ( H + L + C ) / 3; double R3 = Pivot + 1.000 * (H - L); double R2 = Pivot + 0.618 * (H - L); double R1 = Pivot + 0.382 * (H - L); double S1 = Pivot - 0.382 * (H - L); double S2 = Pivot - 0.618 * (H - L); double S3 = Pivot - 1.000 * (H - L); ... Complete code example with fibonacci Pivot points calculated on the onBar method: package jforex;
import java.util.*; import java.math.*;
import com.dukascopy.api.*;
public class test implements IStrategy { private IEngine engine; private IConsole console; private IHistory history; private IContext context; private IIndicators indicators; private IUserInterface userInterface; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; this.indicators = context.getIndicators(); this.userInterface = context.getUserInterface(); }
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!=instrument.EURUSD) return; Period testPeriod = Period.FIVE_MINS; if (period != Period.FIVE_MINS) return; IBar Bar = history.getBar(instrument,testPeriod,OfferSide.BID,1); double O = Bar.getOpen(); double H = Bar.getHigh(); double L = Bar.getLow(); double C = Bar.getClose(); print("Open: " + O + " High: " + H + " Low: " + L + " Close: " + C,instrument); // Fibonacci pivot points - benchmark method double Pivot = ( H + L + C ) / 3; double R3 = Pivot + 1.000 * (H - L); double R2 = Pivot + 0.618 * (H - L); double R1 = Pivot + 0.382 * (H - L); double S1 = Pivot - 0.382 * (H - L); double S2 = Pivot - 0.618 * (H - L); double S3 = Pivot - 1.000 * (H - L); // Using "FIBPIVOT" indicator method 1 Object[] FIBPIVOT = indicators.calculateIndicator(Instrument.EURUSD, testPeriod, new OfferSide[] {OfferSide.BID,OfferSide.BID}, "FIBPIVOT", new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE,IIndicators.AppliedPrice.CLOSE}, new Object[]{1}, 1); double m1_R3 = round((Double)FIBPIVOT[5],5); double m1_R2 = round((Double)FIBPIVOT[3],5); double m1_R1 = round((Double)FIBPIVOT[1],5); double m1_P0 = round((Double)FIBPIVOT[0],5); double m1_S1 = round((Double)FIBPIVOT[2],5); double m1_S2 = round((Double)FIBPIVOT[4],5); double m1_S3 = round((Double)FIBPIVOT[6],5); // Using "FIBPIVOT" indicator method 2 double[] FIBPIVOT2 = indicators.fibPivot(Instrument.EURUSD, testPeriod, OfferSide.BID, 1, 1); double m2_R3 = round((Double)FIBPIVOT2[5],5); double m2_R2 = round((Double)FIBPIVOT2[3],5); double m2_R1 = round((Double)FIBPIVOT2[1],5); double m2_P0 = round((Double)FIBPIVOT2[0],5); double m2_S1 = round((Double)FIBPIVOT2[2],5); double m2_S2 = round((Double)FIBPIVOT2[4],5); double m2_S3 = round((Double)FIBPIVOT2[6],5); print("Fibonnaci benchmark , calculateIndicator , fibPivot S3: " + round(S3,5) + " , " + m1_S3 + " , " + m2_S3 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot S2: " + round(S2,5) + " , " + m1_S2 + " , " + m2_S2 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot S1: " + round(S1,5) + " , " + m1_S1 + " , " + m2_S1 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot P0: " + round(Pivot,5) + " , " + m1_P0 + " , " + m2_P0 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot R1: " + round(R1,5) + " , " + m1_R1 + " , " + m2_R1 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot R2: " + round(R2,5) + " , " + m1_R2 + " , " + m2_R2 ,instrument); print("Fibonnaci benchmark , calculateIndicator , fibPivot R3: " + round(R3,5) + " , " + m1_R3 + " , " + m2_R3 ,instrument); } private void print (String comment,Instrument inst) { console.getOut().println("Comment" + " : " + inst.toString() + " : " + comment); } public static double round(double d, int decimalPlace){ BigDecimal bd = new BigDecimal(Double.toString(d)); bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } }
Output messages:
09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot R3: 1.42976 , 1.42086 , 1.42086 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot R2: 1.42688 , 1.42072 , 1.42072 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot R1: 1.42509 , 1.42063 , 1.42063 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot P0: 1.4222 , 1.4205 , 1.4205 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot S1: 1.41932 , 1.42036 , 1.42036 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot S2: 1.41753 , 1.42027 , 1.42027 09:46:46 Comment : EUR/USD : Fibonnaci benchmark , calculateIndicator , fibPivot S3: 1.41464 , 1.42014 , 1.42014 09:46:46 Comment : EUR/USD : Open: 1.4234 High: 1.42678 Low: 1.41922 Close: 1.42061
|
|
|
|
 |
API Support
|
Post subject: Re: Using indicators API |
Post rating: 0
|
Posted: Thu 02 Jun, 2011, 07:30
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|