Hi,
I'm new to JForex.
Getting no graph from custom indicators when running in visual backtest mode. While these custom indicators work fine when manually added to an instrument chart. I probably missed something, can you please help on drawing indicators output ?
Solutions I tried based on what I saw on the forum:
1) I Implemented the IDrawingIndicator interface, but drawOutput() is never called during backtesting, (while it is called, when the indicator is manually added to an existing chart - the case that works anyway).
2) Tried to draw the indicators output directly from the strategy, but the graph is wired ! Example: the COPY indicator below just copies inputs (OCHLV) to outputs. - When I draw the OCHL returned by the indicator, the graph is false. - When I draw the OCHL from the bar passed through onBar() instead, the graph is correct.
--- details --- /* ** Calculation function of the COPY indicator */ public IndicatorResult calculate(int startIndex, int endIndex) { //calculating startIndex taking into account lookback value if (startIndex - getLookback() < 0) { startIndex -= startIndex - getLookback(); } int i, j; for (i = startIndex, j=0; i <= endIndex; i++, j++) { for (int k = 4; k >=0; k--) { outputs[k][j]=inputs[0][k][i]; } } return new IndicatorResult(startIndex, j); }
/* ** draw function of the Strategy */ public void drawBarOutput(String aTag, Instrument aInstrument, Period aPeriod, Object[][] aOutput) throws JFException { IChart myChart=context.getChart(aInstrument); IChartObject myObject; if (myChart == null || aOutput[0]==null || aOutput[1]==null) return; // get bars for Times on the x axis IBar prevBar = history.getBar(aInstrument, aPeriod, OfferSide.BID, 2); IBar currBar = history.getBar(aInstrument, aPeriod, OfferSide.BID, 1); for(int i=0; i<aOutput[1].length-1; i++) { // don't graph Volumes (length-1) myObject = myChart.draw(aTag+"["+i+"]"+currBar.getTime(), IChart.Type.SHORT_LINE, prevBar.getTime(), (Double)aOutput[0][i], // aOutput[0]=previous output vector currBar.getTime(), (Double)aOutput[1][i]);// aOutput[1]=new output vector } // END FOR }
|