|
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.
My attempt to make a strategy |
DoubleDutch
|
Post subject: My attempt to make a strategy |
Post rating: 0
|
Posted: Wed 08 Feb, 2012, 19:23
|
|
User rating: 0
Joined: Sat 24 Sep, 2011, 16:10 Posts: 16 Location: Netherlands, Rotterdam
|
Dear Support, After reading a lot on the Dukascopy wiki page I decided to try and make my own strategy with Eclipse. I used the 'Simple Strategy' as an example https://www.dukascopy.com/wiki/#Simple_StrategyIt is far from finished but would you be so kind to look at the strategy and tell me what is incorrect or even better fix the problem? I get a error on line 73. I've tried everything to fix it. More info on the strategy can be found in the code. Kind regards, Martin
Attachments: |
MPivot.java [3.77 KiB]
Downloaded 269 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.
|
|
|
|
|
 |
API Support
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Thu 09 Feb, 2012, 08:53
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Change the method to: private IOrder submitOrder(double amount, OrderCommand orderCmd, double takeProfitPips) throws JFException { double stopLossPrice = 0, takeProfitPrice = 0; // Calculating stop loss and take profit prices if (orderCmd == OrderCommand.BUY) { stopLossPrice = history.getLastTick(this.instrument).getAsk() - this.stopLossPips * this.instrument.getPipValue(); takeProfitPrice = history.getLastTick(this.instrument).getAsk() + takeProfitPips * this.instrument.getPipValue(); } if (orderCmd == OrderCommand.SELL) { stopLossPrice = history.getLastTick(this.instrument).getBid() + this.stopLossPips * this.instrument.getPipValue(); takeProfitPrice = history.getLastTick(this.instrument).getBid() - takeProfitPips * this.instrument.getPipValue(); }
// Submitting the order for the specified instrument at the // current market price return this.engine.submitOrder(getLabel(orderCmd), this.instrument, orderCmd, amount, 0, 0, stopLossPrice, takeProfitPrice); }
In order to avoid such compilation time errors and more convenient coding, consider using some IDE, for example Eclipse: https://www.eclipse.org/downloads/packag ... /indigosr1And then import the Standalone JForex-API project: https://www.dukascopy.com/wiki/#Use_in_Eclipse
|
|
|
|
 |
DoubleDutch
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Sun 12 Feb, 2012, 22:27
|
|
User rating: 0
Joined: Sat 24 Sep, 2011, 16:10 Posts: 16 Location: Netherlands, Rotterdam
|
Dear Support, Thank you for your quick reply. Would you be so kind to take a look at the following strategy that I'm trying to make? I got the indicator the way I want it. It is your (dukascopy) indicator with a small change. I tried to register the indicator to a strategy, following the instructions at https://www.dukascopy.com/wiki/#Use_custom_indicator_in_strategies . What I want the strategy to do is simple. If getBid > pR1 (see indicator) it should make a BUY order. If getAsk < pS1 (see indicator) it should make a Sell order. It should be easy, but I don't understand how I can get the strategy to use the variable from the indicator to open an order. I would really appreciate your help.  Kind regards, Martin
Attachments: |
CustomIndicatorStrategy.java [5.2 KiB]
Downloaded 266 times
|
MyIndicator.java [18.69 KiB]
Downloaded 259 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.
|
|
|
|
|
 |
API Support
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Mon 13 Feb, 2012, 09:01
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Your indicator has 3 outputs, just as the custom indicator in the second example: https://www.dukascopy.com/wiki/#Use_cust ... t_on_chartPlease try the example and then change: - Indicator filepath indicatorJfxFile.
- Indicator name indicatorName .
- Your indicator has two optional outputs "Period" and "Show historical levels". You have to make a variable for each of them and replace with those the variables which stand for the previous indicators optional inputs (the ones preceded by "//optional inputs according to optInputParameterInfos of the indicator").
- Put the two new optional inputs in array optionalInputArray.
To get the idea how to parse outputs and work with them, also see the third example: https://www.dukascopy.com/wiki/#Use_cust ... namicIndexAnd also universal method examples in: https://www.dukascopy.com/wiki/#Indicato ... price_feed
|
|
|
|
 |
DoubleDutch
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Mon 13 Feb, 2012, 15:24
|
|
User rating: 0
Joined: Sat 24 Sep, 2011, 16:10 Posts: 16 Location: Netherlands, Rotterdam
|
|
|
|
 |
API Support
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Mon 13 Feb, 2012, 15:39
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
First try approach without any style settings: chart.addIndicator(myIndicator, optionalInputArray) Also have a look at the following line: double[] PS1 = (double []) resultArr[3]; Presumably the index should be 2.
|
|
|
|
 |
DoubleDutch
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Mon 13 Feb, 2012, 16:06
|
|
User rating: 0
Joined: Sat 24 Sep, 2011, 16:10 Posts: 16 Location: Netherlands, Rotterdam
|
Thank you, but it still gives the same error: Quote: 15:02:42 java.lang.NullPointerException @ newjforex.CustomIndPivot.onStart(CustomIndPivot.java:101)
|
|
|
|
 |
API Support
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Mon 13 Feb, 2012, 16:27
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Make sure that you have the chart opened and that the indicator is actually loaded by performing null-checks, for instance: if(myIndicator == null){ console.getErr().println("Indicator " +indicatorName+ " not found!"); context.stop(); } if(chart == null){ console.getErr().println("Chart for " +instrument+ " not found! Please open the chart."); context.stop(); }
|
|
|
|
 |
DoubleDutch
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Tue 14 Feb, 2012, 12:32
|
|
User rating: 0
Joined: Sat 24 Sep, 2011, 16:10 Posts: 16 Location: Netherlands, Rotterdam
|
I tried everything but it always gives the same error. I'm not sure if I followed your instructions right about making a variable for "Period" & "Show historical levels".
Could you please have a look at both the strategy and the indicator? I would really appreciate it.
Martin
Attachments: |
CustomIndPivot.java [9.37 KiB]
Downloaded 261 times
|
MyIndicator.jfx [13.57 KiB]
Downloaded 264 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.
|
|
|
|
|
 |
API Support
|
Post subject: Re: My attempt to make a strategy |
Post rating: 0
|
Posted: Tue 14 Feb, 2012, 12:50
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
indicator name should be "TPIVOT" not "MyIndicator". This already would have been indicated by the null checks, if they were put before the line where the NullPointerException occurs.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|