code: @Override
      protected Decimal calculate(int index) {
          if (stopLossLimit.isNaN()) {
              // Case without initial stop-loss limit value
              stopLossLimit = indicator.getValue(0).minus(stopLossDistance);
          }
          Decimal currentValue = indicator.getValue(index);
          Decimal referenceValue = stopLossLimit.plus(stopLossDistance);
          
          if (currentValue.isGreaterThan(referenceValue)) {
              stopLossLimit = currentValue.minus(stopLossDistance);
          }
          return stopLossLimit;
      }
docs: Simple implementation of the trailing stop-loss concept.
  Logic:
  IF CurrentPrice - StopLossDistance > StopLossLimit THEN StopLossLimit = CurrentPrice - StopLossDistance
  @param index
  @return Decimal