code: private boolean rule4(Double sample) {
          if (null == rule4PreviousSample || sample.doubleValue() == rule4PreviousSample.doubleValue()) {
              rule4PreviousSample = sample;
              rule4PreviousDirection = "=";
              rule4Count = 0;
              return false;
          }
  
          String sampleDirection = (sample > rule4PreviousSample) ? ">" : "<";
  
          if (sampleDirection.equals(rule4PreviousDirection)) {
              rule4Count = 0;
          } else {
              ++rule4Count;
          }
  
          rule4PreviousSample = sample;
          rule4PreviousDirection = sampleDirection;
  
          return Math.abs(rule4Count) >= 14;
      }
docs: Fourteen (or more) points in a row alternate in direction, increasing then decreasing