From 5a53a21e97311d239f57266d58d2d7b6f55c42a6 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 25 Dec 2025 15:20:24 +0800
Subject: [PATCH] feat(indicator): 更新技术指标基础类和MACD实现
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/indicator/MACDTest.java | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/indicator/MACDTest.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/indicator/MACDTest.java
new file mode 100644
index 0000000..ec93614
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/indicator/MACDTest.java
@@ -0,0 +1,118 @@
+package com.xcong.excoin.modules.okxNewPrice.indicator;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * MACD Indicator Test Class
+ * Used to verify the correctness of MACD calculation logic
+ */
+public class MACDTest {
+
+ public static void main(String[] args) {
+ // Create MACD instance
+ MACD macd = new MACD();
+
+ // Set MACD bars parameters (optional, using default values here)
+ macd.setMacdBarsMultiplier(2); // Default multiplier
+ macd.setMacdBarsSmoothingPeriod(0); // No smoothing
+
+ // Generate test price data (simple upward trend)
+ List<BigDecimal> prices = generateTestPrices(30);
+
+ System.out.println("=== MACD Indicator Test Start ===");
+ System.out.println("Price count: " + prices.size());
+ System.out.println("MACD parameters: fast=" + macd.getFastPeriod() + ", slow=" + macd.getSlowPeriod() + ", signal=" + macd.getSignalPeriod());
+ System.out.println("MACD bars parameters: multiplier=" + macd.getMacdBarsMultiplier() + ", smoothing=" + macd.getMacdBarsSmoothingPeriod());
+ System.out.println();
+
+ // Calculate MACD
+ macd.calculate(prices);
+
+ // Output results
+ System.out.println("=== MACD Calculation Results ===");
+ System.out.println("DIF: " + macd.getDif());
+ System.out.println("DEA: " + macd.getDea());
+ System.out.println("MACD Bars: " + macd.getMacdBar());
+ System.out.println();
+
+ // Trend judgment
+ System.out.println("=== Trend Judgment ===");
+ if (macd.getDif().compareTo(BigDecimal.ZERO) > 0) {
+ System.out.println("DIFF > 0: Bullish trend");
+ } else if (macd.getDif().compareTo(BigDecimal.ZERO) < 0) {
+ System.out.println("DIFF < 0: Bearish trend");
+ } else {
+ System.out.println("DIFF = 0: No trend");
+ }
+
+ // Test smoothing function
+ testSmoothingFunction();
+
+ System.out.println("=== MACD Indicator Test End ===");
+ }
+
+ /**
+ * Generate test price data
+ * @param count Number of data points
+ * @return Price list
+ */
+ private static List<BigDecimal> generateTestPrices(int count) {
+ List<BigDecimal> prices = new ArrayList<>();
+ // Start from 100, simple upward trend with some random fluctuations
+ BigDecimal basePrice = new BigDecimal(100);
+ for (int i = 0; i < count; i++) {
+ // Add random fluctuation between 0.1 and 0.5
+ BigDecimal price = basePrice.add(new BigDecimal(Math.random() * 0.4 + 0.1));
+ prices.add(price.setScale(2, BigDecimal.ROUND_HALF_UP));
+ basePrice = price;
+ }
+ return prices;
+ }
+
+ /**
+ * Test MACD bars smoothing function
+ */
+ private static void testSmoothingFunction() {
+ System.out.println("=== MACD Bars Smoothing Function Test ===");
+
+ MACD macd = new MACD();
+ macd.setMacdBarsMultiplier(2);
+ macd.setMacdBarsSmoothingPeriod(3); // 3-day smoothing
+
+ // Generate test price data with more fluctuations
+ List<BigDecimal> prices = generateVolatileTestPrices(30);
+
+ macd.calculate(prices);
+
+ System.out.println("Price count: " + prices.size());
+ System.out.println("MACD parameters: fast=" + macd.getFastPeriod() + ", slow=" + macd.getSlowPeriod() + ", signal=" + macd.getSignalPeriod());
+ System.out.println("MACD bars parameters: multiplier=" + macd.getMacdBarsMultiplier() + ", smoothing=" + macd.getMacdBarsSmoothingPeriod());
+ System.out.println();
+
+ System.out.println("Smoothed MACD Results:");
+ System.out.println("DIF: " + macd.getDif());
+ System.out.println("DEA: " + macd.getDea());
+ System.out.println("MACD Bars: " + macd.getMacdBar());
+ System.out.println();
+ }
+
+ /**
+ * Generate test price data with more fluctuations
+ * @param count Number of data points
+ * @return Price list
+ */
+ private static List<BigDecimal> generateVolatileTestPrices(int count) {
+ List<BigDecimal> prices = new ArrayList<>();
+ // Start from 100 with more random fluctuations
+ BigDecimal basePrice = new BigDecimal(100);
+ for (int i = 0; i < count; i++) {
+ // Add random fluctuation between -1.0 and 1.0
+ BigDecimal price = basePrice.add(new BigDecimal(Math.random() * 2 - 1));
+ prices.add(price.setScale(2, BigDecimal.ROUND_HALF_UP));
+ basePrice = price;
+ }
+ return prices;
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.1