Program: 98343
Project: 98343
Buggy source:
@Override public void onBar(Instrument instrument,Period period,IBar askBar,IBar bidBar) throws JFException {
  if (!instrument.equals(this.instrument) || !period.equals(this.period))   return;
  if (askBar.getVolume() == 0 || bidBar.getVolume() == 0)   return;
  IBar prevBar=history.getBar(instrument,period,OfferSide.BID,1);
  double[][] ha=indicators.heikinAshi(instrument,period,OfferSide.BID,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  final int PREV=numberOfCandlesBefore + numberOfCandlesAfter - 1;
  final int OPEN=0, HIGH=2, LOW=3, CLOSE=1;
  double average=priceToPips(((ha[PREV][HIGH] - ha[PREV][LOW]) + (ha[PREV - 1][HIGH] - ha[PREV - 1][LOW])) / 2.0);
  double spread=askPrice - bidPrice;
  stopLossPips=roundPips(stopLossFactor * average);
  if (stopLossPips < stopLossFactor)   return;
  double volume=getLotSize(account);
  takeProfitPips=roundPips(takeProfitFactor * average);
  if (takeProfitPips < takeProfitFactor)   return;
  if (!useStopLoss)   stopLossPips=0;
  double[][] dc=indicators.donchian(instrument,period,OfferSide.BID,dcTimePeriod,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  final int UPPER=0, LOWER=1;
  double[] maf=indicators.ma(instrument,period,OfferSide.BID,appliedPriceFast,maTimePeriodFast,maTypeFast,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  double[] mas=indicators.ma(instrument,period,OfferSide.BID,appliedPriceSlow,maTimePeriodSlow,maTypeSlow,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  if (askPrice < maf[PREV]) {
    for (    IOrder order : engine.getOrders()) {
      if (order.getLabel().substring(0,id.length()).equals(id) && order.getState() == IOrder.State.FILLED) {
        if (order.isLong() && order.getProfitLossInPips() > stopLossFactor)         order.close();
      }
    }
  }
 else   if (bidPrice > maf[PREV]) {
    for (    IOrder order : engine.getOrders()) {
      if (order.getLabel().substring(0,id.length()).equals(id) && order.getState() == IOrder.State.FILLED) {
        if (!order.isLong() && order.getProfitLossInPips() > stopLossFactor)         order.close();
      }
    }
  }
  double amt=0;
  boolean uol=account.getUseOfLeverage() > maximumUoL;
  if (uol) {
    for (    IOrder order : engine.getOrders(instrument)) {
      if (order.getState() == IOrder.State.FILLED) {
        if (order.isLong())         amt+=order.getAmount();
 else         amt-=order.getAmount();
      }
    }
  }
  boolean longOk=(uol && amt > 0) ? false : true;
  boolean shortOk=(uol && amt < 0) ? false : true;
  if (verbose) {
    SimpleDateFormat bdf=new SimpleDateFormat("String_Node_Str");
    bdf.setTimeZone(TimeZone.getTimeZone("String_Node_Str"));
    console.getOut().printf("String_Node_Str",bdf.format(roundTime(prevBar.getTime(),60000)));
    console.getOut().printf("String_Node_Str",Arrays.deepToString(ha));
    console.getOut().printf("String_Node_Str",Arrays.deepToString(dc));
    console.getOut().printf("String_Node_Str",Arrays.toString(maf));
    console.getOut().printf("String_Node_Str",Arrays.toString(mas));
    console.getOut().printf("String_Node_Str",bidPrice,askPrice,stopLossPips,takeProfitPips);
    console.getOut().printf("String_Node_Str",average,spread,volume);
    if (uol)     console.getOut().printf("String_Node_Str",amt,account.getUseOfLeverage());
  }
  if (longOk && bidPrice + spread < dc[LOWER][PREV] && dc[LOWER][PREV] < dc[LOWER][PREV - 1]) {
    double stopLossPrice=stopLossPips > 0 ? stopLossPrice=askPrice - getPipPrice(stopLossPips) : 0;
    double takeProfitPrice=askPrice + getPipPrice(takeProfitPips);
    console.getOut().printf("String_Node_Str",getLabel(instrument),instrument.name(),askPrice,volume,stopLossPrice,takeProfitPrice);
    IOrder order=engine.submitOrder(getLabel(instrument),instrument,OrderCommand.BUY,volume,askPrice,slippage,stopLossPrice,takeProfitPrice);
  }
  if (shortOk && askPrice > dc[UPPER][PREV] && dc[UPPER][PREV] > dc[UPPER][PREV - 1]) {
    double stopLossPrice=stopLossPips > 0 ? stopLossPrice=bidPrice + getPipPrice(stopLossPips) : 0;
    double takeProfitPrice=bidPrice - getPipPrice(takeProfitPips);
    console.getOut().printf("String_Node_Str",getLabel(instrument),instrument.name(),bidPrice,volume,stopLossPrice,takeProfitPrice);
    IOrder order=engine.submitOrder(getLabel(instrument),instrument,OrderCommand.SELL,volume,bidPrice,slippage,stopLossPrice,takeProfitPrice);
  }
}

Fixed version (ground truth):
@Override public void onBar(Instrument instrument,Period period,IBar askBar,IBar bidBar) throws JFException {
  if (!instrument.equals(this.instrument) || !period.equals(this.period))   return;
  if (askBar.getVolume() == 0 || bidBar.getVolume() == 0)   return;
  IBar prevBar=history.getBar(instrument,period,OfferSide.BID,1);
  double[][] ha=indicators.heikinAshi(instrument,period,OfferSide.BID,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  double average=priceToPips(instrument,((ha[PREV][HIGH] - ha[PREV][LOW]) + (ha[PREV - 1][HIGH] - ha[PREV - 1][LOW])) / 2.0);
  double spread=askPrice - bidPrice;
  stopLossPips=roundPips(stopLossFactor * average);
  if (stopLossPips < stopLossFactor)   return;
  double volume=getLotSize(account);
  takeProfitPips=roundPips(takeProfitFactor * average);
  if (takeProfitPips < takeProfitFactor)   return;
  if (!useStopLoss)   stopLossPips=0;
  double[][] dc=indicators.donchian(instrument,period,OfferSide.BID,dcTimePeriod,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  final int UPPER=0, LOWER=1;
  double[] maf=indicators.ma(instrument,period,OfferSide.BID,appliedPriceFast,maTimePeriodFast,maTypeFast,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  double[] mas=indicators.ma(instrument,period,OfferSide.BID,appliedPriceSlow,maTimePeriodSlow,maTypeSlow,indicatorFilter,numberOfCandlesBefore,prevBar.getTime(),numberOfCandlesAfter);
  if (askPrice < maf[PREV]) {
    for (    IOrder order : engine.getOrders()) {
      if (order.getLabel().substring(0,id.length()).equals(id) && order.getState() == IOrder.State.FILLED) {
        if (order.isLong() && order.getProfitLossInPips() > stopLossFactor)         order.close();
      }
    }
  }
 else   if (bidPrice > maf[PREV]) {
    for (    IOrder order : engine.getOrders()) {
      if (order.getLabel().substring(0,id.length()).equals(id) && order.getState() == IOrder.State.FILLED) {
        if (!order.isLong() && order.getProfitLossInPips() > stopLossFactor)         order.close();
      }
    }
  }
  double amt=0;
  boolean uol=account.getUseOfLeverage() > maximumUoL;
  if (uol) {
    for (    IOrder order : engine.getOrders(instrument)) {
      if (order.getState() == IOrder.State.FILLED) {
        if (order.isLong())         amt+=order.getAmount();
 else         amt-=order.getAmount();
      }
    }
  }
  boolean longOk=(uol && amt > 0) ? false : true;
  boolean shortOk=(uol && amt < 0) ? false : true;
  if (verbose) {
    SimpleDateFormat bdf=new SimpleDateFormat("String_Node_Str");
    bdf.setTimeZone(TimeZone.getTimeZone("String_Node_Str"));
    console.getOut().printf("String_Node_Str",bdf.format(roundTime(prevBar.getTime(),60000)));
    console.getOut().printf("String_Node_Str",Arrays.deepToString(ha));
    console.getOut().printf("String_Node_Str",Arrays.deepToString(dc));
    console.getOut().printf("String_Node_Str",Arrays.toString(maf));
    console.getOut().printf("String_Node_Str",Arrays.toString(mas));
    console.getOut().printf("String_Node_Str",bidPrice,askPrice,stopLossPips,takeProfitPips);
    console.getOut().printf("String_Node_Str",average,spread,volume);
    if (uol)     console.getOut().printf("String_Node_Str",amt,account.getUseOfLeverage());
  }
  if (longOk && bidPrice + spread < dc[LOWER][PREV] && dc[LOWER][PREV] < dc[LOWER][PREV - 1]) {
    double stopLossPrice=stopLossPips > 0 ? stopLossPrice=askPrice - getPipPrice(instrument,stopLossPips) : 0;
    double takeProfitPrice=askPrice + getPipPrice(instrument,takeProfitPips);
    console.getOut().printf("String_Node_Str",getLabel(instrument),instrument.name(),askPrice,volume,stopLossPrice,takeProfitPrice);
    IOrder order=engine.submitOrder(getLabel(instrument),instrument,OrderCommand.BUY,volume,askPrice,slippage,stopLossPrice,takeProfitPrice);
  }
  if (shortOk && askPrice > dc[UPPER][PREV] && dc[UPPER][PREV] > dc[UPPER][PREV - 1]) {
    double stopLossPrice=stopLossPips > 0 ? stopLossPrice=bidPrice + getPipPrice(instrument,stopLossPips) : 0;
    double takeProfitPrice=bidPrice - getPipPrice(instrument,takeProfitPips);
    console.getOut().printf("String_Node_Str",getLabel(instrument),instrument.name(),bidPrice,volume,stopLossPrice,takeProfitPrice);
    IOrder order=engine.submitOrder(getLabel(instrument),instrument,OrderCommand.SELL,volume,bidPrice,slippage,stopLossPrice,takeProfitPrice);
  }
}