JFUtil offers [an elegant way of requesting indicators from the JForex IIndicators interface]. But the new design for JForex IIndicators through JFUtil is only fixing one side of the problem. There is still the question of what to do with the multiple return types from the calculations. In JForex, indicators like RSI returns a one-dimensional array. Other indicators like Stochastic Oscillator returns a two-dimensional array. And some other ones return three or more dimensional arrays. Java doesn't allow overloading a method with multiple return types, as the program wouldn't know what to expect. So how can we get rid of coding mess like this in our JForex strategy? [java] Stochastic stochBean = IndicatorBeanFactory.getStochastic(); Object objs = Indicating.calculateMultiDimension(instrument, Period.ONE_MIN, stochBean, 1); double sto = new double; sto = (double)objs; // %K values sto = (double)objs; // %D values [/java] The default calculation method in JForex returns a generic Object array. It's up to the programmer to know what to expect from the call and cast the Object into something useful. Obviously, this is a recipe for programming headaches and runtime errors. Having said this, one of the biggest benefits of JForex is that it uses a standard programming language like Java. So if there's something that you don't like about the API, you can probably change it (e.g. Facade pattern). This is the purpose of JFUtil to some extent, to simplify the JForex API behaviour. In any case, I'm sure other Java programmers have faced this problem before and have come up with good solutions for it. A search on stackoverflow.com doesn't yield a quick fix solution at first glimpse. My guess is that this require leveraging the knowledge about the program structure. We know in advance what dimension of the calculation result we can expect based on the indicator itself, perhaps I can use something like a Command pattern to choose a calculation sub-routine and then return a Map object with named values? I have yet to try implementing this. I am open to design suggestions to encapsulate multiple return values through a single interface. So that any indicator bean can use the same calculation interface with an easy to use output. In the mean time, getting multi-dimensional indicators results through JFUtil 2.1.2 isn't pretty.
[an elegant way of requesting indicators from the JForex IIndicators interface]: http://www.quantisan.com/conjuring-beans-to-simplify-jforex-iindicators/