OPEN-SOURCE SCRIPT

使用 DI+ 和 DI- 的策略 (最終完整修正且含圖表止損止盈線)

策略名稱: 基於 DI+ 和 DI- 的趨勢追蹤策略 (附 ATR 止損止盈) / DI+ and DI- Trend Following Strategy with ATR Stop Loss and Take Profit

策略描述 (中文):

本策略基於趨向指標 (Directional Movement Index, DMI) 中的 DI+ 和 DI- 指標,結合趨勢過濾均線和 ATR (Average True Range) 指標來判斷市場趨勢和設定動態的止損止盈。DMI 旨在衡量價格變動的方向和強度。

DI+ (正趨向指標): 衡量向上趨勢的強度。
DI- (負趨向指標): 衡量向下趨勢的強度。
當 DI+ 高於 DI- 且收盤價高於趨勢過濾均線時,視為強勢上漲趨勢,產生買入訊號;反之,當 DI- 高於 DI+ 且收盤價低於趨勢過濾均線時,視為強勢下跌趨勢,產生賣出訊號。

本策略使用 ATR 指標來計算動態的止損和止盈水平,使止損止盈的距離能根據市場的波動性進行調整,提高策略的適應性。

策略描述 (英文):

This strategy is based on the Directional Movement Index (DMI), specifically the DI+ and DI- indicators, combined with a trend-filtering moving average and the Average True Range (ATR) to identify market trends and set dynamic stop-loss and take-profit levels. The DMI is designed to measure the direction and strength of price movements.

DI+ (Positive Directional Indicator): Measures the strength of upward trends.
DI- (Negative Directional Indicator): Measures the strength of downward trends.
When DI+ is above DI- and the closing price is above the trend-filtering moving average, it is considered a strong uptrend, generating a buy signal. Conversely, when DI- is above DI+ and the closing price is below the trend-filtering moving average, it is considered a strong downtrend, generating a sell signal.

This strategy uses the ATR indicator to calculate dynamic stop-loss and take-profit levels, allowing the stop-loss and take-profit distances to adjust to market volatility, improving the strategy's adaptability.

策略參數 (中英文對照):

DI 長度 (DI Length): 計算 DI+ 和 DI- 的週期長度。 (預設值: 14) / The period length for calculating DI+ and DI-. (Default: 14)
ADX 平滑 (ADX Smoothing): 用於平滑 ADX 的週期長度 (即使不直接使用 ADX,此參數也是必需的)。 (預設值: 14) / The period length used for smoothing the ADX (this parameter is required even if ADX is not used directly). (Default: 14)
趨勢過濾均線長度 (Trend Filter Moving Average Length): 計算趨勢過濾均線的週期長度。 (預設值: 20) / The period length for calculating the trend-filtering moving average. (Default: 20)
趨勢強度門檻值 (Trend Strength Threshold): DI+ 和 DI- 之間差距的門檻值,用於判斷趨勢是否足夠強勁。 (預設值: 20) / The threshold for the difference between DI+ and DI-, used to determine if the trend is strong enough. (Default: 20)
ATR 長度 (ATR Length): 計算 ATR 的週期長度。 (預設值: 14) / The period length for calculating the ATR. (Default: 14)
ATR 停損倍數 (ATR Stop Loss Multiplier): 止損價格與進場價格之間以 ATR 的倍數表示的距離。 (預設值: 1.5) / The distance between the stop-loss price and the entry price, expressed as a multiple of the ATR. (Default: 1.5)
ATR 止盈倍數 (ATR Take Profit Multiplier): 止盈價格與進場價格之間以 ATR 的倍數表示的距離。 (預設值: 2.5) / The distance between the take-profit price and the entry price, expressed as a multiple of the ATR. (Default: 2.5)
策略用法 (中文):

在 TradingView 上開啟一個圖表。
開啟 Pine Script 編輯器。
複製並貼上提供的程式碼。
點擊「新增到圖表」。
在策略設定中,根據您的需求調整參數。
使用回測功能測試不同參數組合的表現。
策略用法 (英文):

Open a chart on TradingView.
Open the Pine Script editor.
Copy and paste the provided code.
Click "Add to Chart".
In the strategy settings, adjust the parameters according to your needs.
Use the backtesting feature to test the performance of different parameter combinations.
訊號判斷 (中英文對照):

買入訊號 (Long Entry Signal): DI+ > DI- + 趨勢強度門檻值 且 收盤價 > 趨勢過濾均線 / DI+ > DI- + Trend Strength Threshold AND Close > Trend Filter Moving Average
賣出訊號 (Short Entry Signal): DI- > DI+ + 趨勢強度門檻值 且 收盤價 < 趨勢過濾均線 / DI- > DI+ + Trend Strength Threshold AND Close < Trend Filter Moving Average
止損止盈計算 (中英文對照):

多單停損 (Long Stop Loss): 進場價格 - (ATR * ATR 停損倍數) / Entry Price - (ATR * ATR Stop Loss Multiplier)
多單止盈 (Long Take Profit): 進場價格 + (ATR * ATR 止盈倍數) / Entry Price + (ATR * ATR Take Profit Multiplier)
空單停損 (Short Stop Loss): 進場價格 + (ATR * ATR 停損倍數) / Entry Price + (ATR * ATR Stop Loss Multiplier)
空單止盈 (Short Take Profit): 進場價格 - (ATR * ATR 止盈倍數) / Entry Price - (ATR * ATR Take Profit Multiplier)
注意事項 (中英文對照):

回測結果僅供參考,不代表未來績效。 / Backtesting results are for reference only and do not guarantee future performance.
策略參數需要根據不同的市場和時間週期進行調整。 / Strategy parameters need to be adjusted according to different markets and timeframes.
此策略不適用於所有市場環境。 / This strategy is not suitable for all market conditions.
請謹慎使用,並自行承擔交易風險。 / Please use with caution and at your own risk.
Bands and ChannelsCandlestick analysisTrend Analysis

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?

Pernyataan Penyangkalan