Skip to content

amytsengtw/txf-adaptive-scalper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

[AMY] Adaptive Volatility Scalper (TXF Optimized)

[AMY] 台指期動態波動率極速策略

Version Platform License

📖 Overview (專案概述)

[AMY] Adaptive Volatility Scalper is a quantitative trading strategy designed specifically for Taiwan Index Futures (TXF) intraday trading. It addresses the "Rigid Target Problem" found in traditional fixed-point strategies by integrating Average True Range (ATR) volatility modeling.

本專案是一個專為 台指期 (TXF) 當沖交易設計的量化策略。它解決了傳統策略中「固定停利點數」過於僵化的問題,透過引入 ATR (真實波動幅度均值) 波動率模型,實現動態風控。

The system dynamically adjusts Profit Targets (TP) and Stop Losses (SL) based on real-time market conditions, ensuring the strategy captures maximum alpha during high-volatility expansion while preserving capital during low-volatility consolidation.

系統會根據即時的市場波動,自動調整「停利點 (TP)」與「停損點 (SL)」。在波動放大時自動拉大獲利目標,在盤整時自動縮小防守區間,以達到期望值最大化。


🧠 Core Algorithms & Methodology (核心演算法)

The strategy operates on a three-layer architecture to ensure high signal-to-noise ratio (SNR) and robust risk management. 本策略基於三層架構運作,以確保高訊噪比 (SNR) 與穩健的風險管理。

1. Signal Generation: Low-Latency HMA (訊號生成層)

We utilize the Hull Moving Average (HMA) to minimize the lag inherent in traditional moving averages (SMA/EMA). 我們使用 赫爾均線 (HMA) 來消除傳統均線的滯後性。

  • Fast HMA (12): Reacts immediately to price action. (反應價格的快速變化)
  • Slow HMA (50): Establishes the immediate baseline. (確立短線基準)
  • Logic: Entry signals are generated on Crossover (Bullish) or Crossunder (Bearish). (金叉做多,死叉做空)

2. Regime Filtering: Trend Baseline (趨勢濾網層)

To mitigate counter-trend risks, a 200-period Exponential Moving Average (EMA) serves as the global trend filter. 為了避免逆勢接刀的風險,使用 200 EMA 作為全域趨勢濾網。

  • Long Rule (做多規則): Allowed only when $Price > EMA_{200}$
  • Short Rule (做空規則): Allowed only when $Price < EMA_{200}$
  • Note: This filter can be toggled OFF in settings. (此濾網可在設定中關閉)

3. Risk Management: ATR Adaptive Targeting (動態風控層)

This is the core innovation. Targets are calculated dynamically rather than using static points. 這是本策略的核心創新,停利停損點位皆為動態計算。

Formula (計算公式)

$$ Target_{Dynamic} = Entry_{Price} \pm (ATR_{14} \times Multiplier_{TP}) $$

Logic Flow (邏輯流程)

  1. Calculate ATR: Measure the volatility of the last 14 periods. (計算過去14根K棒的波動率)
  2. Apply Multiplier: Default is 1.2x for TP and 0.8x for SL. (套用倍數:停利 1.2倍 / 停損 0.8倍)
  3. Boundary Check (邊界檢查):
    • Min Limit: Ensures the target covers transaction fees. (確保利潤覆蓋手續費)
    • Max Limit: Caps the target to ensure realistic execution. (設定上限以確保能成交)

⚙️ Features (功能特點)

Strict State Machine (嚴格狀態機)

The script implements a finite state machine (pos variable: 0, 1, -1) to manage trade lifecycle.

  • Benefit: Prevents repainting and ensures signals do not duplicate within the same trade cycle.
  • 優勢: 防止訊號重繪 (Repaint),並確保同一筆交易週期內不會出現重複訊號。

"All-in-One" Alerting System (一鍵警報系統)

Designed for automation efficiency. The script uses the alert() function to aggregate all events.

  • Setup: Select "Any alert() call" in TradingView.
  • Payload: Sends distinct messages for Buy, Sell, Take Profit, and Stop Loss.
  • 優勢: 支援 TradingView 的 alert() 函數。只需設定一次「Any alert() call」,即可同時接收進場、獲利、停損的所有通知。

Real-Time Dashboard (即時資訊面板)

A data panel in the bottom-right corner visualizes the "Black Box" calculations:

  • Current ATR Value & Suggested Dynamic Target.
  • Current Position & Trend Status.
  • 功能: 右下角面板即時顯示 ATR 數值、動態計算的目標點數以及目前持倉狀態。

🛠 Configuration Parameters (參數設定指南)

Parameter (參數) Default (預設) Description (說明)
HMA Fast Length 12 Signal sensitivity. Lower = Faster. (快線長度,越小越靈敏)
HMA Slow Length 50 Baseline stability. (慢線長度,趨勢基準)
EMA Filter 200 / ON Global trend filter. Can be toggled. (大趨勢濾網,可開關)
TP Multiplier 1.2 Multiplier for ATR to set Profit Target. (停利 ATR 倍數)
SL Multiplier 0.8 Multiplier for ATR to set Stop Loss. (停損 ATR 倍數)
Min TP Points 20 Minimum points to aim for. (最小獲利點數限制)
Max TP Points 60 Maximum points to cap greed. (最大獲利點數限制)

🚀 Installation & Usage (安裝與使用)

  1. Copy Code: Copy the .pine source code from the src folder. (複製原始碼)
  2. Pine Editor: Open TradingView -> Pine Editor -> Paste the code. (打開 TradingView Pine 編輯器貼上代碼)
  3. Add to Chart: Click "Add to chart". (點擊加入圖表)
  4. Timeframe: Optimized for 5-minute (5m) charts on TXF. (建議週期:台指期 5分K)

Visual Guide (視覺說明)

  • 🟡 Yellow Line: Fast HMA (快線)
  • White Line: 200 EMA Trend Filter (趨勢濾網)
  • 🔵 Blue Line: Dynamic Profit Target (獲利線 - 持倉時顯示)
  • 🟣 Purple Line: Dynamic Stop Loss (停損線 - 持倉時顯示)
  • 💎 Diamond Icon: Profit Target Hit (獲利達成圖示)

⚠️ Disclaimer (免責聲明)

This project is for quantitative research and educational purposes only.

  • Past performance does not guarantee future results.
  • Trading futures involves substantial risk of loss and is not suitable for every investor.
  • Please perform your own backtesting and paper trading before deploying real capital.

本專案僅供量化研究與教學用途。

  • 過去績效不代表未來獲利保證。
  • 期貨交易具有高風險,請務必在投入真倉前進行完整的回測與模擬交易。

Created by AMY

About

Quantitative trading strategy for Taiwan Index Futures (TXF) utilizing Hull Moving Average (HMA) and ATR-based dynamic risk management.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors