Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

drawOutput() never called during backtesting
 Post subject: drawOutput() never called during backtesting Post rating: 0   New post Posted: Thu 31 Mar, 2011, 07:46 

User rating: 0
Joined: Sun 30 Jan, 2011, 11:43
Posts: 6
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
}


 
 Post subject: Re: drawOutput() never called during backtesting Post rating: 0   New post Posted: Sat 02 Apr, 2011, 06:49 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
At runtime, the tester calls only calculate(int startIndex, int endIndex) method.
It will not try to draw the indicator even you have charts opened.
The fast solution is what you tried:
- start strategy, click Pause
- manually add your custom indicator to chart
- click Continue and your custom indicator will be plotted

As a more complicated solution, there is a method to the IChart called addIndicator() if I am not wrong.
If called in your strategy it should solve your problem but you must deal with the chart operations in your code
and registering indicators directly in the strategy. I did not try it so far.

Regards


 
 Post subject: Re: drawOutput() never called during backtesting Post rating: 0   New post Posted: Wed 06 Apr, 2011, 19:28 

User rating: 0
Joined: Sun 30 Jan, 2011, 11:43
Posts: 6
Thanks for your help;

I implemented the addIndicator() method with no success.

It actually adds the indicator to the indicator list (in the instrument navigation panel on the left), but it doesn't appear the tester's graph.

Wondering how people can extensively test scenarios without a fully featured testing tool.

All ideas are welcome :-)
Thanks again.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com