PROTECTED SOURCE SCRIPT
Futures Trading Strategy (Converted)

此腳本是一個期貨交易策略,結合多項技術指標以生成交易訊號,並以嚴謹的風險管理控制進場部位。策略主要針對趨勢強弱與盤整的市場狀態進行判斷,藉此過濾假訊號,並透過連續訊號確認機制提高進出場決策的可靠性。
技術指標與參數說明
風險管理
使用者可調設定每次交易風險百分比(預設 1%),並利用 ATR(平均真實區間)作為市場波動的衡量依據,依據當前賬戶權益計算出合理的進場部位大小。
盤中波動與趨勢判斷
ATR 與 Volatility Factor:腳本先利用指定參數計算 ATR,進而與 50 期簡單移動平均比較,得出一個反映當前市場波動強弱的因子。
ADX 的自訂計算:透過計算正向與反向動向(plusDM 與 minusDM)及進行 RMA 平滑處理,最終生成 ADX 值,用以衡量市場趨勢強度。
HMA 及斜率:利用 Hull 移動平均(HMA)及其基於線性回歸的斜率變化,捕捉趨勢轉向的訊號。
VHF(縱橫比濾波器):計算指定期數內價格的區間與價格變動的比率,協助辨識市場是否處於盤整狀態。
交易訊號生成與過濾
原始訊號:檢查價格與 HMA 的穿越狀態,當前一根 K 線由 HMA 下方穿越至上方則產生看多訊號,反之則看空。
Gap 訊號:藉由收盤價與 HMA 間差距的變化提出判斷,分析價格動能是否存在過熱或回調現象。
快速轉向訊號:利用 HMA 斜率由負轉正或由正轉負的急速變化,捕捉趨勢轉折。
Pivot 訊號:運用內建的 pivotlow 與 pivothigh 函式,確認轉折點。
為避免盤整時段產生誤判,當 VHF 低於設定水平且 ADX(經過波動率調整後的門檻)不足時,將進一步屏蔽交易訊號。
訊號確認機制
為降低過度交易與假訊號的風險,策略要求相同方向的信號需連續達到設定的確認棒數(confirmationBars)後,才視為最終的進場訊號。
下單與視覺化
當最終確認的多頭或空頭訊號出現,且倉位狀態允許,腳本即以計算出的合理單位尺寸發起對應方向的進場單。
同時,在圖表上繪製 HMA 曲線以及隱藏式計算的 ATR、ADX 與 VHF 指標,並以圖形標注方式分別展示買入與賣出訊號。
風險提示 本腳本僅供學習與策略回測參考,歷史效能並不代表未來表現。請根據自身風險承受能力審慎評估後使用,交易存在資金損失風險。
This script is a futures trading strategy that integrates multiple technical indicators to generate trade signals while employing rigorous risk management for position sizing. The strategy primarily evaluates market conditions based on trend strength and consolidation to filter out false signals and uses a consecutive signal confirmation mechanism to improve entry and exit decisions.
Technical Indicators and Parameter Details
Risk Management
The user can adjust the risk percentage per trade (defaulting to 1%).
The strategy uses the Average True Range (ATR) as a measure of market volatility to determine an appropriate trade size based on the current account equity.
Intraday Volatility and Trend Assessment
ATR and Volatility Factor: The script calculates the ATR using specified parameters and then compares it with a 50-period simple moving average (SMA) to derive a factor that reflects the current market volatility.
Custom ADX Calculation: By computing the positive and negative directional movements (plusDM and minusDM) and applying a smoothed RMA, the strategy generates the ADX to assess market trend strength.
HMA and Slope: The Hull Moving Average (HMA) is used along with its linear regression-based slope variation to capture potential trend reversals.
VHF (Vertical Horizontal Filter): The ratio of the price range over a specified period to the sum of price changes is calculated, assisting in identifying whether the market is in a state of consolidation.
Trading Signal Generation and Filtering
Raw Signal: Evaluates the crossover of price and HMA. A bullish signal is generated when the previous bar closes below the HMA and the current bar closes above the HMA; the converse applies for a bearish signal.
Gap Signal: Analyzes the difference between the closing price and the HMA, examining whether the momentum indicates an overheat or retracement in prices.
Rapid Reversal Signal: Detects sudden shifts in the HMA slope (from negative to positive or vice versa) to signal potential trend reversals.
Pivot Signal: Uses the built-in pivot low and pivot high functions to confirm turning points in the market.
To prevent false signals during consolidating periods, the strategy disables trading signals when the VHF is below the set threshold and the ADX (adjusted by the volatility factor) is insufficient.
Signal Confirmation Mechanism To reduce overtrading and false entries, the script requires that a signal in the same direction persists for a user-defined number of consecutive bars (confirmationBars) before it is considered a valid trading signal.
Order Execution and Visualization
When a confirmed bullish or bearish signal is detected and the current position status allows, the script places an entry order using the calculated position size based on risk management rules.
The HMA is plotted on the chart, and while ATR, ADX, and VHF calculations remain hidden, the script marks buy and sell signals graphically for easy visualization.
Risk Disclaimer This script is provided for educational and backtesting purposes only. Past performance is not indicative of future results. Please assess your risk tolerance and use the strategy with caution, as trading involves the risk of capital loss.
技術指標與參數說明
風險管理
使用者可調設定每次交易風險百分比(預設 1%),並利用 ATR(平均真實區間)作為市場波動的衡量依據,依據當前賬戶權益計算出合理的進場部位大小。
盤中波動與趨勢判斷
ATR 與 Volatility Factor:腳本先利用指定參數計算 ATR,進而與 50 期簡單移動平均比較,得出一個反映當前市場波動強弱的因子。
ADX 的自訂計算:透過計算正向與反向動向(plusDM 與 minusDM)及進行 RMA 平滑處理,最終生成 ADX 值,用以衡量市場趨勢強度。
HMA 及斜率:利用 Hull 移動平均(HMA)及其基於線性回歸的斜率變化,捕捉趨勢轉向的訊號。
VHF(縱橫比濾波器):計算指定期數內價格的區間與價格變動的比率,協助辨識市場是否處於盤整狀態。
交易訊號生成與過濾
原始訊號:檢查價格與 HMA 的穿越狀態,當前一根 K 線由 HMA 下方穿越至上方則產生看多訊號,反之則看空。
Gap 訊號:藉由收盤價與 HMA 間差距的變化提出判斷,分析價格動能是否存在過熱或回調現象。
快速轉向訊號:利用 HMA 斜率由負轉正或由正轉負的急速變化,捕捉趨勢轉折。
Pivot 訊號:運用內建的 pivotlow 與 pivothigh 函式,確認轉折點。
為避免盤整時段產生誤判,當 VHF 低於設定水平且 ADX(經過波動率調整後的門檻)不足時,將進一步屏蔽交易訊號。
訊號確認機制
為降低過度交易與假訊號的風險,策略要求相同方向的信號需連續達到設定的確認棒數(confirmationBars)後,才視為最終的進場訊號。
下單與視覺化
當最終確認的多頭或空頭訊號出現,且倉位狀態允許,腳本即以計算出的合理單位尺寸發起對應方向的進場單。
同時,在圖表上繪製 HMA 曲線以及隱藏式計算的 ATR、ADX 與 VHF 指標,並以圖形標注方式分別展示買入與賣出訊號。
風險提示 本腳本僅供學習與策略回測參考,歷史效能並不代表未來表現。請根據自身風險承受能力審慎評估後使用,交易存在資金損失風險。
This script is a futures trading strategy that integrates multiple technical indicators to generate trade signals while employing rigorous risk management for position sizing. The strategy primarily evaluates market conditions based on trend strength and consolidation to filter out false signals and uses a consecutive signal confirmation mechanism to improve entry and exit decisions.
Technical Indicators and Parameter Details
Risk Management
The user can adjust the risk percentage per trade (defaulting to 1%).
The strategy uses the Average True Range (ATR) as a measure of market volatility to determine an appropriate trade size based on the current account equity.
Intraday Volatility and Trend Assessment
ATR and Volatility Factor: The script calculates the ATR using specified parameters and then compares it with a 50-period simple moving average (SMA) to derive a factor that reflects the current market volatility.
Custom ADX Calculation: By computing the positive and negative directional movements (plusDM and minusDM) and applying a smoothed RMA, the strategy generates the ADX to assess market trend strength.
HMA and Slope: The Hull Moving Average (HMA) is used along with its linear regression-based slope variation to capture potential trend reversals.
VHF (Vertical Horizontal Filter): The ratio of the price range over a specified period to the sum of price changes is calculated, assisting in identifying whether the market is in a state of consolidation.
Trading Signal Generation and Filtering
Raw Signal: Evaluates the crossover of price and HMA. A bullish signal is generated when the previous bar closes below the HMA and the current bar closes above the HMA; the converse applies for a bearish signal.
Gap Signal: Analyzes the difference between the closing price and the HMA, examining whether the momentum indicates an overheat or retracement in prices.
Rapid Reversal Signal: Detects sudden shifts in the HMA slope (from negative to positive or vice versa) to signal potential trend reversals.
Pivot Signal: Uses the built-in pivot low and pivot high functions to confirm turning points in the market.
To prevent false signals during consolidating periods, the strategy disables trading signals when the VHF is below the set threshold and the ADX (adjusted by the volatility factor) is insufficient.
Signal Confirmation Mechanism To reduce overtrading and false entries, the script requires that a signal in the same direction persists for a user-defined number of consecutive bars (confirmationBars) before it is considered a valid trading signal.
Order Execution and Visualization
When a confirmed bullish or bearish signal is detected and the current position status allows, the script places an entry order using the calculated position size based on risk management rules.
The HMA is plotted on the chart, and while ATR, ADX, and VHF calculations remain hidden, the script marks buy and sell signals graphically for easy visualization.
Risk Disclaimer This script is provided for educational and backtesting purposes only. Past performance is not indicative of future results. Please assess your risk tolerance and use the strategy with caution, as trading involves the risk of capital loss.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.