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.

Indicator values != chart values
 Post subject: Indicator values != chart values Post rating: 0   New post Posted: Wed 23 Feb, 2011, 17:09 

User rating: 0
Joined: Wed 17 Nov, 2010, 17:00
Posts: 2
Hello!
I have an issue with inconsistency of indicator calculated values and chart values.
This could be my omission, but please help me to understand:
here is the code :
package jforex;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.MaType;
public class StochCheck implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
   
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.context = context;
      this.indicators = context.getIndicators();
      this.userInterface = context.getUserInterface();
   }
   public void onAccount(IAccount account) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onStop() throws JFException {}
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(period!=Period.ONE_HOUR){return;}
        double[] tmp = context.getIndicators().stoch(instrument, Period.ONE_HOUR, OfferSide.BID, 40, 3, MaType.SMA, 3, MaType.SMA, 0);
        IChart chart = context.getChart(instrument);
        if (chart != null) {
            IChartObject chartObject = chart.draw("X" + bidBar.getTime(), IChart.Type.TIMEMARKER, bidBar.getTime(), bidBar.getHigh());
            chartObject.setText(tmp[0] + "");
        }
   }
}



There i'm using stoch with 40,3,3,SMA,SMA , the same I put into chart, but values doesn't match.
I also tried to set shift index to 1 instead of 0, but it's doesn't help.

Please advice.


 
 Post subject: Re: Indicator values != chart values Post rating: 0   New post Posted: Thu 24 Feb, 2011, 16:31 

User rating: 5
Joined: Fri 22 Oct, 2010, 09:54
Posts: 24
Hi,

Try it out with shift = 1 instead of 0. 0 = currently forming candle and 1 = the last formed candle.

double[] tmp = context.getIndicators().stoch(instrument, Period.ONE_HOUR, OfferSide.BID, 40, 3, MaType.SMA, 3, MaType.SMA, 1);


regards,
Kirilla


 
 Post subject: Re: Indicator values != chart values Post rating: 0   New post Posted: Fri 25 Feb, 2011, 13:15 

User rating: 0
Joined: Wed 17 Nov, 2010, 17:00
Posts: 2
Thank you! But as I mentioned I already tried with 0 and 1 and 2 it's doesn't help.
It looks as some major bug in indicators system.
Please advice.


 
 Post subject: Re: Indicator values != chart values Post rating: 0   New post Posted: Fri 25 Feb, 2011, 15:19 

User rating: 5
Joined: Fri 22 Oct, 2010, 09:54
Posts: 24
Hi,

I've checked this and it wroked fine.

package jforex;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.MaType;
public class StochCheck implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
   
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.context = context;
      this.indicators = context.getIndicators();
      this.userInterface = context.getUserInterface();
   }
   public void onAccount(IAccount account) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onStop() throws JFException {}
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if(period!=Period.ONE_HOUR){return;}
       
        double[] tmp = context.getIndicators().stoch(instrument, Period.ONE_HOUR, OfferSide.BID, 40, 3, MaType.SMA, 3, MaType.SMA, 1);
        IChart chart = context.getChart(instrument);
        if (chart != null) {
            IChartObject chartObject = chart.draw("X" + bidBar.getTime(), IChart.Type.TIMEMARKER, bidBar.getTime(), bidBar.getHigh());
            chartObject.setText(tmp[0] + "");
        }
       
        for(int i = 0; i < tmp.length ;i++){
            this.console.getOut().println(i+". " + tmp[i]);
        }
   }
}


I set the shift to 1, because when it is 0 it will change with every tick. I turn off every filter on my chart(flat and sunday) and I set chart shows Bid price. the first item of tmp will be Slow %K and the second Slow %D. Both of those value were equal with indicator on the chart.

14:10:10 1. 89.58511805677955 (Slow %D)
14:10:10 0. 92.2306560627457 (Slow %K)


regards,
Kirilla


Attachments:
Chart_EUR_USD_Hourly_snapshot.png [26.89 KiB]
Downloaded 374 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

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