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.

TickBarTicksRemaining.java
 Post subject: TickBarTicksRemaining.java Post rating: 0   New post Posted: Mon 11 Aug, 2014, 03:49 
User avatar

User rating: 0
Joined: Tue 14 Aug, 2012, 16:22
Posts: 2
Location: Indonesia, Bandung
Dear Support,

I trade using 70 tick, and need to know how much tick remaining in a candle.
Since I am blind at programming , I search Jforex wiki and found TickBarTicksRemaining.java at this link https://www.dukascopy.com/wiki/#Feed_history/Tick_bars_from_chart_by_shift

The strategy works great, but the problem is when the current candle closed ( 70 ticks in my case), the strategy stopped and I must re-run it.
Is it possible possible to improve this strategy so the counter keeps counting ticks for every new candle?

Regards,


Attachments:
TickBarTicksRemaining.java [1.68 KiB]
Downloaded 81 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.
 
 Post subject: Re: TickBarTicksRemaining.java Post rating: 0   New post Posted: Mon 11 Aug, 2014, 20:57 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

Use this:
package jforex.feed;

import com.dukascopy.api.*;
import com.dukascopy.api.feed.*;

/**
 * The strategy writes on chart how many ticks are remaining in the current tick bar.
 *
 */
public class TickBarTicksRemaining implements IStrategy {

    @Configurable("instrument")
    public Instrument instrument = Instrument.EURUSD;   
   
    private IConsole console;
    private IChart chart;
    private IHistory history;
   
    @Override
    public void onStart(IContext context) throws JFException {       
        console = context.getConsole();
        history = context.getHistory();
        chart   = context.getChart(instrument);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {       
        if (instrument != this.instrument){
            return;
        }
         
        if ( (chart == null) || (chart.getTickBarSize() == null) ) {
            print("Tick bar chart not opened!");
            return;
        }
       
        ITickBar currentTickBar = history.getTickBar(instrument, OfferSide.BID, chart.getTickBarSize(), 0);
        if (currentTickBar != null) {
            int remaining =  (int)(chart.getTickBarSize().getSize() - currentTickBar.getFormedElementsCount());
            print("ticks remaining: " + remaining + " currentTickBar: " + currentTickBar);
            chart.comment("Ticks remaining " + remaining);
        }
    }
   
    private void print(Object o) {
        console.getOut().println(o);
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
    public void onMessage(IMessage message) throws JFException {}
    public void onAccount(IAccount account) throws JFException {}
    public void onStop() throws JFException {}
}


 
 Post subject: Re: TickBarTicksRemaining.java Post rating: 0   New post Posted: Tue 12 Aug, 2014, 04:50 
User avatar

User rating: 0
Joined: Tue 14 Aug, 2012, 16:22
Posts: 2
Location: Indonesia, Bandung
tcsabina wrote:
Hi,

Use this:


Thank you very much sabina, it works like a charm :D

If I may ask your help little further:
1. Currently it only run on single pair that user choose when the strategy first run. It would be nice if it could run on every tick chart (any pair) that open.
2. Is it possible to put the counter to the right of the last candle (like time remaining indicator/strategy for regular chart)?

I hope I don't ask too much

Best regards,


 
 Post subject: Re: TickBarTicksRemaining.java Post rating: 1   New post Posted: Wed 13 Aug, 2014, 07:03 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
1.
You have to cycle through of the chart with a code like this
for (Instrument instrument : context.getSubscribedInstruments()) {
    for (IChart chart : context.getCharts(instrument)) {
    }
        // add code here for all the charts
}

Of course, you have to do this not only once, but from time to time (let's say every 1-2 seconds), so if you open a new chart while the strategy is running, the strategy will detect it.
There is a nice example in the wiki about how to execute a task over and over again: https://www.dukascopy.com/wiki/#Threadin ... _execution


2.
I am not aware if you can move the label what is used in the example to somewhere else. But you have better tools to place custom text or labels anywhere on the chart.
Again, there are nice examples in the wiki about this:
There is the Chart Widget, which can be used to place an OHLC type info box on the chart, so you can move it after it is drawn. This is a good choice.
Or you can use the Screen Label component, which is a bit simpler, and you cannot move it once placed.


Good luck,
and if you stuck, just let us know.


 

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