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.

stochastic with shift 1 not equal to previous stoch shift 0
 Post subject: stochastic with shift 1 not equal to previous stoch shift 0 Post rating: 0   New post Posted: Sat 31 Aug, 2013, 22:37 

User rating: 0
Joined: Sat 08 Jun, 2013, 12:05
Posts: 71
Location: FranceFrance
I was surprised not to have a matching between the 2 same stochastic indicators, with different shifts
example below printing time+","+ stochshift0[0]+","+stochshift1[0], I expected to see matching one bar period later, but 61 != 59 and 38 != 36
21:29:50 2013-08-21 09:30:00, 76.77527151211142, 61.457811194651185
21:29:50 2013-08-21 09:15:00, 59.70342522974027, 38.30409356724653
21:29:50 2013-08-21 09:00:00, 36.84210526314978, 33.78995433789461

thanks for explanations

full strategy
package jforex;

import java.util.*;

import com.dukascopy.api.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class Stoch implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    Period period = Period.FIFTEEN_MINS;
    Instrument instrument1 = Instrument.EURCHF;
   
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   
    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();
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
    }

    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 p, IBar askBar, IBar bidBar) throws JFException {
        if (instrument==instrument1 && p == period ){
            double[] stoch0 = indicators.stoch(instrument1, period, OfferSide.BID, 5, 3, IIndicators.MaType.SMA, 3, IIndicators.MaType.SMA, 0);
            double[] stoch1 = indicators.stoch(instrument1, period, OfferSide.BID, 5, 3, IIndicators.MaType.SMA, 3, IIndicators.MaType.SMA, 1);
            console.getOut().println(df.format(askBar.getTime())+","+stoch0[0]+","+stoch1[0]);
        }
    }
}


 
 Post subject: Re: stochastic with shift 1 not equal to previous stoch shift 0 Post rating: 0   New post Posted: Mon 02 Sep, 2013, 08:01 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
0th bar is the currently forming one, the values of which change on every tick. In onBar method for the respective period 0th bar will be a flat bar aggregated from 0 ticks, because the last bar has just finished and the current one has just began forming. So you just have to see how much sense does it make to calculate an indicator on a flat bar.


 
 Post subject: Re: stochastic with shift 1 not equal to previous stoch shift 0 Post rating: 0   New post Posted: Mon 02 Sep, 2013, 22:34 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Just to say in Java what Support have mentioned:
            double[] stoch0 = indicators.stoch(instrument1, period, OfferSide.BID, 5, 3, IIndicators.MaType.SMA, 3, IIndicators.MaType.SMA, 1);
            double[] stoch1 = indicators.stoch(instrument1, period, OfferSide.BID, 5, 3, IIndicators.MaType.SMA, 3, IIndicators.MaType.SMA, 2);

If you modify your code like this, you will get what you are up to:
20:45:00 2013-09-02 20:30:00,30.159041109786738,39.24023769097511
20:29:59 2013-09-02 20:15:00,39.24023769097511,44.840777502069045


This (that you always use shift>0 for indicator calculation) can be a general rule of thumb.


 
 Post subject: Re: stochastic with shift 1 not equal to previous stoch shift 0 Post rating: 0   New post Posted: Tue 03 Sep, 2013, 07:52 

User rating: 0
Joined: Sat 08 Jun, 2013, 12:05
Posts: 71
Location: FranceFrance
thank you both for the tips


 

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