code: private double calculateProfit(TimeSeries series, Trade trade) {
          Decimal profit = Decimal.ONE;
          if (trade.isClosed()) {
              Decimal exitClosePrice = series.getTick(trade.getExit().getIndex()).getClosePrice();
              Decimal entryClosePrice = series.getTick(trade.getEntry().getIndex()).getClosePrice();
  
              if (trade.getEntry().isBuy()) {
                  profit = exitClosePrice.dividedBy(entryClosePrice);
              } else {
                  profit = entryClosePrice.dividedBy(exitClosePrice);
              }
          }
          return profit.toDouble();
      }
docs: Calculates the profit of a trade (Buy and sell).
  @param series a time series
  @param trade a trade
  @return the profit of the trade