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.

array index out of bounds error in IIndicator.onCalculate()
 Post subject: array index out of bounds error in IIndicator.onCalculate() Post rating: 0   New post Posted: Thu 10 Jan, 2019, 22:14 
User avatar

User rating: 0
Joined: Tue 26 Jan, 2016, 04:18
Posts: 16
Location: CanadaCanada
Does anyone know why the following code would generate an array out of bounds error?

public IndicatorResult calculate(int startIndex, int endIndex) {
        outputs = inputs;
        return new IndicatorResult(startIndex, --endIndex);
    }


Same error occurs even if I don't decrement endIndex. Looking at the original auto generated code, IndicatorResult is called like this:

Quote:
IndicatorResult(startIndex, j);


where j is always endIndex - 1. Therefore, --endIndex should be the same as endIndex - 1. No matter what combinations of endIndex values I try, I always get the same error which never changes from run to run:

Error in indicator: calculate() method of indicator [PTI] returned incorrect values. Requested from-to [0]-[3,448],  input array size [3,449], returned first calculated index [60], number of calculated values [3,447], lookback [60], lookforward [0], first index + number of elements cannot be > input array size


The onStart() method looks like this:
 public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("PTI", "Price projection onto the Cartesian plane", "My indicators",
                false, false, false, 1, 1, 1);
               
        InputParameterInfo inputPI = new InputParameterInfo("Source Series", InputParameterInfo.Type.DOUBLE);
        inputPI.setOfferSide(OfferSide.BID);
        inputPI.setPeriod(timeFrame);
        inputPI.setAppliedPrice(IIndicators.AppliedPrice.CLOSE);
       
        inputParameterInfos = new InputParameterInfo[] {
            inputPI
        };
        optInputParameterInfos = new OptInputParameterInfo[] {
            new OptInputParameterInfo("Timeframe", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(60, 1, 1440, 1))
        };
        outputParameterInfos = new OutputParameterInfo[] {
            new OutputParameterInfo("Projected Price", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
        };
        console = context.getConsole();
    }



Here I am only trying to understand how JForex handles the inputs and outputs arrays as the indicator is called from somewhere else--beats me from where and how/where startIndex and endIndex come from. But also, later I need to build a very simple indicator that passes through all CLOSE price values from a ONE_HOUR timeframe when attached to a chart which timeframe is < ONE_HOUR.

So obviously, the logic is very simple: set the InputParameterInfo to OfferSide.BID, Period.ONE_HOUR, and IIndicators.AppliedPrice.CLOSE.

I assume that JForex will automatically populate the double array inputs[][] with the BID CLOSE price of every ONE_HOUR candle. I write 'assume' because I cannot find any documentation on the exact nature of this input population mechanism.

Why do I want to do this? Because I need to see the display of these values in an indicator pane when later the output of this indicator is passed to another indicator in a strategy I am working on.

As you can see, the calculate() method does not use a loopback and no loops. It's just a straightforward reference copy of 1 array to another. So why should this cause an index out of bounds error???

And why is the first calculated index == 60 when no lookback period is used in the calculate() method, regardless of the timeframe of the chart the indicator is attached to? Shouldn't the first calculated index == 0 always in this case because the first candle in the series is always at index 0?

Any help greatly appreciated as I cannot find any pertinent information neither in the API docs nor the wiki.


 

Jump to:  

cron
  © 1998-2024 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