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.

does MA calculation work in backtesting?
 Post subject: does MA calculation work in backtesting? Post rating: 0   New post Posted: Thu 26 May, 2011, 23:12 

User rating: -
I wrote the following code in the onBar() method to skip further processing if the trend is not going up:

double[] fastMA = JForexContext.getIndicators().ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 40, IIndicators.MaType.SMA, Filter.ALL_FLATS, 2, barTime, 0);

double[] slowMA = JForexContext.getIndicators().ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 80, IIndicators.MaType.SMA, Filter.ALL_FLATS, 2, barTime, 0);

if (fastMA[0] < slowMA[0]) return;

In theory, there should be no trade if fastMA is below slowMA. However during backtesting, I saw several trades under this condition. Am I doing something wrong in the code, or is the MA calculation not working properly in backtesting?

Thanks,

Vinh


 
 Post subject: Re: does MA calculation work in backtesting? Post rating: 0   New post Posted: Wed 01 Jun, 2011, 08:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Make sure you use the right platform filter (Filter.ALL_FLATS since you use it when calling indicators).


 
 Post subject: Re: does MA calculation work in backtesting? Post rating: 0   New post Posted: Thu 02 Jun, 2011, 17:46 

User rating: -
I found out that I forgot to filter out the irrelevant periods. It works now. Thanks.


 

Jump to:  

cron
  © 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