コード例 #1
0
  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;
  }
コード例 #2
0
  // 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;
  }
コード例 #3
0
  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;
  }