Dukascopy
 
 
Wiki JStore Search Login

JFOREX-2998 Calculating MACD
 Post subject: JFOREX-2998 Calculating MACD Post rating: 0   New post Posted: Mon 16 May, 2011, 10:26 

User rating: 0
Joined: Mon 16 May, 2011, 08:45
Posts: 2
Hi Guys,

I am quite new to this and was just trying to get the MACD value using the following code but unfortunately when I check against the Demo graph from the "https://www.dukascopy.com/client/demo/jclient/jforex.jnlp" the values dont match up.

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
       console.getOut().println("Before");
      try {
         String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
         Calendar cal = Calendar.getInstance();
          SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);


         double [] macd0= indicators.macd(instrument, Period.ONE_MIN, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 12, 26, 9, 0) ;
           double macd=macd0[0];
           DecimalFormat df = new DecimalFormat("#.#######");
           console.getOut().println("MACD=" + df.format(macd) + " Time = " + sdf.format(bidBar.getTime()));

         
      } catch (JFException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      
    }


Please advise what I am doing wrong.

Thank you for your time in advance.


 
 Post subject: Re: Calculating MACD Post rating: 0   New post Posted: Mon 16 May, 2011, 11:18 

User rating: 0
Joined: Mon 16 May, 2011, 08:45
Posts: 2
All I am trying to do is print out the MACD value, MACD signal value and MACD hist value as shown on the chart for a given currency.

The value I am getting back from the server do not match up with the one in the demo chart.

Can some one please help me with this.

Any help would be appreciated.


 
 Post subject: Re: JFOREX-2998 Calculating MACD Post rating: 0   New post Posted: Tue 24 May, 2011, 11:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You should add filtration by instrument and set the correct Timezone for your SimpleDateFormat object, have a look at the following:
...
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {       
  if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.ONE_MIN)) {
    return;
  }
...
  SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
  sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
...


 

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