Thank you for your answers, but each one presents methods of printing all elements of a list or array. I'm sorry for not being clear with my request. Here is the question from my original posting:
Can you please help me understand the proper way to access an individual element of a custom indicator's output array for use within logical comparisons, calculations, etc?
I confused the issue by not realizing there are differences between lists and arrays (and I still don't know what I've got in this case).
I have created a custom indicator and I'm trying to use it in a strategy as follows:
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.context = context;
this.indicators = context.getIndicators();
indicators.registerCustomIndicator(new File(context.getFilesDir() + System.getProperty("file.separator") + "sema.jfx"));
Object[] sema = indicators.calculateIndicator(selectedInstrument, selectedPeriod, new OfferSide[] {OfferSide.BID},
"sema", new AppliedPrice[]{AppliedPrice.CLOSE}, new Object[]{0.62, 0.72},
Filter.WEEKENDS, 200, context.getHistory().getLastTick(selectedInstrument).getTime(), 0);
Here is my question explicitly: When I get to "onBar", how do I test the 4th element of the indicator (index=3) to see if it is greater than 2.15? I know the following doesn't work, but it expresses what I am trying to do:
if (sema[3] > 2.15) {
// do something when true
}
It is the individual elements of my custom indicator which I am trying to access for tests and calculations, one at a time. My problem is that I don't know how to convert the array or list or cast types or whatever... because I am still very new to java.
Thank you for your patience.
UPDATE!! ... through trial and error, I've made some progress. I now have 2 questions (at the end)... here is the background:
// this code works when index = 0 only. Any other index gives an out of bounds error.
Object[] semaArr = {(double[])sema[0]};
sMA = ((double[]) semaArr[0])[0];
context.getConsole().getOut().println("***************************");
context.getConsole().getOut().println("sema[0] = " + sMA);
context.getConsole().getOut().println("***************************");
// however, this code shows that the indicator is populating data for indexes 0 through 199 (200 elements).
for (Object o3 : sema) {
for (double d3 : (double[])o3){
context.getConsole().getOut().println("sema = " + d3);
}
}
Historical Tester output looks like this (note that the line labeled sema[0] matches the first sema printed out immediately above it.
2011-06-15 04:08:13 sema = 1.3648239441128291
2011-06-15 04:08:13 sema = 1.3650261687179712 etc.
2011-06-15 04:08:13 sema = 1.3648241282051874 index=2
2011-06-15 04:08:13 sema = 1.3647003373820723 index=1
2011-06-15 04:08:13 sema = 1.365108782584401.......................<----\
2011-06-15 04:08:13 ***************************.....................------- these match, index=0
2011-06-15 04:08:13 sema[0] = 1.365108782584401...................<----/
2011-06-15 04:08:13 ***************************
// 2 Questions:
// Why does the data in positions 1 thru 199 seem to "go away / not be accessible" when the loop logic shows they are there?
// Is the data at index=0 the most recently closed bar? (during onBar processing)? I thought 0 = the in-progress/unfinished bar and 1 = most recent close?
Thanks!