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

converting string output to array output
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=77&t=50105
Page 1 of 1

Author:  us_copiosus [ Sat 28 Sep, 2013, 16:16 ]
Post subject:  converting string output to array output

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

Author:  jlongo [ Sat 28 Sep, 2013, 17:43 ]
Post subject:  Re: converting string output to array output

You do not need to split the string to your array... just get what you want with the getters of IBar objects -> http://www.dukascopy.com/client/javadoc ... /IBar.html

Trade well

JL

Author:  us_copiosus [ Sat 28 Sep, 2013, 21:05 ]
Post subject:  Re: converting string output to array output

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

Author:  jlongo [ Sat 28 Sep, 2013, 21:37 ]
Post subject:  Re: converting string output to array output

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++;
}

Author:  us_copiosus [ Sat 28 Sep, 2013, 22:41 ]
Post subject:  Re: converting string output to array output

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

Author:  jlongo [ Sat 28 Sep, 2013, 22:51 ]
Post subject:  Re: converting string output to array output

http://stackoverflow.com/questions/2585 ... e-resolved

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

Author:  us_copiosus [ Sun 29 Sep, 2013, 02:18 ]
Post subject:  Re: converting string output to array output

Hi

Thank's for the advice :)

Bob M

  Page 1 of 1