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.

Remaining Ticks Counter
 Post subject: Remaining Ticks Counter Post rating: 0   New post Posted: Mon 05 Mar, 2012, 11:19 

User rating: 0
Joined: Mon 05 Mar, 2012, 10:46
Posts: 1
Location: United Kingdom,
Hello,

I trade off a 40 tick chart. I'm trying to code a strategy that displays the number of ticks remaining in the current bar.

I've tried to do this by keeping a counter for each new bar, which is then subtracted from on each tick. However, I've found that the start time of each bar changes even when a new bar has not been displayed. This results in the counter being reset on a random basis, often 2 or 3 times per bar.

Is anyone able to help me code this functionality?

Here is my current code...

package jforex;
import com.dukascopy.api.*;
import java.awt.*;
 
public class TickCounter implements IStrategy {
    private IContext context;
    private Instrument[] instruments;
    private int[] subscribed;
    int tickCount;
    long barTime;
   
    public void onStart(IContext context) throws JFException {
            this.context = context;
            instruments = Instrument.values();
            subscribed = new int[instruments.length];
    }
 
    public void onAccount(IAccount account) throws JFException {
    }
 
    public void onMessage(IMessage message) throws JFException {
    }
 
    public void onStop() throws JFException {
        // garbage collect
        for (int i = 0; i < subscribed.length; i++){
            if (subscribed[i] == 1){
                IChart chart = context.getChart(instruments[i]);
                chart.remove("Ticks");
            }
        }
    }
 
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
        if (askBar.getTime() != barTime)
        {
            barTime = askBar.getTime();
            tickCount = 40;
        }
    }
     
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        IChart chart = context.getChart(instrument);
        if (chart != null){
            subscribed[instrument.ordinal()] = 1;
           
            double _ask = tick.getAsk();
            long _time = tick.getTime();
            long _time_shift = 2 * chart.getSelectedPeriod().getInterval();
                         
            tickCount--;
           
            IChartObject ticks = chart.get("Ticks");
            if (ticks != null) {
                ticks.setText(Double.toString(tickCount));
                ticks.move(_time + _time_shift, _ask);
            }
            else {
                ticks = chart.draw("Ticks", IChart.Type.LABEL, 0, 0);
                ticks.setColor(Color.WHITE);
                ticks.setText(Double.toString(tickCount), new Font(Font.SANS_SERIF, Font.BOLD, 12));
                ticks.move(_time + _time_shift, _ask);
            }
        }
    }
}


 
 Post subject: Re: Remaining Ticks Counter Post rating: 0   New post Posted: Tue 06 Mar, 2012, 16:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See:
https://www.dukascopy.com/wiki/#Feed_history/Tick_bars_from_chart_by_shift


 

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