|
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 add an indicator to Chart? |
[DarthTrader2]
|
Post subject: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Wed 23 Feb, 2011, 16:00
|
|
User rating: 0
Joined: Tue 22 Feb, 2011, 20:43 Posts: 10
|
Hi,
I tried to add an indicator to the chart. This works for the native method ... getIndicator("COG"). But this doesn't work for setting an Object[] with defined values (timePeriod, smoothPeriod).
Please provide an code-sample to set paramater of an indicator in strategy code.
Where is the best place to add the indicator? Currently I add it in onStart() -method.
Thx DT
|
|
|
|
 |
[DarthTrader2]
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Wed 23 Feb, 2011, 19:06
|
|
User rating: 0
Joined: Tue 22 Feb, 2011, 20:43 Posts: 10
|
In every case of adding I'm getting a ClassCastException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [D at com.dukascopy.indicators.CenterOfGravityIndicator.setInputParameter(CenterOfGravityIndicator.java:134) at de.STRG.onStart(HB_CenterOfGravity.java:155) at com.dukascopy.api.impl.execution.s.call(Unknown Source) at com.dukascopy.api.impl.connect.ai.a(Unknown Source) at com.dukascopy.api.impl.connect.v.call(Unknown Source) at com.dukascopy.api.impl.connect.v.call(Unknown Source) at com.dukascopy.api.impl.execution.i.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at com.dukascopy.api.impl.execution.e$a.f(Unknown Source) at com.dukascopy.api.impl.execution.e$a.run(Unknown Source) at java.lang.Thread.run(Unknown Source) I tried the following: chart.addIndicator(this.context.getIndicators().getIndicator("COG"), new Object[] {AppliedPrice.CLOSE, timePeriod, smoothPeriod, maType}); and as alternative this piece of code, with same exception: IIndicator indCOG = this.context.getIndicators().getIndicator("COG"); IIndicatorInfo indCOGInfo = indCOG.getIndicatorInfo(); log("Indicator.getTitle(): " +indCOGInfo.getTitle()); log("Indicator.getNumberOfInputs(): " +indCOGInfo.getNumberOfInputs()); log("Indicator.getNumberOfOptionalInputs(): " +indCOGInfo.getNumberOfOptionalInputs()); log("Indicator.getNumberOfOutputs(): " +indCOGInfo.getNumberOfOutputs()); log("Indicator.toString(): " +indCOGInfo.toString()); for (int i=0; i<indCOGInfo.getNumberOfInputs(); i++) { log("Indicator.getInputParameterInfo(" +i+ ").getName(): " +indCOG.getInputParameterInfo(i).getName()); } for (int i=0; i<indCOGInfo.getNumberOfOptionalInputs(); i++) { log("Indicator.getOptInputParameterInfo(" +i+ ").getName(): " +indCOG.getOptInputParameterInfo(i).getName()); } for (int i=0; i<indCOGInfo.getNumberOfOutputs(); i++) { log("Indicator.getOutputParameterInfo(" +i+ ").getName(): " +indCOG.getOutputParameterInfo(i).getName()); } // after log-output this should run the code and add the indicator indCOG.setInputParameter(0, new Object[]{AppliedPrice.CLOSE}); indCOG.setOptInputParameter(0, new Object[]{timePeriod}); indCOG.setOptInputParameter(1, new Object[]{smoothPeriod}); indCOG.setOptInputParameter(2, new Object[]{maType});
chart.addIndicator(indCOG); Without any parameter the indicator was added successful. Why?
|
|
|
|
 |
API Support
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Thu 24 Feb, 2011, 16:10
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, java.lang.ClassCastException: can occurs if you pass incorrect parameter type to the indicator, for example your parameter is double, but indicator expect int.
|
|
|
|
 |
[DarthTrader2]
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Fri 25 Feb, 2011, 08:12
|
|
User rating: 0
Joined: Tue 22 Feb, 2011, 20:43 Posts: 10
|
Thank you for your very little input .... What parameter is double? I tried several variants, all my own parameters (timePeriod, smoothPeriod) are ints. //indCOG.setInputParameter(0, AppliedPrice.CLOSE); indCOG.setOptInputParameter(0, timePeriod); indCOG.setOptInputParameter(1, smoothPeriod); indCOG.setOptInputParameter(2, maType);
chart.addIndicator(indCOG); So, AppliedPrice.CLOSE should be a Double? But this is a standard param? If I commented this out, the exception occurs at last lin and says that maType is not a Double but it is initialized as: @Configurable("MAType") public IIndicators.MaType maType = IIndicators.MaType.SMMA; f I delete this last line and only apply "timePeriod" and "smoothPeriod" which are definitely INTs and annotated with @Configurable the values are not applied to chart. The default values for COG are applied to chart .... Please provide a little bit more help on this topic ... it should be a core function and doesn't seem to work. My other question was, which method/place in strategy is the right one for adding a chart? Thx DT
|
|
|
|
 |
API Support
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Fri 25 Feb, 2011, 08:53
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, Please try the following: IIndicator ind = this.context.getIndicators().getIndicator("COG"); chart.addIndicator(ind, new Object[]{6, 11, MaType.EMA.ordinal()});
|
|
|
|
 |
[DarthTrader2]
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Fri 25 Feb, 2011, 16:11
|
|
User rating: 0
Joined: Tue 22 Feb, 2011, 20:43 Posts: 10
|
Ok, thanks. But I think there are still some bugs in the adding of indicators: Your recommandation is working, but I'm not able to set the AppliedPrice with this way. chart.addIndicator(indCOG, new Object[]{timePeriod, smoothPeriod, maType.ordinal()}); This works, but the colors of the lines are black. I have to edit the parameter of the indicator, then the colors will be applied. chart.addIndicator(indCOG, new Object[]{timePeriod, smoothPeriod, maType.ordinal(), AppliedPrice.CLOSE}); This compiles and run the code, but in the left upper corner of the indicator window no values are shown. indCOG.setInputParameter(0, AppliedPrice.CLOSE); indCOG.setOptInputParameter(0, timePeriod); indCOG.setOptInputParameter(1, smoothPeriod); indCOG.setOptInputParameter(2, maType.ordinal()); chart.addIndicator(indCOG); This does compile only. Default values for indicator are taken for chart drawing. Is this method supported for setting the indicator values? My conclusion so far: Setting indicators out of onStart-Method of an strategy doesn't work. So we have to put indicators manually on the chart. Are there any other experiences? Thx DT
|
|
|
|
 |
API Support
|
Post subject: Re: How to add an indicator to Chart? |
Post rating: 0
|
Posted: Mon 28 Feb, 2011, 08:42
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, Use the following code to specify the applied price, drawing style, colors, etc for the indicator: for (int i = 0; i < indCOG.getIndicatorInfo().getNumberOfInputs(); i++) { InputParameterInfo inputParameterInfo = indCOG.getInputParameterInfo(i); inputParameterInfo.setAppliedPrice(AppliedPrice.LOW); } chart.addIndicator(indCOG, new Object[]{5, 6, MaType.SMA.ordinal()}, new Color[]{Color.RED, Color.GREEN}, new DrawingStyle[]{DrawingStyle.DASHDOT_LINE, DrawingStyle.LINE}, new int[]{1, 2});
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|