HQChart Financial Charting Library

repository·master·Indexed 23 days ago

https://github.com/jones2000/hqchart

A high-performance financial charting library and indicator calculation engine supporting K-line charts and Analyst Syntax (麦语法). It is compatible with JavaScript, Vue 2.0/3.0, uniapp, and Mini Programs (WeChat, DingTalk). Features include over 80 built-in indicators, drawing tools, order flow visualization, and support for stocks, futures, cryptocurrency, and forex across web and mobile platforms.

Tokens
30.3K
Snippets
27
Records
190
Agent score
86%

What's inside HQChart

  1. Overview of HQChart

    master

    HQChart is a financial charting library and indicator execution engine ported from traditional C++ desktop stock clients to JS/Python platforms. It includes a K-line chart graphics library and a 麦语法 (Analyst Syntax) indicator executor.

    Supported Platforms:

    • JavaScript
    • Vue 2.0 / Vue 3.0
    • uniapp
    • Mini Programs (WeChat, etc.)

    Supported Asset Types:

    • Stocks, Futures, Cryptocurrency, Forex, and other K-line related instruments.

    Indicator Engine:

    • The 麦语法 (Analyst Syntax) engine supports JS, Node.js, Python, C#, and C++.
    • Supports calculation in frontend worker threads.
  2. K-Line (Candlestick) Chart Features

    master

    HQChart provides a comprehensive K-Line charting engine with the following capabilities:

    • Data Support: Supports forward and backward adjustment (复权), multiple timeframes (daily, weekly, monthly, yearly, minute), and stock overlays.
    • Visual Styles: Supports various candlestick shapes including hollow, solid, American (US), and close-price lines. Also supports area charts, Renko charts, Line Break charts, and candlestick color customization.
    • Indicators: Includes over 80 built-in indicators (e.g., MA, BOLL, MACD, KDJ, VOL, RSI, OBV, etc.) and supports custom indicators using TongdaXing (通达信) syntax.
    • Drawing Tools: Includes lines (segments, rays, trend, parallel, etc.), shapes (rectangles, circles, triangles), and annotations (text, icons). Drawings can be saved locally or in memory.
    • Interactivity: Supports mouse dragging for movement, keyboard controls for crosshair and zooming, Y-axis dragging for scaling, and indicator tab buttons.
    • Advanced Analysis: Supports interval statistics, pattern matching, order flow visualization, volume profiles (fixed and visible range), and chip distribution (筹码图).
    • Backtesting: Supports front-end backtesting for single indicators/stocks, calculating metrics like Trade Count, Success/Fail rates, Profit, Max Drawdown, and Beta coefficient.
  3. Trend (Minute) Chart Features

    master

    The Trend chart engine is optimized for intraday and high-frequency data:

    • Data Support: Supports minute-level data, multi-day minute data, and various markets including Shanghai/Shenzhen, Hong Kong stocks, and domestic futures.
    • Visual Features: Supports stock overlays, A-share call auction (集合竞价) display/hide, and index leading indicators.
    • Market Specifics: Supports US market pre-market, intraday, and post-market sessions.
    • Interactivity: Supports multi-stock synchronized crosshair movement and predictive lines.
  4. Use VUE HQChart generic components

    master

    The vuehqchart package provides several independent Vue components for financial market data visualization. Each component can be used individually depending on your requirements:

    • searchsymbol.vue: A stock code search component with an autocomplete/suggestion dropdown.
    • stockinfo: Displays individual stock information, including price, percentage change, etc.
    • stocktradeinfo: Displays market depth (bid/ask), tick data (transaction history), and market activity/anomalies.
    • stockkline.demo: Displays trend charts and K-line (candlestick) charts.
    • stockfull: A comprehensive component that integrates the full individual stock market data view.
  5. Other Financial Data Visualizations

    master

    Beyond K-lines and trend charts, HQChart supports several specialized financial UI components:

    • Quote Lists (报价列表): A high-performance virtual table built on canvas. Features include fixed columns, keyboard navigation (PageUP/Down, Up/Down, Left/Right), tab switching, column reordering/resizing, and floating K-line/trend windows.
    • T-Type Quotes (T型报价): Specialized layout for options or specific trading views.
    • Order Flow (订单流): Multiple styles of order flow visualization.
    • Data Tables: Supports transaction details (成交明细表), price lists (分价表), big data tables, and bulk trade (大宗交易) views.
    • Specialty Charts: Depth charts, OX charts, OrderBook Heatmaps, and Scatterplot indicators.
  6. Access HQChart demo examples

    master

    The demo/ directory contains various HTML examples for different chart types and mobile adaptations.

    Note: The built-in test data interfaces in the demo/ directory have been discontinued, so these examples will not fetch data by default. For the latest working instances, refer to the samples/ directory.

  7. Implement HQChart in uni-app

    master

    HQChart supports uni-app across multiple platforms (H5, App, and Mini Programs). Key integration topics include:

    • Using built-in HQChart components in uni-app.
    • Creating K-line charts and time-series charts for H5 and App platforms.
    • Using conditional compilation to support H5, App, and Mini Programs simultaneously.
    • Solving white-screen issues when uni-app pages are hidden and then shown.
    • Using renderjs with HQChart for H5.
    • Creating custom HQChart components for uni-app.
    • Running WeChat Mini Programs within uni-app using Vue 3.
  8. Integrate Data using NetworkFilter

    master

    Data integration is handled via the NetworkFilter callback function.

    1. Placement: NetworkFilter must be a top-level property in the option object passed to SetOption.
    2. Mechanism: External data is returned to the chart via the callback function within NetworkFilter.
    3. Data Structures: The chart parses different data structures based on the requested data name. Refer to the specific documentation for K-Line or Minute-Line data formats.
  9. Customize CodeMirror editor keywords for financial indicators

    master

    To enable syntax highlighting for financial indicator functions (like MA, EMA, CLOSE, etc.) within the editor, you must configure the editor mode to text/javascript and modify the CodeMirror JavaScript mode definition to include financial-specific keywords and styles.

    1. Configure the Editor Mode

    In your App.vue, set the editor configuration to use the JavaScript mode:

    mode: 'text/javascript'

    2. Modify the CodeMirror JavaScript Mode

    Locate the following file in your project: node_modules/codemirror/mode/javascript/javascript.js

    Replace the existing keywords() function with a custom implementation that maps financial keywords to specific styles (e.g., functionname, dataname, colorname). This allows the editor to visually distinguish between indicator functions, market data variables, and color constants.

    // Example of the custom keywords function structure to be inserted into javascript.js
    var keywords = function(){
        function kw(type) {return {type: type, style: "keyword"};}
        var FUNCTION_NAME=kw('functionname');
        var DATA_NAME={type: "dataname", style:'variable-2'};
        var LINE_WIDTH_NAME=kw('linewidth');
        var DRAW_NAME=kw("drawname");
    
        var COLORRED={type: "colorname", style:'colorred'};
        // ... other color definitions
    
        var jsKeywords = {
           "MA":FUNCTION_NAME,
           "EMA":FUNCTION_NAME,
           "CLOSE":DATA_NAME,
           "C":DATA_NAME,
           "COLORRED":COLORRED,
           // ... other financial keywords
        };
    
        return jsKeywords;
    }();
  10. Integrate third-party data for K-Line charts

    master

    Extensive documentation for connecting external data to K-line charts, covering:

    • Data Types: Daily K-line, 1-minute K-line, tick-by-tick (分笔) K-line, and market index (大盘) data.
    • Advanced Data Handling: Paged downloading for daily and 1-minute K-line data, incremental updates via polling or WebSocket, and handling circulating share capital.
    • Visuals & Indicators: Integrating indicator data, BS indicators, custom line segments/polygons, custom icons, text rendering within indicators, and custom colored K-line bars or custom columns.
    • Specialized Features: Overlaying multiple stocks, handling information announcements, cross-period function data, FINVALUE and FINANCE function data, and filling K-line background colors.
    • Advanced Rendering: Rendering DOM elements in indicators, drawing scatter plots, drawing dots, and handling specific data structures like DRAWTEXTREL, DRAWTEXTABS, and DRAWTEXT_FIX.
    • Other: Order flow (订单流), volume distribution charts, and real-time DYNAINFO data.