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.

interface question
 Post subject: interface question Post rating: 0   New post Posted: Wed 17 Jun, 2015, 06:39 
User avatar

User rating: 2
Joined: Sat 02 May, 2015, 20:20
Posts: 20
Location: Ukraine, Kyiv
Hello, I'm attempting to utilize some of the code of the MQL to Jforex converter here at https://code.google.com/p/jftoolbox/source/browse/trunk/src/jforex/mql/MQLBridge.java

There are many valuable conversions here among them ihighest and ilowest that I would like to use. I have copied the functions into my strategy code. I have figured out how to get everything hooked up except one thing.

IBar[] bars = box.getNBars(symbol, convertedPeriod, offerSide, start, count);


From the original Ibox code https://code.google.com/p/jftoolbox/source/browse/trunk/src/jforex/api/IBox.java

I see it is an interface and I don't even understand exactly what this line does but I copied a snippet over from the Ibox java code and here is what I have in my strategy:
    public interface Ibox {
        IBar[] getNBars(Instrument instrument, Period period, OfferSide offerSide, int start, int count) throws JFException;             
    }
This is placed at the top of my
public class FullMarketDepth implements IStrategy {


So in the MQLbridge code they call the Ibox interface...
import jforex.api.IBox;
so I think I can use my code snippet instead of this but how do I get it working such that I can call box.getNBars?

So After I place the public interface Ibox I then call it using
protected IBox box = null;


So code looks like this
   public interface IBox {
        List<IBar> getLastBars(Instrument instrument, Period period, OfferSide offerSide, int bars, boolean takeUnformedBar) throws JFException;
        IBar[] getNBars(Instrument instrument, Period period, OfferSide offerSide, int start, int count) throws JFException;
    }
    protected IBox box = null;


I put in my strategy the ihighest code
protected int iHighest(Instrument symbol, int timeframe, int type, int count, int start) {
        return iHighest(symbol, timeframe, type, count, start, OfferSide.BID);
    }
    protected int iHighest  (Instrument symbol, int timeframe, int type, int count, int start, OfferSide offerSide) {
        int rc = -1;
        if (symbol == null) {
            symbol = instrument;
        }
        Period convertedPeriod = convertPeriod(timeframe);

        try {
            IBar[] bars = box.getNBars(symbol, convertedPeriod, offerSide, start, count);         
            double highValue = Double.MIN_VALUE;
            for (int i = 0; i < bars.length; i++) {

                IBar bar = bars[i];

                double value = 0;
                switch (type) {
                case MODE_OPEN:
                    value = bar.getOpen();
                    break;
                case MODE_LOW:
                    value = bar.getLow();
                    break;
                case MODE_HIGH:
                    value = bar.getHigh();
                    break;
                case MODE_CLOSE:
                    value = bar.getClose();
                    break;
                case MODE_VOLUME:
                    value = bar.getVolume();
                    break;
                case MODE_TIME:
                    value = bar.getTime() / 1000;
                    break;
                default:
                    value = bar.getOpen();
                    break;
                }
                if (value > highValue) {
                    rc = i + start;
                    highValue = value;
                }
            }

        } catch (JFException e) {
            e.printStackTrace();
            context.stop();
        }
        return rc;
    }


In the Bar routine I then try to use the Ihighest code with
 for (int w=0;w<=lookbackbars;w++) {        
         int tempvollast3barsbar=iHighest(instrument,PERIOD_M1,MODE_VOLUME,2,w);}     


but when I run it, it gives me a runtime error of
05:32:22 java.lang.NullPointerException @ jforex.FullMarketDepth.iHighest(FullMarketDepth.java:659)

Please help. If I can get this working it will get a lot of code working...

Thank you!
TBB


 
 Post subject: Re: interface question Post rating: 0   New post Posted: Mon 22 Jun, 2015, 14:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please give full example to reproduce the error.
Please note that we cannot give advice on programming that is not related to JForex API https://www.dukascopy.com/client/javadoc/.


 

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