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.

Converting obsolete methods to valid ones
 Post subject: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 09:33 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
Hello,

I run the strategy in JForex program. It was working well but recently it stops when I execute the following code:

ILongLineChartObject longLine = chart.getChartObjectFactory().createLongLine( "longTrendLine", xt1, p1, t2, p2 );


Is this because that createLongLine call is depreciated? How the valid call should look now?

Regards,
FXer


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 10:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See the notice at the beginning of:
https://www.dukascopy.com/wiki/#Chart_object_catalog
Also find there 2 examples of long line usage.
If you don't succeed to resolve this, then for more efficient assistance please:
  1. provide a full example strategy,
  2. provide a precise test case and JForex-API version,
  3. describe the behavior that you find being wrong,
  4. provide error messages from Messages tab or Java Console, if any,
  5. describe the desired behavior.


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 11:00 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
Hello Support,

I do succeed, but it haven't solve my problem, because full code sequence was as follows:

ILongLineChartObject longLine = chart.getChartObjectFactory().createLongLine( "longTrendLine"+X, t1, p1, t2, p2 );
// Many things to do, and at the end:
if (chart.get("longTrendLine"+X) != null) {
    chart.remove("longTrendLine"+X);
}


Because there is no createLongLine(String s) constructor, how to remove such object? Do I have to keep objects list? Can I also remove those objects if my strategy stopped in the meantime?

Regards,
FXer


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 11:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
https://www.dukascopy.com/wiki/#Create_a ... cts/Remove
If you don't succeed removing it, please provide what you receive on the java console:
viewtopic.php?f=81&t=39073


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 13:13 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
The issue is not a bug problem but - as I understood - change in philosophy. Please see code attached below:

package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.ILongLineChartObject;

public class StrategyXXX implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    ILongLineChartObject longLine;
    IChart chart;
   
    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();
       
        ITick tick = history.getLastTick(Instrument.EURUSD);
        List<ITick> ticks = history.getTicks(Instrument.EURUSD, tick.getTime() - 60 * 1000L, tick.getTime());
        chart = context.getChart(Instrument.EURUSD);
        if (ticks != null && !ticks.isEmpty()) {
            ITick firstTick = ticks.get(0);
            ITick lastTick = ticks.get(ticks.size() - 1);
            longLine =  chart.getChartObjectFactory().createLongLine();
            // longLine =  chart.getChartObjectFactory().createLongLine("longLine");
            //     Is there now equivalent of constructor as above?
            longLine.setTime(0, firstTick.getTime());
            longLine.setPrice(0, firstTick.getAsk());
            longLine.setTime(1, lastTick.getTime());
            longLine.setPrice(1, lastTick.getAsk());   
            chart.addToMainChart(longLine);
        }
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
        chart.remove(longLine);
        // As far as I understood, the only way to remove such object
        // is to refer it by address. But what if I stopped the program
        // (or it broke)  in the meantime? Is there equivalent of  remover
        // like below:
        // if (chart.get("longLine") != null) { chart.remove("longLine"); }
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


Till now I paint on my chart "by hand" and then add some objects from script. In any moment I could distinguish if I painted it or added in script, because of the object naming style I use. As I understood, now there is no way to distinguish if its "painted" or "added by script"... Now to remove all the objects I have painted from my script I have to keep reference in the script. But what if my script broke in the meantime (it happens sometimes)?

Regards,
FXer


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Thu 26 Apr, 2012, 13:59 

User rating: 1
Joined: Tue 24 Apr, 2012, 13:41
Posts: 39
BTW, how to draw a channel. When I run code below:
IChannelChartObject channel = chart.getChartObjectFactory().createChannel();
channel.setTime(0, t1); channel.setPrice(0, p1);
channel.setTime(1, t2); channel.setPrice(1, p2);
channel.setTime(2, t3); channel.setPrice(2, p3);


I get severe exception Incorrect point index [3] , pointCount = [2] , pointIndex must be less or equal to pointCount.

Regards,
FXer


 
 Post subject: Re: Converting obsolete methods to valid ones Post rating: 0   Post Posted: Fri 27 Apr, 2012, 14:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
fxer wrote:
As I understood, now there is no way to distinguish if its "painted" or "added by script"
From platform perspective - not. However, from strategy you can retrieve all strategy-drawn objects by chart.getAll().
fxer wrote:
Now to remove all the objects I have painted from my script I have to keep reference in the script. But what if my script broke in the meantime (it happens sometimes)?
The objects can be removed not only by reference, but also by the key. Try not removing the objects on strategy stop and start a strategy that only removes objects - it should find them either by key or from chart.getAll().

fxer wrote:
BTW, how to draw a channel. When I run code below:
Code:
IChannelChartObject channel = chart.getChartObjectFactory().createChannel();
channel.setTime(0, t1); channel.setPrice(0, p1);
channel.setTime(1, t2); channel.setPrice(1, p2);
channel.setTime(2, t3); channel.setPrice(2, p3);

I get severe exception Incorrect point index [3] , pointCount = [2] , pointIndex must be less or equal to pointCount.
Try on the latest JForex DEMO the example channel in:
https://www.dukascopy.com/wiki/#Chart_object_catalog


 

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