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.

problems comparing indicator values
 Post subject: problems comparing indicator values Post rating: 0   New post Posted: Sun 07 Nov, 2010, 22:35 
User avatar

User rating: 0
Joined: Thu 16 Jun, 2011, 21:37
Posts: 98
Location: SwitzerlandSwitzerland
Hello all,

I am saving a macd value at time X in my program and during every onBar I am comparing the value of the macd val at time X to the new macd values. Depending on the situation my code sometimes compares (< or >) the saved macd value at time X to the new macd value from onBar at time same X. Sometimes the original macd val I have stored will be large than the newly returned macd val from the same time X.

It seems obvious that the precision of the double is what is causing this. My question is, should I be truncating the macd values or should I be storing them as BigDecimal? What is the standard length that all double indicator values get truncated to?

Thanks for the help,
jForexUser


 
 Post subject: Re: problems comparing indicator values Post rating: 0   New post Posted: Tue 09 Nov, 2010, 22:11 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
Hi,

Have a look here first: viewtopic.php?f=9&t=24189
If you test using Tick on Close, you could receive undesired ticks from other instruments. For example, you get onBar tick for USDJPY at moment X and you try log the EURUSD macd values; I suppose you use shift 0 or 1 or similar; but EURUSD tick for time X may not still be generated and in fact the EURUSD last tick is at time X-1 so the macd shows the value at time X-1 tick. To be sure what you check, in onBar print the instrument first: console.getOut.println(instrument) got from onBar() and its time from bidBar.getTime(). Also, if you test using Tick on Close, better change and use Tick on Open.


 
 Post subject: Re: problems comparing indicator values Post rating: 0   New post Posted: Wed 10 Nov, 2010, 08:55 
User avatar

User rating: 0
Joined: Thu 16 Jun, 2011, 21:37
Posts: 98
Location: SwitzerlandSwitzerland
hi darlu72,

I have solved this problem be truncating the macd's to 7 decimal places using the following code:

double truncateDouble(double p_val) {
     DecimalFormat newForm = new DecimalFormat("#.#######");
     return Double.valueOf(newForm.format(p_val));
}


hope this helps others!


 

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