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.

Problem with indicator values when backtesting
 Post subject: Problem with indicator values when backtesting Post rating: 0   New post Posted: Wed 12 Jun, 2013, 16:55 

User rating: 0
Joined: Thu 23 May, 2013, 10:24
Posts: 3
Location: SwitzerlandSwitzerland
Hello,
I found a strange behavior of indicators when I'm backtesting. Where did I make the mistake?

I have the following code in the onBar method:

IBar previousBar = history.getBar(instrument, period, OfferSide.BID, 1); 
long currBarTime = previousBar.getTime();
int candlesBefore = 2, candlesAfter = 0;

double sma200[] = indicators.sma(myInstrument, myPeriod, OfferSide.BID, AppliedPrice.CLOSE,
        200, Filter.NO_FILTER, candlesBefore, currBarTime, candlesAfter);


I want to use later this indicator to read the value for the previously closed bar, or the one before by using:
sma200[1] or sma200[0]

When I'm running my strategy in real time, everything seems fine, I'm getting the correct values for the indicator.
The problem starts when I run my strategy in the Historical Tester. If I compare the value of SMA200 of the chart of the Historical Tester with the value my code prints into the log I found a difference. Please note that the problem is only with the indicator values, the bar OHLC values are fine...


 
 Post subject: Re: Problem with indicator values when backtesting Post rating: 0   New post Posted: Thu 13 Jun, 2013, 07:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Indicator_usage_checklist


 
 Post subject: Re: Problem with indicator values when backtesting Post rating: 0   New post Posted: Thu 13 Jun, 2013, 11:12 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
In addition to the checklist above you may also be experiencing the same as this other poster (namely accessing the most recent SMA with [0] and not [199]):

https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=48578


 
 Post subject: Re: Problem with indicator values when backtesting Post rating: 0   New post Posted: Thu 13 Jun, 2013, 15:45 

User rating: 0
Joined: Thu 13 Jun, 2013, 15:43
Posts: 1
CriticalSection wrote:
In addition to the checklist above you may also be experiencing the same as this other poster (namely accessing the most recent SMA with [0] and not [199]):

https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=48578


Issue solved, thank you! The problem was related with filters indeed.


 

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