Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Convert calculated BBANDS indicator into double Type
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=57716
Page 1 of 1

Author:  powerof618 [ Wed 22 Sep, 2021, 12:28 ]
Post subject:  Convert calculated BBANDS indicator into double Type

Hello,
I want to build a strategy with the BBANDS indicator on a 10 Pip RangeBarChart, but I don´t know, how to get the values of the indicator.
With the RSI indicator I did it this way and it worked fine:
Object[] rsiObjectsFeed = indicators.calculateIndicator(feedDescriptor, new OfferSide[]{myOfferSide}, "RSI",
                    new AppliedPrice[]{AppliedPrice.CLOSE}, new Object[]{rsiTimePeriod}, candlesBefore, feedData.getTime(), candlesAfter);
            double[] rsi = (double[]) rsiObjectsFeed[0];         
            console.getOut().println("rsi value: " + rsi[0]);


I tried to do it the similar way with the BBANDS indicator.
Object[] bbandsUniversal = indicators.calculateIndicator(
                    feedDescriptor, new  OfferSide[] {myOfferSide}, "BBANDS",
                    new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE}, new Object[]{timePeriod, nbDevUp, nbDevDn, MaType.SMA.ordinal()},0);
           
            double[][] bbands = {(double[]) bbandsUniversal[0], (double[]) bbandsUniversal[1], (double[]) bbandsUniversal[2]};
            console.getOut().println("upperbbands value: " + bbands[0]);
            console.getOut().println("midllebbands value: " + bbands[1]);
            console.getOut().println("lowerbbands value: " + bbands[2]);


Compilation is successful, but it doesn´t work. There are no values shown in the message tab.

How can I convert the "Object[] bbandsUniversal" into a double type, so I get the values of the different Bands?

Author:  vadim_berezhnoj [ Wed 29 Sep, 2021, 10:16 ]
Post subject:  Re: Convert calculated BBANDS indicator into double Type

Hello

One value is returned for each output when indicator calculated by shift:

Object[] bbandsUniversal = indicators.calculateIndicator(
        feedDescriptor, new  OfferSide[] {myOfferSide}, "BBANDS",
        new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
        new Object[]{timePeriod, nbDevUp, nbDevDn, MaType.SMA.ordinal()}, 0);

double[] bbands = {(Double) bbandsUniversal[0], (Double) bbandsUniversal[1], (Double) bbandsUniversal[2]};
console.getOut().println("upperbbands value: " + bbands[0]);
console.getOut().println("midllebbands value: " + bbands[1]);
console.getOut().println("lowerbbands value: " + bbands[2]);


Array with size corresponding to amount of candles is returned for each output when indicator calculated by candles range:

Object[] bbandsUniversal = indicators.calculateIndicator(
        feedDescriptor, new  OfferSide[] {myOfferSide}, "BBANDS",
        new IIndicators.AppliedPrice[] {IIndicators.AppliedPrice.CLOSE},
        new Object[]{timePeriod, nbDevUp, nbDevDn, MaType.SMA.ordinal()},
        candlesBefore, feedData.getTime(), candlesAfter);

double[][] bbands = {(double[]) bbandsUniversal[0], (double[]) bbandsUniversal[1], (double[]) bbandsUniversal[2]};
console.getOut().println("upperbbands value: " + Arrays.toString(bbands[0]));
console.getOut().println("midllebbands value: " + Arrays.toString(bbands[1]));
console.getOut().println("lowerbbands value: " + Arrays.toString(bbands[2]));

  Page 1 of 1