private void makeDough() throws JFException { console.getOut().println("rucham pape"); List<IOrder> orders = engine.getOrders(); if (orders.isEmpty()) { console.getOut().println("attempt to open"); feedTheAlligator(alligatorShift); } else { for (IOrder order : orders) { console.getOut().println("attempt to close..."); if (putTheAlligatorToSleep(order, alligatorShift) != null) { console.getOut().println("...and open"); feedTheAlligator(alligatorShift); } } } }
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; }