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.

Indicator.calculate: endIndex > inputsArray.length
 Post subject: Indicator.calculate: endIndex > inputsArray.length Post rating: 0   New post Posted: Thu 04 Aug, 2011, 13:28 
User avatar

User rating: 3
Joined: Wed 18 May, 2011, 16:25
Posts: 331
Location: SwitzerlandSwitzerland
I'm testing indicators with periods other than the selected chart timeframe. As input I'm passing bars with the timeframe being passed by an optional parameter.
I now experience that calculate is being called with endIndex > inputs.length when adding the indicator to a chart.
The error even shows up when setting the optional period parameter to the same value as the selected period on the chart.

The start of calculate reads as follows:
    public IndicatorResult calculate(int startIndex, int endIndex) {
        //calculating startIndex taking into account lookback value
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
        if (startIndex >= endIndex || inputs[0].length < endIndex) {
           context.getConsole().getOut().println("Testindicator.log: index/inputs-arraysize problem: startIdx/endIdx=" + startIndex + "/" + endIndex + ", inputs.length=" + inputs[0].length);
            return new IndicatorResult(0, 0);
        }

        ....


The indicator is producing the following log messages. You can see, that the DukasCopy error message states that the input array size = 4000, which it clearly isn't (length=142...).

Quote:
11:44:58 Error in indicator: calculate() method of indicator [TestIndicator] returned less values than expected. Requested from-to [0]-[3999], input array size [4000], returned first calculated index [0], number of calculated values [0], lookback [0], lookforward [0], expected number of elements is [4000]
11:44:58 TestIndicator.log: index/inputarray problem: startIdx/endIdx=0/3999, inputs.length=142


I've attached the test code.

I guess this a bug?
Or am I missing something here?

Any feedback is highly appreciated.
Thanks & best, RR.


Attachments:
File comment: Testindicator with dummy logic
TestIndicator.java [6.65 KiB]
Downloaded 323 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.
 
 Post subject: Re: JFOREX-3142 Indicator.calculate: endIndex > inputsArray. Post rating: 0   New post Posted: Fri 09 Sep, 2011, 08:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Have a look at the following: https://www.dukascopy.com/wiki/index.php?title=Indicator_with_multiple_inputs
"Indicators always have at least one input (main input). Main input's instrument, period and offer side are chart's instrument, period and offer side. Even if the main input wasn't defined in the indicator, it still exists. Indicator's calculate method receives indexes (startIndex and endIndex ) for this main input." That is why input synchronization is required.

In order to see the full picture:
Add one more input with default everything as follows:
...
 inputParameterInfos = new InputParameterInfo[] { 
                 barInput,
                 new InputParameterInfo("Default input", InputParameterInfo.Type.BAR)
         };

...
Add additional debug messages:
...
 if (startIndex >= endIndex || inputs[0].length < endIndex) { 
          context.getConsole().getOut().println("main input's length: " + inputs[1].length);
          context.getConsole().getOut().println("Testindicator: index/inputs-arraysize problem: startIdx/endIdx=" + startIndex + "/" + endIndex + ", inputs.length=" + inputs[0].length);
             return new IndicatorResult(0, 0);
         }

...


 

Jump to:  

  © 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