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.

TickBar vs time based indicators
 Post subject: TickBar vs time based indicators Post rating: 0   New post Posted: Mon 16 Sep, 2013, 08:39 

User rating: 3
Joined: Mon 05 Nov, 2012, 11:56
Posts: 80
Location: Germany,
Dear Support,

I got stuck here please help! I'm going to write a strategy based on the 70 tick bars using the following piece of code below:

 int tickBarSize= 70 ;
   
   .....................................................................................................................................
    context.subscribeToTickBarFeed(Instrument.EURUSD, OfferSide.BID,  TickBarSize.valueOf(tickBarSize), new ITickBarFeedListener() {
            @Override
            public void onBar(Instrument instrument, OfferSide offerSide, TickBarSize size, ITickBar bar) {
                            
                double[] heikin = indicators.heikinAshi(instrument, period, OfferSide.BID, 1);  // what period ????
                ......................................................................................................
            }
        });


My question is: how to use the time based indicator indicators.heikinAshi within the ITickBarFeedListener here ? What value should I give for the indicators.heikinAshi's "Period" parameter?

Thank you in advance!


 
 Post subject: Re: TickBar vs time based indicators Post rating: 0   New post Posted: Mon 16 Sep, 2013, 08:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See the example:
https://www.dukascopy.com/wiki/#Chart_feeds/Feed_history,_indicator_calculation_and_chart_opening
For more on indicator calculation on a feed, see:
https://www.dukascopy.com/wiki/#Indicator_Calculation/Universal_price_feed


 
 Post subject: Re: TickBar vs time based indicators Post rating: 0   New post Posted: Mon 16 Sep, 2013, 11:11 

User rating: 3
Joined: Mon 05 Nov, 2012, 11:56
Posts: 80
Location: Germany,
API Support wrote:



Thanks Support for the prompt answer! After reading the links I understood that I have to calculate the heikinAshi indicator with the following function below:

Object[] heikin= indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "heikinAshi", new AppliedPrice[] { AppliedPrice.CLOSE }, null, dataCount, feedData.getTime(), 0);


but how can I get the "IFeedDescriptor feedDescriptor" and feedData.getTime() variables from within the context.subscribeToTickBarFeed function?

Could you please give an example? I don't really understand the connection between ITickBarFeedListener and IFeedDescriptor here.

Thanks in advance!


 
 Post subject: Re: TickBar vs time based indicators Post rating: 0   New post Posted: Mon 16 Sep, 2013, 11:56 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ccadar wrote:
but how can I get the "IFeedDescriptor feedDescriptor" and feedData.getTime() variables from within the context.subscribeToTickBarFeed function?
You need to use IContext.subscribeToFeed, consider modifying our given wiki example to use the heikin ashi indicator:
public class TickBarsHeikinAshi implements IStrategy, IFeedListener {

    private IConsole console;
    private IIndicators indicators;

    @Configurable(value = "feed type", description = "choose any type of feed (except ticks) in the strategy parameters dialog")
    public IFeedDescriptor feedDescriptor = new TickBarFeedDescriptor(Instrument.EURUSD, TickBarSize.valueOf(70), OfferSide.BID);

    @Override
    public void onStart(IContext context) throws JFException {

        console = context.getConsole();
        indicators = context.getIndicators();

        if (feedDescriptor.getDataType() == DataType.TICKS) {
            console.getErr().println("IFeedListener does not work with ticks yet!");
            context.stop();
        }

        context.setSubscribedInstruments(new HashSet<Instrument>(Arrays.asList(new Instrument[] { feedDescriptor.getInstrument() })), true);

        console.getOut().println("subscribe to feed=" + feedDescriptor);
        context.subscribeToFeed(feedDescriptor, this);

    }

    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
        console.getInfo().println(feedData + " of feed: " + feedDescriptor);
        try {
            double[] c = (double[]) indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "HeikinAshi",
                    new AppliedPrice[] { AppliedPrice.CLOSE }, null, 1)[0];
            console.getOut().format("%s ha O: %.5f H: %.5f L: %.5f C: %.5f ", DateUtils.format(feedData.getTime()), c[OPEN], c[HIGH], c[LOW], c[CLOSE]).println();
        } catch (JFException e) {
            console.getErr().println(e);
            e.printStackTrace();
        }
    }

ccadar wrote:
I don't really understand the connection between ITickBarFeedListener and IFeedDescriptor here.
There is no connection between those two rather IFeedListener is a generalization of ITickBarFeedListener and IFeedDescriptor correspondingly of TickBarFeedDescriptor. Using more general methods gives you more flexibility in adjusting the strategy when the business logic changes - for instance, in the given example you may switch to using 1-minute candles or, say, renko bricks simply by changing the feed descriptor parameter in the strategy dialog, without any additional coding required.


Attachments:
TickBarsHeikinAshi.java [2.65 KiB]
Downloaded 85 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:  

  © 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