code: public Order operate(int index, Decimal price, Decimal amount) {
          Order order = null;
          if (isNew()) {
              order = new Order(index, startingType, price, amount);
              entry = order;
          } else if (isOpened()) {
              if (index < entry.getIndex()) {
                  throw new IllegalStateException("The index i is less than the entryOrder index");
              }
              order = new Order(index, startingType.complementType(), price, amount);
              exit = order;
          }
          return order;
      }
docs: Operates the trade at the index-th position
  @param index the tick index
  @param price the price
  @param amount the amount
  @return the order