Dukascopy
 
 
Wiki JStore Search Login

converting string output to array output
 Post subject: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 16:16 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi

Can you show me how to alter the following String output:-

2013.09.26 22:06:24,1375725600000[2013-08-05 18:00:00.000+0000] O: 1.32598 C: 1.32582 H: 1.32659 L: 1.32566 V: 5108.65
2013.09.26 22:06:24,1375729200000[2013-08-05 19:00:00.000+0000] O: 1.32581 C: 1.32601 H: 1.32606 L: 1.3251 V: 3713.53
2013.09.26 22:06:24,1375732800000[2013-08-05 20:00:00.000+0000] O: 1.32602 C: 1.32579 H: 1.32604 L: 1.32542 V: 2478.61
2013.09.26 22:06:24,1375736400000[2013-08-05 21:00:00.000+0000] O: 1.32579 C: 1.32613 H: 1.32642 L: 1.32554 V: 1455.94
2013.09.26 22:06:24,1375740000000[2013-08-05 22:00:00.000+0000] O: 1.32613 C: 1.32578 H: 1.32615 L: 1.32565 V: 1264.67
2013.09.26 22:06:24,1375743600000[2013-08-05 23:00:00.000+0000] O: 1.3258 C: 1.32576 H: 1.32587 L: 1.32528 V: 982.19

to an Array output, like:-

for i=0 to 5
Array[0][i] -Date
Array[1][i] - Time
Array[2][i] - Open
Array[3][i] - High
Array[4][i] - Low
Array[5][i] - Close
array[6][i] - Volume

Many thanks

Bob M


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 17:43 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
You do not need to split the string to your array... just get what you want with the getters of IBar objects -> https://www.dukascopy.com/client/javadoc ... /IBar.html

Trade well

JL


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 21:05 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi there

A bit of overkill here............
I don't understand how to iterate for the six bars concerned...........
******************************
// get the last six hour bars data: Date, Time, OHLC and Volume and save to Array

long startTime = (barTime - 1000*60*60*6);
long prevBarTime = (barTime - 1000*60*60);

List<IBar> lastSixBars = myHistory.getBars(myInstrument, myPeriod, OfferSide.BID, com.dukascopy.api.Filter.WEEKENDS, startTime, prevBarTime);

for (IBar bar : lastSixBars) {

//print out a whole Bar of information as one string
myContext.getConsole().getOut().println(bar.toString());

// save the various pieces to an Array
double[][]ohlcvArray = new double[6][lastSixBars.size()];
for (int i = 0; i < lastSixBars.size(); i++){
ohlcvArray[0][i] = lastSixBars.get(i).getTime();
ohlcvArray[1][i] = lastSixBars.get(i).getOpen();
ohlcvArray[2][i] = lastSixBars.get(i).getHigh();
ohlcvArray[3][i] = lastSixBars.get(i).getLow();
ohlcvArray[4][i] = lastSixBars.get(i).getClose();
ohlcvArray[5][i] = lastSixBars.get(i).getVolume();

myConsole.getOut().println("Date: "+ df.format(ohlcvArray[0][i]) + "," + "Time: "+ tf.format(ohlcvArray[0][i]) + "," + "Open: "+ ohlcvArray[1][i] + "," + "High: " + ohlcvArray[2][i] + "," + "Low: " + ohlcvArray[3][i] + "," + "Close: " + ohlcvArray[4][i] + "," + "Volume: " + ohlcvArray[5][i]);

}
}
lastSixBars.clear();

Bob M


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 21:37 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
double[][]ohlcvArray = new double[6][lastSixBars.size()];
int i=0;
for (IBar bar : lastSixBars) {

//print out a whole Bar of information as one string
myContext.getConsole().getOut().println(bar.toString());
ohlcvArray[0][i] = bar.getTime();
ohlcvArray[1][i] = bar.getOpen();
ohlcvArray[2][i] = bar.getHigh();
ohlcvArray[3][i] = bar.getLow();
ohlcvArray[4][i] = bar.getClose();
ohlcvArray[5][i] = bar.getVolume();

myConsole.getOut().println("Date: "+ df.format(ohlcvArray[0][i]) + "," + "Time: "+ tf.format(ohlcvArray[0][i]) + "," + "Open: "+ ohlcvArray[1][i] + "," + "High: " + ohlcvArray[2][i] + "," + "Low: " + ohlcvArray[3][i] + "," + "Close: " + ohlcvArray[4][i] + "," + "Volume: " + ohlcvArray[5][i]);

i++;
}


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 22:41 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
thank you................

A few lines of code further on I am trying to calculate the return over the six-bar period

return = ((ohlcvArray[4][5] - ohlcvArray[1][0]) / ohlcvArray[1][0] * 100);

I get the following error message

ohlcvArray cannot be resolved ?

Bob M


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sat 28 Sep, 2013, 22:51 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
https://stackoverflow.com/questions/2585 ... e-resolved

i advise you to spend some time here -> https://www.newthinktank.com/videos/java-video-tutorial/


 
 Post subject: Re: converting string output to array output Post rating: 0   New post Posted: Sun 29 Sep, 2013, 02:18 
User avatar

User rating: 2
Joined: Fri 02 Mar, 2012, 22:08
Posts: 200
Location: New Zealand, Dunedin
Hi

Thank's for the advice :)

Bob M


 

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