Build a Go-Powered Daily Stock Screener: Auto‑Run, CSV Output & Web Visualization

This article guides you through creating a Go-based quantitative stock‑screening system that automatically runs each afternoon, processes over a thousand stocks, selects those staying above the 20‑day moving average for three consecutive days, and presents results via CSV files and a web dashboard.

Code Wrench
Code Wrench
Code Wrench
Build a Go-Powered Daily Stock Screener: Auto‑Run, CSV Output & Web Visualization

Why Choose Go for Quantitative Analysis?

Quantitative investing deals with massive data and high concurrency, demanding top performance. Go offers high concurrency with goroutine support for tens of thousands of simultaneous tasks, near‑C execution speed, and concise, maintainable code, making it ideal for long‑term extensions.

System Architecture

Stock Screener System
├── Data Acquisition Layer (API / Simulated Market Data)
├── Indicator Calculation Layer (MA and other technical indicators)
├── Concurrent Analysis Layer (goroutine pool)
└── Output & Visualization Layer (CSV + Web UI)

Core Functions

1. Technical Indicator Calculation (20‑Day Moving Average)

func CalculateMA(klines []KLineData, period int) float64 {
    if len(klines) < period { return 0 }
    sum := 0.0
    for i := len(klines)-period; i < len(klines); i++ {
        sum += klines[i].Close
    }
    return sum / float64(period)
}

2. Detecting Three Consecutive Days Above MA20

func IsAboveMA20(klines []KLineData) bool {
    if len(klines) < 23 { return false }
    for i := len(klines)-3; i < len(klines); i++ {
        ma20 := CalculateMA(klines[:i+1], 20)
        if klines[i].Close < ma20 { return false }
    }
    return true
}

3. Daily Scheduled Task (Runs Automatically at 15:00)

func ScheduleDailyTask(file, resultDir string, hour, minute int) {
    for {
        now := time.Now()
        nextRun := time.Date(now.Year(), now.Month(), now.Day(), hour, minute, 0, 0, now.Location())
        if now.After(nextRun) { nextRun = nextRun.Add(24 * time.Hour) }
        time.Sleep(nextRun.Sub(now))
        RunAnalysis(file, resultDir)
    }
}

4. Web Visualization

Backend provides an /api/stocks endpoint returning the selected symbols.

Frontend uses ECharts to plot closing prices together with the 20‑day moving average.

Open http://localhost:8080 in a browser to view the results.

Performance Optimizations

Adjust worker count: use number of CPU cores for CPU‑bound tasks, and twice the core count for I/O‑bound workloads.

Employ buffered channels to reduce blocking.

Utilize an HTTP connection pool to improve network efficiency.

Future Extensions

Persist data to MySQL or MongoDB.

Add real‑time push notifications via WebSocket.

Implement additional technical‑analysis strategies for entry/exit signals.

Introduce back‑testing to validate strategy performance.

Enhance visualizations with Grafana or TradingView‑style dashboards.

Conclusion

The project delivers a complete Go‑based daily automated stock‑screening system that runs without manual intervention, handles 1000+ symbols concurrently, offers clean and extensible code, and visualizes results on a web page.

Source Code

Full source code is open‑source on GitHub:

https://github.com/louis-xie-programmer/go-stock-analyzer

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

web-visualizationstock-analysis
Code Wrench
Written by

Code Wrench

Focuses on code debugging, performance optimization, and real-world engineering, sharing efficient development tips and pitfall guides. We break down technical challenges in a down-to-earth style, helping you craft handy tools so every line of code becomes a problem‑solving weapon. 🔧💻

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.