private IOrder putTheAlligatorToSleep(IOrder alligatorOrder, int shift) throws JFException {
    IOrder result = null;

    // dirty
    // get alligator from previous bar and the alligator from alligatorWidth
    // bars back
    // to check for alligator reversal
    IBar prevBar = history.getBar(instrument, alligatorTimeframe, OfferSide.BID, shift);
    // dirty

    double[][] alligator =
        indicators.alligator(
            instrument,
            alligatorTimeframe,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            prevBar.getTime(),
            prevBar.getTime());

    // Trend trend = askTheAlligator(alligator, prevBar, shift);
    // close on shorter trend switch
    HashMap<String, double[]> alis =
        findMTMShorterAlligators(timeframeWidth, alligatorTimeframe, shift);

    if (!isAlligatorCoherent(new ArrayList(alis.values()), alligatorTimeframe)) {
      alligatorOrder.close();
    }

    return result;
  }
  // TODO - make possible to parameterize the Trend conditions Lips/Jaw and
  // Gator
  private boolean didAlligatorReverse(
      double[][] alligator, IBar alligatorBar, Period timeframe, int shift) throws JFException {

    IBar historicalAlligatorBar =
        history.getBar(instrument, timeframe, OfferSide.BID, alligatorLength + shift);

    double[][] historicalAlligator =
        indicators.alligator(
            instrument,
            timeframe,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            historicalAlligatorBar.getTime(),
            alligatorBar.getTime());

    double alligatorTeeth = alligator[0][1];
    double alligatorLips = alligator[0][2];

    // double historicalAlligatorJaw = historicalAlligator[0][0];
    double historicalAlligatorTeeth = historicalAlligator[1][0];
    double historicalAlligatorLips = historicalAlligator[2][0];

    boolean result =
        Math.signum(historicalAlligatorTeeth - historicalAlligatorLips)
                == Math.signum(alligatorTeeth - alligatorLips)
            ? false
            : true;

    return result;
  }
  private HashMap<String, double[]> findMTMShorterAlligators(
      int width, Period basePeriod, int shift) throws JFException {
    HashMap<String, double[]> result = new HashMap<String, double[]>();

    int baseIndex = this.periods.indexOf(basePeriod);
    Period shortPeriod = this.periods.get(baseIndex + width);
    console.getOut().println("Short period " + shortPeriod.toString());

    IBar shortBar = history.getBar(instrument, shortPeriod, OfferSide.BID, shift);

    /*
     * not necessarily quickest double[][] longAlligator =
     * indicators.alligator(instrument, longPeriod, OfferSide.BID,
     * AppliedPrice.MEDIAN_PRICE, jaw, teeth, lips, longBar.getTime(),
     * longBar.getTime());
     *
     * double[][] shortAlligator = indicators.alligator(instrument,
     * shortPeriod, OfferSide.BID, AppliedPrice.MEDIAN_PRICE, jaw, teeth,
     * lips, shortBar.getTime(), shortBar.getTime());
     */

    double[] shortAlligator =
        indicators.alligator(
            instrument,
            shortPeriod,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            shift);

    double[] alligator =
        indicators.alligator(
            instrument,
            alligatorTimeframe,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            shift);

    result.put(shortPeriod.name(), shortAlligator);
    result.put(alligatorTimeframe.name(), alligator);

    console.getOut().println("result " + result.size());
    return result;
  }
  private HashMap<String, double[]> findMTMLongerAlligators(int width, Period basePeriod, int shift)
      throws JFException {
    HashMap<String, double[]> result = new HashMap<String, double[]>();

    int baseIndex = this.periods.indexOf(basePeriod);
    Period longPeriod = this.periods.get(baseIndex - width);
    console.getOut().println("Long period " + longPeriod.toString());

    IBar longBar = history.getBar(instrument, longPeriod, OfferSide.BID, shift);

    double[] longAlligator =
        indicators.alligator(
            instrument,
            longPeriod,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            shift);

    double[] alligator =
        indicators.alligator(
            instrument,
            alligatorTimeframe,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            shift);

    result.put(alligatorTimeframe.name(), alligator);
    result.put(longPeriod.name(), longAlligator);

    return result;
  }
  private IOrder feedTheAlligator(int shift) throws JFException {

    IOrder result = null;
    OrderCommand feed = null;
    double stopLossPrice, takeProfitPrice;

    // dirty
    // get alligator from previous bar and the alligator from alligatorWidth
    // bars back
    // to check for alligator reversal
    IBar prevBar = history.getBar(instrument, alligatorTimeframe, OfferSide.BID, shift);
    // dirty

    double[][] alligator =
        indicators.alligator(
            instrument,
            alligatorTimeframe,
            OfferSide.BID,
            AppliedPrice.MEDIAN_PRICE,
            jaw,
            teeth,
            lips,
            prevBar.getTime(),
            prevBar.getTime());

    double alligatorJaw = alligator[0][0];
    double alligatorTeeth = alligator[1][0];
    double alligatorLips = alligator[2][0];

    Date date = new Date(prevBar.getTime());
    console
        .getOut()
        .println(
            "On "
                + date
                + " Alligator says - Jaw: "
                + alligatorJaw
                + " Teeth: "
                + alligatorTeeth
                + " Lips: "
                + alligatorLips);

    Trend alligatorSays = askTheAlligator(alligator, prevBar, 1);
    HashMap<String, double[]> mtmAlligators =
        findMTMShorterAlligators(timeframeWidth, alligatorTimeframe, shift);

    boolean isAliCoherent =
        isAlligatorCoherent(new ArrayList(mtmAlligators.values()), alligatorTimeframe);

    if (alligatorSays == Trend.BEARISH && isAliCoherent) feed = OrderCommand.SELL;
    else if (alligatorSays == Trend.BULLISH && isAliCoherent) feed = OrderCommand.BUY;

    if (feed != null) {
      if (feed == OrderCommand.BUY) {
        stopLossPrice =
            history.getLastTick(this.instrument).getAsk()
                - this.stopLossPips * this.instrument.getPipValue();
        takeProfitPrice =
            history.getLastTick(this.instrument).getAsk()
                + takeProfitPips * this.instrument.getPipValue();
      } else {
        stopLossPrice =
            history.getLastTick(this.instrument).getBid()
                + this.stopLossPips * this.instrument.getPipValue();
        takeProfitPrice =
            history.getLastTick(this.instrument).getBid()
                - takeProfitPips * this.instrument.getPipValue();
      }

      result =
          engine.submitOrder(
              getLabel(feed),
              this.instrument,
              feed,
              amount,
              0,
              20,
              stopLossPips != 0 ? stopLossPrice : stopLossPips,
              takeProfitPips != 0 ? takeProfitPrice : takeProfitPips);

      // engine.submitOrder("order", Instrument.EURUSD, feed, amount, 0,
      // 20, stopLossPrice, 0);
    }

    return result;
  }