Some things to keep in mind with when coding an indicator with multiple inputs & outputs.
1. Define correct number of arrays
I will need 2 time periods and 4 outputs, so first I have to make sure I start the arrays correctly:
private int[] timePeriod = new int[2]; private double[][] outputs = new double[4][];
2. Defining the correct parameter info for each item
I need to define 2 periods and 4 ouputs
indicatorInfo = new IndicatorInfo("maCross", "Moving Average Cross",
"My indicators",true, false, false, 1, 2, 4);
optInputParameterInfos = new OptInputParameterInfo[] {
new OptInputParameterInfo("Time period 1:",
OptInputParameterInfo.Type.OTHER,
new IntegerRangeDescription(5, 2, 100, 1)),
new OptInputParameterInfo("Time period 2:",
OptInputParameterInfo.Type.OTHER,
new IntegerRangeDescription(8, 2, 100, 1))
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("MA1", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("MA2", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("UP", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_UP),
new OutputParameterInfo("DOWN", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_DOWN)};
3. Calculating the Output Values
You need to use arrays for input values. In my case for the “time Period 1″ I have to use the first array value which is 0, and for the “time Period 2″ I use the second array value which is 1
outputs[0][j] = value/timePeriod[0]; outputs[1][j] = value2/timePeriod[1]; outputs[2][j] = 0; outputs[3][j] = 0;
Also make sure you find values for all outputs. I have 4 outputs, so I need values for outputs[0], outputs[1], outputs[2] and outputs[3].
4. Download Sample Source code
Here is a sample source code for a maCross indicator I just coded for practice.
Click to download: maCross.java
Category: >> jForex
