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.

Bband values (filtered) from previous bars
 Post subject: Bband values (filtered) from previous bars Post rating: 0   New post Posted: Tue 31 May, 2011, 09:07 

User rating: 0
Joined: Tue 31 May, 2011, 06:24
Posts: 4
Location: US
I can't seem to figure out how to pull the Bband value from several bars back. I'm filtering weekends. Here is what I've got in my code:

           double upperBand = indicators.bbands(this.instrument, this.period, OfferSide.BID, AppliedPrice.CLOSE, 20, 2, 2, MaType.EMA, Filter.WEEKENDS, 1, bidBar.getTime(), 3)[0][0];


So, how would I call up the bband value three bars back so I can compare the closing price of the bar three bars back to see if it is above the upper bband? I actually want to do this for multiple bars as well (e.g. determine when there are multiple bars in series that close above the upper bband).

I assume I need to figure out how to call the value from the array. I suspect it is something like upperBand[value][value] but I don't know what should replace each [value].

Any help would be much appreciated.


 
 Post subject: Re: Bband values (filtered) from previous bars Post rating: 0   New post Posted: Wed 01 Jun, 2011, 08:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Have a look the following JForex Wiki article: https://www.dukascopy.com/wiki/index.php ... nger_Bands
And the following code:
...
Period  period = Period.ONE_HOUR;
Instrument instrument = Instrument.EURUSD;
       
IBar bar = history.getBar(instrument, period, OfferSide.BID, 3); //fetching a bar 3 bars back
double closePrice = bar.getClose();

int candlesBefore = 1, candlesAfter = 0;
double[][] bbands = indicators.bbands(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 20, 2, 2, MaType.EMA, Filter.NO_FILTER, candlesBefore, bar.getTime(), candlesAfter);           

console.getOut().println("bbands values: " + bbands[0][0] + ", " + bbands[1][0] + ", " + bbands[2][0]);
...


 
 Post subject: Re: Bband values (filtered) from previous bars Post rating: 0   New post Posted: Fri 03 Jun, 2011, 19:29 

User rating: 0
Joined: Tue 31 May, 2011, 06:24
Posts: 4
Location: US
Excellent help. Thanks for your extra effort of providing the coding example, particularly the console line print - that helped me figure out that all I need to do is rename the variable for each bband bar I want back in time.

For others out there with the same interest, here is how I coded it and checked the results:

              double[][] bbands1 = indicators.bbands(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 20, stdDev, stdDev, MaType.EMA, Filter.WEEKENDS, 1, bidBar.getTime(), 0);     //one bar back in time      
                       console.getOut().println("bbands1 values: " + bbands1[0][0] + ", " + bbands1[1][0] + ", " + bbands1[2][0]);
              double[][] bbands2 = indicators.bbands(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 20, stdDev, stdDev, MaType.EMA, Filter.WEEKENDS, 2, bidBar.getTime(), 0);      //two bars back in time     
                       console.getOut().println("bbands2 values: " + bbands2[0][0] + ", " + bbands2[1][0] + ", " + bbands2[2][0]);
              double[][] bbands3 = indicators.bbands(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 20, stdDev, stdDev, MaType.EMA, Filter.WEEKENDS, 3, bidBar.getTime(), 0);      //three bars back in time     
                       console.getOut().println("bbands3 values: " + bbands3[0][0] + ", " + bbands3[1][0] + ", " + bbands3[2][0]);
              double[][] bbands15 = indicators.bbands(instrument, period, OfferSide.BID, AppliedPrice.CLOSE, 20, stdDev, stdDev, MaType.EMA, Filter.WEEKENDS, 15, bidBar.getTime(), 0);      //15 bars back in time     
                       console.getOut().println("bbands15 values: " + bbands15[0][0] + ", " + bbands15[1][0] + ", " + bbands15[2][0]);

 


Now, for example, I can simply call the lower bband value that is 15 bars back by asking for "bbands15[2][0]". Not sure if this is the simplest way to do it, nor the least computer processor intensive since it is forced to run bbands multiple times for each bar, but it works. (If there is a cleaner way to program it, I'd love to know.)

Best regards,
Just4FX


 

Jump to:  

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