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.

about IHighLowListener??
 Post subject: about IHighLowListener?? Post rating: 0   New post Posted: Thu 26 Apr, 2018, 11:11 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
........................
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.IHighLowListener
............................
public class secStrategy implements IStrategy ,IHighLowListener {

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

}

....................
@Override
public void highUpdated(Instrument instrument, double high) {
//To change body of generated methods, choose Tools | Templates.
if (instrument.equals(Curinstrument))
{
this.maxHighPrice=high;
print(String.format(" cur high=%.5f",high));
}
}

@Override
public void lowUpdated(Instrument instrument, double low) {
//To change body of generated methods, choose Tools | Templates.
if(instrument.equals(this.Curinstrument))
{
this.minLowPrice=low;
print(String.format("cur min price=%.5f",low));
}
}
......................

}

Running all day, nothing happened!!!!


I don't understand why this is happening, someone told me how to use this interface!
!
thanks!


 
 Post subject: Re: about IHighLowListener?? Post rating: 0   New post Posted: Fri 27 Apr, 2018, 15:41 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You need to add your IHighLowListener implementation to DataService. Otherwise he cannot receive information

context.getDataService().addHighLowListener(Period.DAILY, Instrument.EURUSD, this);


 
 Post subject: Re: about IHighLowListener?? Post rating: 0   New post Posted: Tue 01 May, 2018, 03:27 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
The problem is still there!!!

Can you tell me what "this" means()?

...........
I use this way:

public class myStrategy implements IStrategy, IHighLowListener {

      public Instrument Curinstrument = Instrument.USDJPY;
      private IDataService myDataService;
      private IHighLowListener myHighLowListener;
       private IContext context;
          ................................

     public void onStart(IContext context) throws JFException {

               [color=#0040FF]    myDataService = context.getDataService();
                    if (myDataService != null) {
                   
                     myDataService.addHighLowListener(Period.DAILY, Curinstrument, myHighLowListener);[/color]
              }

..........................


 
 Post subject: Re: about IHighLowListener?? Post rating: 0   New post Posted: Tue 01 May, 2018, 08:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
grosskt wrote:
Can you tell me what "this" means()?

this refers to the current object
https://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

grosskt wrote:
I use this way:

public class myStrategy implements IStrategy, IHighLowListener {

      public Instrument Curinstrument = Instrument.USDJPY;
      private IDataService myDataService;
      private IHighLowListener myHighLowListener;
       private IContext context;
          ................................

     public void onStart(IContext context) throws JFException {

               [color=#0040FF]    myDataService = context.getDataService();
                    if (myDataService != null) {
                   
                     myDataService.addHighLowListener(Period.DAILY, Curinstrument, myHighLowListener);[/color]
              }


You declared variable, but didn't initialize it. In this example myHighLowListener == null.

First option is to implement IHighLowListener interface inside your strategy, as in your first example, and then pass this into parameters.

Second option is to create IHighLowListener object, override methods, and then pass reference to this object in dataService.
    @Override
    public void onStart(IContext context) throws JFException {

        IHighLowListener myHighLowListener = new IHighLowListener() {
            @Override
            public void highUpdated(Instrument instrument, double high) {
                //your logic here
            }

            @Override
            public void lowUpdated(Instrument instrument, double low) {
                //your logic here
            }
        };

        context.getDataService().addHighLowListener(Period.ONE_MIN, Instrument.EURUSD, myHighLowListener);
    }


 
 Post subject: Re: about IHighLowListener?? Post rating: 0   New post Posted: Wed 02 May, 2018, 09:41 

User rating: 0
Joined: Mon 11 Dec, 2017, 03:30
Posts: 26
Location: China,
Run these code:

     .........................
                      private IEngine engine;
                      private IHistory history;
                      private IConsole console;
                      private IDataService myDataService;
                      private IHighLowListener myHighLowListener;
                      private IContext context;
                ..................................................
                 public void onStart(IContext context) throws JFException {
                                 this.context = context;
                                 this.console = context.getConsole();
                                   this.engine = context.getEngine();
                                this.history = context.getHistory();
                                 myDataService = context.getDataService(); 
                                 .........................
                                   Set<Instrument> instruments = new HashSet<Instrument>();
                                  instruments.add(Curinstrument);
                                   context.setSubscribedInstruments(instruments, true);
                                   ................................

                            if (myDataService != null) {
       
                                           myHighLowListener = new IHighLowListener() {
                                                 double _maxHighPrice=0,_minLowPrice=0;
                @Override
                public void highUpdated(Instrument instrument, double high)  {
                    //your logic here
                    try{
                     if(high!=0)
                          _maxHighPrice = high;
                    // console.getOut().println("cur min price=%.5f"+high);
                    }
                    catch(Exception et)
                    {
                        et.printStackTrace();
                        // console.getOut().println("HighUpdated exception"+et);
                    }
                }

                @Override
                public void lowUpdated(Instrument instrument, double low)  {
                    //your logic here
                    try
                    {
                       if(low!=0)
                         _minLowPrice = low;
                   // console.getOut().println("cur min price=%.5f"+low);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                      //  console.getOut().println("lowUpdated exception"+e);
                    }
                }
           
            };
            if(myHighLowListener!=null)
            myDataService.addHighLowListener(Period.DAILY, Curinstrument, myHighLowListener);
            //myDataService.
            else
                 console.getOut().println("create highlowlistener exception");
             ...............................


in netbean platom exception found :

2018-05-02 16:40:13.697 ERROR AbstractStrategyRateDataNotificationManager -
java.lang.NullPointerException
at com.dukascopy.charts.data.datacache.hl.HighLowManager.scheduleToFillPreviousCandle(HighLowManager.java:302)
at com.dukascopy.charts.data.datacache.hl.HighLowManager.newCandle(HighLowManager.java:222)
at com.dukascopy.api.impl.connect.JForexHighLowManager.newCandle(JForexHighLowManager.java:112)
at com.dukascopy.dds2.greed.agent.strategy.tester.listener.TesterHighLowManager.onBar(TesterHighLowManager.java:138)
at com.dukascopy.dds2.greed.agent.strategy.notification.candle.StrategyCandleNotificationManager.onBar(StrategyCandleNotificationManager.java:91)
at com.dukascopy.dds2.greed.agent.strategy.notification.candle.StrategyCandleNotificationManager.onBar(StrategyCandleNotificationManager.java:27)
at com.dukascopy.dds2.greed.agent.strategy.notification.AbstractStrategyRateDataNotificationManager.historicalBarReceived(AbstractStrategyRateDataNotificationManager.java:339)
at com.dukascopy.dds2.greed.agent.strategy.tester.AbstractStrategyRunner.historicalCandleReceived(AbstractStrategyRunner.java:465)
at com.dukascopy.dds2.greed.agent.strategy.tester.StrategyTesterRunner.run(StrategyTesterRunner.java:348)
at java.lang.Thread.run(Thread.java:748)
2018-05-02 16:40:13.698 ERROR AbstractStrategyRateDataNotificationManager -


 

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