Dukascopy
 
 
Wiki JStore Search Login

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.

sma over typical price indicator
 Post subject: Indicator problem Post rating: 0   New post Posted: Sun 08 Jan, 2012, 00:42 
User avatar

User rating: 0
Joined: Fri 16 Dec, 2011, 15:05
Posts: 26
Location: Italy, ventimiglia
Hi everybody,

I tried to change a bit the example code of the indicator in Wiki in this way:

private Period period = Period.DAILY;
public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("EXAMPIND", "Sums previous values", "My indicators",false, false, false, 1, 1, 1);
        inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Input data", InputParameterInfo.Type.DOUBLE)};
        inputParameterInfos[0].setPeriod(this.period);
        optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER,new IntegerRangeDescription(2, 2, 100, 1))};
        outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE)};

    }

(I did that because I'd like to create an indicator which is independent from the chart timeframe)

But I get an exception in the calculate method:

20:01:27 Error in indicator: java.lang.ArrayIndexOutOfBoundsException: 1 @ jforex.Indicator.calculate(Indicator.java:36)


 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 value = 0;
           for (int k = timePeriod; k > 0; k--)
           {
              value += inputs[1][i - k];////Line 36 throwing the exception
           }
            outputs[0][j] = value;
        }
        return new IndicatorResult(startIndex, j);
    }

I'm quite new to java, so, sorry if it's a stupid question.
Thank you in advance,
Calogero


 
 Post subject: Re: Indicator problem Post rating: 0   New post Posted: Mon 09 Jan, 2012, 13:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You get this exception because you have only 1 input -> one input array, but you are trying to access the element with index 1 (arrays start with 0th element).
For more efficient assistance, please describe in detail what are you trying to do. What do you want to change in the indicator?


 
 Post subject: Re: Indicator problem Post rating: 0   New post Posted: Mon 09 Jan, 2012, 14:30 
User avatar

User rating: 0
Joined: Fri 16 Dec, 2011, 15:05
Posts: 26
Location: Italy, ventimiglia
Hello support,

I'd like to create an indicator independent of time frames.
Something like sma[n] of typical price but always on the daily timeframe.

Thank you in advance for support.
Calogero


 
 Post subject: sma over typical price indicator Post rating: 0   New post Posted: Mon 09 Jan, 2012, 16:07 
User avatar

User rating: 0
Joined: Fri 16 Dec, 2011, 15:05
Posts: 26
Location: Italy, ventimiglia
Hello support,

I'd like to create an indicator independent of time frames.
Something like sma[n] of typical price but always on the daily timeframe.

Thank you in advance for support.
Calogero


 
 Post subject: Re: sma over typical price indicator Post rating: 0   New post Posted: Tue 10 Jan, 2012, 15:41 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
Attachment:
SMADailySingle5.java [7.11 KiB]
Downloaded 302 times
For more on multiple timeframe indicators see:
https://www.dukascopy.com/wiki/#Indicato ... nt_periods


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com