|
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.
How to use custom Period in onBar method ? |
[LorencSoftware]
|
Post subject: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 02 Feb, 2011, 01:11
|
|
User rating: 0
Joined: Wed 10 Nov, 2010, 23:03 Posts: 6 Location: Slovakia
|
Hello,
I would like to ask you for question.
I found out, that the onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) method is invoking in the Historical tester only with the predefined Period instances. These are following: static Period ONE_HOUR static Period ONE_MIN static Period ONE_SEC static Period ONE_YEAR static Period TEN_MINS static Period TEN_SECS static Period THIRTY_MINS static Period THIRTY_SECS etc...
So here is my question. My strategy I am programming has to check every single 3MINUTES bar, so I need the onBar method has to be invoked also with Period 3Minutes. How is this possible to do so?
I have tried to create new Period instance 3minutes in JForex Preferences but it didnt help. The historicalTester is still invoking the onBar method in my strategy only with the default predefined Periods. What can you suggest me? How can I make the StrategyTester invoking the onBar implemented method in my custom strategy with custom period 3Minutes?
Here is example what I mean for better understanding. ... public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (period.equals(Period.createCustomPeriod(Unit.Minute, 3))) { console.getOut().println("last 3Min askBar has openPrice at: "+askBar.getOpen()); } } ... When you will run this strategy, the console output will never be printed. So it means the onBar method is never invoked with period 3MINUTES. What can I do?
Thank you very much for your help, I very appreciate that.
|
|
|
|
 |
API Support
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 02 Feb, 2011, 13:49
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Yes, it will be available in the next release. You will need to use the IContext.subscribeToBarsFeed method to subscribe to the IBarFeedListener listener, you can do it using the following code: context.subscribeToBarsFeed(currentInstrument, Period.createCustomPeriod(Unit.Minute, 3), OfferSide.ASK, new IBarFeedListener() { @Override public void onBar(Instrument instrument, Period period, OfferSide offerSide, IBar bar) { console.getOut().println(instrument + " " + period + " " + offerSide + " " + bar); } });
|
|
|
|
 |
[LorencSoftware]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 02 Feb, 2011, 18:58
|
|
User rating: 0
Joined: Wed 10 Nov, 2010, 23:03 Posts: 6 Location: Slovakia
|
Hello thank you for your reply. That's great it is going to be in next release.  (Btw do you know the approximate date when it will be released? Just to know if I will be waiting just few days, or weeks or more) I guess indicators are also not supporting custom Periods... Today I tried to calculate fractal indicator from the strategy (fractal indicator is included in JForexAPI) and it is normally working when put Period.FIVE_MINS parametr into fractal calculating method, but when I put some custom period (Period.createCustomPeriod(Unit.Minute, 3)) it's throwing exception. So I guess indicators are also not supporting custom periods in this time, right? Are you also planing to support custom periods also for indicators in the next release? Because when strategies will support custom periods, it would be useless if indicators can not support custom periods.
|
|
|
|
 |
API Support
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Mon 07 Feb, 2011, 13:21
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
LorencSoftware wrote: I guess indicators are also not supporting custom Periods...
Indicators supports custom periods.
|
|
|
|
 |
nicofr0707
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Tue 08 Feb, 2011, 13:31
|
|
User rating: 5
Joined: Fri 02 Sep, 2011, 10:08 Posts: 157 Location: FranceFrance
|
Hello, Today I tried to use a custom period with the stochastic indicator but it returns an exception : Strategy tester: java.lang.ArrayIndexOutOfBoundsException: -1 I did this : double[] stoch1 = indicators.stoch(_instrument, Period.createCustomPeriod(Unit.Hour, 2), OfferSide.BID, fastK, slowK, IIndicators.MaType.SMA, slowD, IIndicators.MaType.SMA, shift);
if I use Period.createCustomPeriod(Unit.Hour, 1) or Period.createCustomPeriod(Unit.Hour, 4) like the standard periods it works fine. Did I do something wrong or is it because customPeriod isn't available yet ? Thanks
|
|
|
|
 |
[LorencSoftware]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Tue 08 Feb, 2011, 20:09
|
|
User rating: 0
Joined: Wed 10 Nov, 2010, 23:03 Posts: 6 Location: Slovakia
|
nicofr0707 wrote: Hello, Today I tried to use a custom period with the stochastic indicator but it returns an exception : Strategy tester: java.lang.ArrayIndexOutOfBoundsException: -1 I did this : double[] stoch1 = indicators.stoch(_instrument, Period.createCustomPeriod(Unit.Hour, 2), OfferSide.BID, fastK, slowK, IIndicators.MaType.SMA, slowD, IIndicators.MaType.SMA, shift);
if I use Period.createCustomPeriod(Unit.Hour, 1) or Period.createCustomPeriod(Unit.Hour, 4) like the standard periods it works fine. Did I do something wrong or is it because customPeriod isn't available yet ? Thanks I have the same problem with indicator FRACTAL. When I am using the indicator FRACTAL with classic periods like Period.ONE_HOUR or Period.createCustomPeriod(Unit.Minute, 30) etc... then everything works fine. But when I am trying to use it with custom non-classic period (for example Period.createCustomPeriod(Unit.Minute, 3)) it doesn't work. So I dont understand your post where you are saying that this is already implemented, this using of custom periods, in indicators...? Because it seems it's not true.
|
|
|
|
 |
API Support
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 09 Feb, 2011, 14:40
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
nicofr0707 wrote: Today I tried to use a custom period with the stochastic indicator but it returns an exception :
Strategy tester: java.lang.ArrayIndexOutOfBoundsException: -1
Currently this problem persist if you call an indicator with a custom period in the onBar method and run a strategy in the historical tester. Fix will be available in the next release.
|
|
|
|
 |
[panic]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Thu 10 Feb, 2011, 13:00
|
|
User rating: 0
Joined: Thu 10 Feb, 2011, 12:57 Posts: 2
|
Support wrote: Yes, it will be available in the next release. You will need to use the IContext.subscribeToBarsFeed method to subscribe to the IBarFeedListener listener, you can do it using the following code: context.subscribeToBarsFeed(currentInstrument, Period.createCustomPeriod(Unit.Minute, 3), OfferSide.ASK, new IBarFeedListener() { @Override public void onBar(Instrument instrument, Period period, OfferSide offerSide, IBar bar) { console.getOut().println(instrument + " " + period + " " + offerSide + " " + bar); } });
I have tried the code above. I get compiler message "IBarFeedListener cannot be resolved to a type". What should I do?
|
|
|
|
 |
nicofr0707
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Fri 11 Feb, 2011, 15:06
|
|
User rating: 5
Joined: Fri 02 Sep, 2011, 10:08 Posts: 157 Location: FranceFrance
|
@support Quote: Currently this problem persist if you call an indicator with a custom period in the onBar method and run a strategy in the historical tester. Fix will be available in the next release. OK thanks. Please check onTick to, because by me it happens when I call the indicator from onTick.
|
|
|
|
 |
[Caleb]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Fri 04 Mar, 2011, 00:01
|
|
User rating: 0
Joined: Sat 07 Nov, 2009, 00:25 Posts: 11
|
Hello, Has this issue been rectified yet. I am awear that API 2.6.38 has now been deployed as of 28-02/2011 but unfortunately am still experiencing the same difficulty computing an indicator with a custom period through onTick(). Happy to be getting the feeds though Mr A. Anderson
|
|
|
|
 |
API Support
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Fri 04 Mar, 2011, 08:35
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
[Caleb]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 09 Mar, 2011, 21:16
|
|
User rating: 0
Joined: Sat 07 Nov, 2009, 00:25 Posts: 11
|
I should have stated, I have already subscribed and am receiving onBar notifications. Infact that is where I am trying to access the indicator. The following stack trace is the result of calling "ma" with a 60Min custom period as opposed to the basic Period.ONE_HOUR: getIndicators().ma(instrument, period, side, IIndicators.AppliedPrice.CLOSE, MAPeriod, type, shift); java.lang.InternalError: Unknown parameter type at com.dukascopy.api.impl.aj.setOptInputParamInteger(Unknown Source) at com.dukascopy.api.impl.ai.setOptInputParameter(Unknown Source) at com.dukascopy.indicators.MAIndicator.getLookback(MAIndicator.java:106) at com.dukascopy.api.impl.ab.a(Unknown Source) at com.dukascopy.api.impl.ab.calculateIndicator(Unknown Source) at com.dukascopy.dds2.greed.agent.strategy.tester.ai.calculateIndicator(Unknown Source) at com.dukascopy.api.impl.ab.a(Unknown Source) at com.dukascopy.api.impl.ab.ma(Unknown Source) ... at com.dukascopy.dds2.greed.agent.strategy.tester.a.a(Unknown Source) at com.dukascopy.dds2.greed.agent.strategy.tester.l.run(Unknown Source) at com.dukascopy.dds2.greed.agent.strategy.tester.a.wI(Unknown Source) at com.dukascopy.dds2.greed.actions.StrategyTesterAction.vc(Unknown Source) at com.dukascopy.dds2.greed.actions.StrategyTesterAction.uB(Unknown Source) at com.dukascopy.dds2.greed.actions.c.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
|
|
|
|
 |
nicofr0707
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Fri 11 Mar, 2011, 13:14
|
|
User rating: 5
Joined: Fri 02 Sep, 2011, 10:08 Posts: 157 Location: FranceFrance
|
I'm trying to compute an indicator with custom period through onTick() to... I have suscribed the custom period with subscribeToBarsFeed, like support said (even if I think it's not necessary because the indicator is called from onTick() and not onBar() in my case) Here is what I get from the Stochastic indicator with 2 methods : Custom period : 2 hour. public void onTick(Instrument instrument, ITick tick) throws JFException {
double[][] stoch = indicators.stoch(instrument, Period.createCustomPeriod(Unit.Hour, 2), OfferSide.BID, fastK, slowK, IIndicators.MaType.SMA, slowD, IIndicators.MaType.SMA, com.dukascopy.api.Filter.ALL_FLATS, 1, tick.getTime(), 0);
console.getOut().println("stoch slowK : " + stoch[0][0]); // traces slowK of the last CLOSED candle console.getOut().println("stoch slowD : " + stoch[1][0]); // traces slowD of the last CLOSED candle
double[] stoch1 = indicators.stoch(instrument, Period.createCustomPeriod(Unit.Hour, 2), OfferSide.BID, fastK, slowK, IIndicators.MaType.SMA, slowD, IIndicators.MaType.SMA, shift);
console.getOut().println("stoch1 slowK : " + stoch1[0]); // traces "NaN" console.getOut().println("stoch1 slowD : " + stoch1[1]); // traces "NaN"
} The advantage of calculating an indicator from onTick() is to always have up to date indicator values for current period without waiting for candle to close... With standard periods, all works just fine from onTick(), but with custom ones values are calculated ONLY on the close of the candle. Am I write ? Support, do you plan to do something to make it work right from onTick() to, or is this just a bug ? Thanks
|
|
|
|
 |
[liquidmenace]
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Wed 16 Mar, 2011, 03:00
|
|
User rating: 0
Joined: Sun 06 Mar, 2011, 14:41 Posts: 1
|
I would like to use custom periods based on price in a strategy. I can create them i jForex but I cant see how to in the documentation. There is no enum in the Units to allow the creation.
Any suggestions would be welcome
Mick
|
|
|
|
 |
API Support
|
Post subject: Re: How to use custom Period in onBar method ? |
Post rating: 0
|
Posted: Mon 21 Mar, 2011, 16:12
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, liquidmenace wrote: I would like to use custom periods based on price in a strategy. I can create them i jForex but I cant see how to in the documentation. There is no enum in the Units to allow the creation.
Please have a look at the following: https://www.dukascopy.com/client/javadoc ... /Unit.htmlCaleb wrote: I should have stated, I have already subscribed and am receiving onBar notifications. Infact that is where I am trying to access the indicator. The following stack trace is the result of calling "ma" with a 60Min custom period as opposed to the basic Period.ONE_HOUR:
Could you please provide the values of "instrument, period, side, MAPeriod, type, shift" that you use in your code getIndicators().ma(instrument, period, side, IIndicators.AppliedPrice.CLOSE, MAPeriod, type, shift);
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|