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.

Convert calculated BBANDS indicator into double Type
 Post subject: Convert calculated BBANDS indicator into double Type Post rating: 0   New post Posted: Wed 22 Sep, 2021, 12:28 

User rating: 3
Joined: Thu 13 Dec, 2018, 22:09
Posts: 13
Location: GermanyGermany
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?


 
 Post subject: Re: Convert calculated BBANDS indicator into double Type Post rating: 0   New post Posted: Wed 29 Sep, 2021, 10:16 
Visual JForex expert at Dukascopy
User avatar

User rating:
Joined: Mon 22 Apr, 2013, 11:30
Posts: 604
Location: UkraineUkraine
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]));


 

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