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.

Getting historical indicator values
 Post subject: Getting historical indicator values Post rating: 0   New post Posted: Tue 20 Mar, 2012, 18:59 

User rating: 0
Joined: Sun 18 Mar, 2012, 17:13
Posts: 4
Hi,

I'm trying to calculate the highest volume of x bars in my strategy. I keep the last bar update time saved in a local long variable (long prevbartime). I then calculate the length of the period in milliseconds (long periodms) and get volume of previous 30 bars with the following method:

double[] histvolume = indicators.volume(instrument, period, OfferSide.BID, prevbartime - 30 * periodms, prevbartime);


The problem with this method is that if market has not been open throughout the time span then a JFException is thrown. Is there more elegant way to do this?


 
 Post subject: Re: Getting historical indicator values Post rating: 0   New post Posted: Wed 21 Mar, 2012, 09:26 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
rounder8 wrote:
The problem with this method is that if market has not been open throughout the time span then a JFException is thrown.
This is not the case (see in the example below).
rounder8 wrote:
Is there more elegant way to do this?

Consider application of candle stick filters, e.g.:
package jforex.strategies.indicators;

import java.util.Arrays;

import com.dukascopy.api.*;

@RequiresFullAccess
public class VolumeIndTest implements IStrategy {   
   
    private IIndicators indicators;
    private IConsole console;
    private IHistory history;
   

    @Override
    public void onStart(IContext context) throws JFException {
        indicators = context.getIndicators();
        console = context.getConsole();
        history = context.getHistory();
        long time = history.getBarStart(Period.FOUR_HOURS, history.getLastTick(Instrument.EURUSD).getTime());
       
        double[] volumes = indicators.volume(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, Filter.NO_FILTER, 50, time, 0);
        double[] volumes2 = indicators.volume(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, Filter.WEEKENDS, 50, time, 0);
       
        //mind that the latest value is the last one in the array
        console.getOut().println("volume no filter: " + Arrays.toString(volumes));
        console.getOut().println("volume weekends filter: " + Arrays.toString(volumes2));

        context.stop();
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}

}


 

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