|
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.
Channel Bib/Ask Indicator (some problems) |
pirate_
|
Post subject: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Mon 05 Nov, 2012, 19:15
|
|
User rating: 0
Joined: Thu 01 Nov, 2012, 17:40 Posts: 7
|
Hi all! I'm trying to make a simple channel indicator, the upper line calculates as a highest high of 12-period Bid price array and the bottom line = the lowest low of 12-period Ask price array. But when I'm trying to compile it the error appears with a messge "OfferSide cannot be resolved". And the same with the AppliedPrice. What is wrong with the code? And how can I manage this problem? Thank you in advance! package jforex;
import com.dukascopy.api.indicators.*;
public class Channel2Lines_v2 implements IIndicator { private IndicatorInfo indicatorInfo; private InputParameterInfo[] inputParameterInfos; private OptInputParameterInfo[] optInputParameterInfos; private OutputParameterInfo[] outputParameterInfos; private double[][] inputs = new double[2][]; private int timePeriod = 12; private double[][] outputs = new double[2][]; public void onStart(IIndicatorContext context) { indicatorInfo = new IndicatorInfo("ChannelInd", "Calculates extremums", "My indicators", true, false, false, 2, 1, 2); inputParameterInfos = new InputParameterInfo[] { new InputParameterInfo("Ch1_Price:", InputParameterInfo.Type.PRICE){ { setAppliedPrice(AppliedPrice.HIGH); setOfferSide(OfferSide.BID); } }, new InputParameterInfo("Ch2_Price:", InputParameterInfo.Type.PRICE){ { setAppliedPrice(AppliedPrice.LOW); setOfferSide(OfferSide.ASK); } } }; optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(12, 2, 100, 1))}; outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("Channel1", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE), new OutputParameterInfo("Channel2", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE)}; }
public IndicatorResult calculate(int startIndex, int endIndex) { //calculating startIndex taking into account lookback value if (startIndex - getLookback() < 0) { startIndex -= startIndex - getLookback(); } int i, j; for (i = startIndex, j = 0; i <= endIndex; i++, j++) { double value1 = 0; double value2 = 99999; for (int k = timePeriod; k > 0; k--) { if (inputs[0][i - k] > value1) value1 = inputs[0][i - k]; if (inputs[1][i - k] < value2) value2 = inputs[1][i - k]; } outputs[0][j] = value1; outputs[1][j] = value2; } return new IndicatorResult(startIndex, j); }
public IndicatorInfo getIndicatorInfo() { return indicatorInfo; }
public InputParameterInfo getInputParameterInfo(int index) { if (index <= inputParameterInfos.length) { return inputParameterInfos[index]; } return null; }
public int getLookback() { return timePeriod; }
public int getLookforward() { return 0; }
public OptInputParameterInfo getOptInputParameterInfo(int index) { if (index <= optInputParameterInfos.length) { return optInputParameterInfos[index]; } return null; }
public OutputParameterInfo getOutputParameterInfo(int index) { if (index <= outputParameterInfos.length) { return outputParameterInfos[index]; } return null; }
public void setInputParameter(int index, Object array) { inputs[index] = (double[]) array; }
public void setOptInputParameter(int index, Object value) { timePeriod = (Integer) value; }
public void setOutputParameter(int index, Object array) { outputs[index] = (double[]) array; } }
|
|
|
|
 |
API Support
|
 |
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Wed 07 Nov, 2012, 14:27
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
pirate_
|
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Wed 07 Nov, 2012, 20:38
|
|
User rating: 0
Joined: Thu 01 Nov, 2012, 17:40 Posts: 7
|
API Support, thank you! The code had compiled successfully. But when I add indicator to the chart, the new error occures: 19:28:36 Error in indicator: java.lang.ClassCastException: [[D cannot be cast to [D @ jforex.Channel2Lines_v21.setInputParameter(Channel2Lines_v21.java:97) Full Exeption: java.lang.ClassCastException: [[D cannot be cast to [D at jforex.Channel2Lines_v21.setInputParameter(Channel2Lines_v21.java:97) at com.dukascopy.api.impl.cm.a(Unknown Source) at com.dukascopy.charts.math.dataprovider.AbstractDataProvider$e.c(Unknown Source) at com.dukascopy.charts.math.dataprovider.AbstractDataProvider$e.run(Unknown Source) What do I have to do with inputs? public void setInputParameter(int index, Object array) { inputs[index] = (double[]) array; }
|
|
|
|
 |
API Support
|
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Thu 08 Nov, 2012, 10:41
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Change the InputParameterInfo to InputParameterInfo.Type.DOUBLE.
|
|
|
|
 |
pirate_
|
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Mon 12 Nov, 2012, 19:31
|
|
User rating: 0
Joined: Thu 01 Nov, 2012, 17:40 Posts: 7
|
It works fine now, thank you! The only issue is when the indicator is placed on the chart, sometimes the error appears: 18:20:03 Error in indicator: java.lang.ArrayIndexOutOfBoundsException: 21 @ jforex.Channel2Lines_v21.calculate(Channel2Lines_v21.java:54) Full exeption: java.lang.ArrayIndexOutOfBoundsException: 21 at jforex.Channel2Lines_v21.calculate(Channel2Lines_v21.java:54) at com.dukascopy.api.impl.cm.a(Unknown Source) at com.dukascopy.charts.math.dataprovider.AbstractDataProvider$e.c(Unknown Source) at com.dukascopy.charts.math.dataprovider.AbstractDataProvider$e.run(Unknown Source) But still, despite that, indicator works correctly, so it's not a big problem. The final code is: package jforex;
import com.dukascopy.api.indicators.*; import com.dukascopy.api.IIndicators.AppliedPrice; import com.dukascopy.api.OfferSide;
public class Channel2Lines_v21 implements IIndicator { private IndicatorInfo indicatorInfo; private InputParameterInfo[] inputParameterInfos; private OptInputParameterInfo[] optInputParameterInfos; private OutputParameterInfo[] outputParameterInfos; private double[][] inputs = new double[2][]; private int timePeriod = 12; private double[][] outputs = new double[2][]; public void onStart(IIndicatorContext context) { indicatorInfo = new IndicatorInfo("ChannelInd", "Calculates extremums", "My indicators", true, false, false, 2, 1, 2); inputParameterInfos = new InputParameterInfo[] { new InputParameterInfo("Ch1_Price:", InputParameterInfo.Type.DOUBLE){ { setAppliedPrice(AppliedPrice.HIGH); setOfferSide(OfferSide.BID); } }, new InputParameterInfo("Ch2_Price:", InputParameterInfo.Type.DOUBLE){ { setAppliedPrice(AppliedPrice.LOW); setOfferSide(OfferSide.ASK); } } }; optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(12, 2, 100, 1))}; outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("Channel1", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE), new OutputParameterInfo("Channel2", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE)}; }
public IndicatorResult calculate(int startIndex, int endIndex) { //calculating startIndex taking into account lookback value if (startIndex - getLookback() < 0) { startIndex -= startIndex - getLookback(); } int i, j; for (i = startIndex, j = 0; i <= endIndex; i++, j++) { double value1 = 0; double value2 = 999; for (int k = timePeriod; k > 0; k--) { if (inputs[0][i - k] > value1) value1 = inputs[0][i - k]; if (inputs[1][i - k] < value2) value2 = inputs[1][i - k]; } outputs[0][j] = value1; outputs[1][j] = value2; } return new IndicatorResult(startIndex, j); }
public IndicatorInfo getIndicatorInfo() { return indicatorInfo; }
public InputParameterInfo getInputParameterInfo(int index) { if (index <= inputParameterInfos.length) { return inputParameterInfos[index]; } return null; }
public int getLookback() { return timePeriod; }
public int getLookforward() { return 0; }
public OptInputParameterInfo getOptInputParameterInfo(int index) { if (index <= optInputParameterInfos.length) { return optInputParameterInfos[index]; } return null; }
public OutputParameterInfo getOutputParameterInfo(int index) { if (index <= outputParameterInfos.length) { return outputParameterInfos[index]; } return null; }
public void setInputParameter(int index, Object array) { inputs[index] = (double[]) array; }
public void setOptInputParameter(int index, Object value) { timePeriod = (Integer) value; }
public void setOutputParameter(int index, Object array) { outputs[index] = (double[]) array; } }
|
|
|
|
 |
API Support
|
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Tue 13 Nov, 2012, 09:22
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Consider adding additional array range checks: for (int k = timePeriod; k > 0 && i - k < inputs[0].length && i - k < inputs[1].length; k--) {
|
|
|
|
 |
pirate_
|
Post subject: Re: Channel Bib/Ask Indicator (some problems) |
Post rating: 0
|
Posted: Tue 13 Nov, 2012, 18:47
|
|
User rating: 0
Joined: Thu 01 Nov, 2012, 17:40 Posts: 7
|
It looks like the error is gone. Thanks again!
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|