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.javaThere 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.javaI 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