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.

Calling ATR & How to use OHLC inputs
 Post subject: Calling ATR & How to use OHLC inputs Post rating: 0   New post Posted: Thu 05 Nov, 2009, 04:34 

User rating: 0
Joined: Wed 21 Oct, 2009, 04:47
Posts: 22
Hi there,

I am attempting to call the ATR indicator to create an ATR Band but I am having difficulties understanding how this should be done. The first problem being is that there is little info on what parameters it takes without going to the TA-LIB site and then trying decode the source (unless there is some proper docco on each indicator & their parameters?)

From what I understand so far, the ATR is expecting an array with OHLCV which is given by the input:

        inputParameterInfos =
            new InputParameterInfo[]{new InputParameterInfo("Input data", InputParameterInfo.Type.PRICE)};


When I try to feed this into the ATR indicator, I seem to be getting a graph that is shifted forward by the lookback value (14). Could someone kindly point out what I have done incorrectly in this code:

        double atrBuffer[] = new double[endIndex - startIndex + 2 + atrIndicator.getLookback()];

       //multPrice - copy the section of the array
        double[][] multPrice = new double[5][endIndex - startIndex + 1 + getLookback()];
        for (int arrc=0, j=0; arrc < 5; arrc++, j++)
        for (int resIndex = 0; resIndex <= endIndex; resIndex++) {
            //Inputs: 0 open, 1 close, 2 high, 3 low, 4 volume
            multPrice[j][resIndex] = inputs[0][arrc][resIndex];
        }

        // call the atr indicator
        atrIndicator.setInputParameter(0, multPrice);
        atrIndicator.setOptInputParameter(0, timePeriod);
        atrIndicator.setOutputParameter(0, atrBuffer);
        IndicatorResult atrResult = atrIndicator.calculate(startIndex - 1, endIndex);

        // Set output values which is Close + atr*multipler
        int i = 0, k =0;
        for (i = 1, k = atrResult.getNumberOfElements(); i < k; i++) {
            outputs[0][i - 1] = multPrice[1][i] + atrBuffer[i]*multipler;
            outputs[1][i - 1] = multPrice[1][i] + atrBuffer[i]*multipler;
        }
        return new IndicatorResult(startIndex, i-1);

       

Appreciate your help!


 
 Post subject: Re: Calling ATR & How to use OHLC inputs Post rating: 0   New post Posted: Fri 06 Nov, 2009, 08:21 

User rating: 0
Joined: Wed 21 Oct, 2009, 04:47
Posts: 22
I figured it out - you need add the offset by lookback bars when using the resultant OHLC prices.

eg.
        int i = 0, k =0;
        for (i = 1, k = atrResult.getNumberOfElements(); i < k; i++) {
            outputs[0][i - 1] = multPrice[1][i+getLookback()-1] + (atrBuffer[i] * multipler);
            outputs[1][i - 1] = multPrice[1][i+getLookback()-1] - (atrBuffer[i] * multipler);
        }


 

Jump to:  

  © 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