策略
基于ADX指标的趋势反转策略Trend-Reversal-Strategy-Based-on-ADX-Indicator
ChaoZhang · PineScript · 趋势跟踪 · 2023-09-13 17:02:31
概述
本策略名称为“基于ADX指标的趋势反转策略”。该策略利用ADX指标判断趋势强度,在超买超卖时捕捉反转机会。 ADX表示平均趋向指数,反映趋势的力度。ADX值越高,表明趋势越强。当ADX大于25时,认为存在较明显趋势。 DMI包括DI+和DI-两线。DI+在上时表示上涨趋势,DI-在上时表示下跌趋势。 本策略的交易逻辑:
- 当ADX高于45,认为趋势非常强劲。
- 此时若DI+低于DI-,则判断为超卖状态,出现趋势反转机会,做多。
- 反之,若DI-低于DI+,则判断为超买状态,出现反转机会,做空。
- 在反转后及时止盈。
该策略的优势是使用ADX判断强势趋势的反转点,高ADX值可以有效过滤震荡市场的假信号。但ADX参数需要优化,且止损策略也很重要。 总体来说,ADX指标较好地判定强势趋势反转的时机。但交易者仍需关注更多因素,ADX仅作为辅助判断指标之一。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_1 | true | From Month |
| v_input_2 | true | From Day |
| v_input_3 | 2021 | From Year |
| v_input_4 | true | Thru Month |
| v_input_5 | true | Thru Day |
| v_input_6 | 2112 | Thru Year |
| v_input_7 | true | Show Date Range |
源码(32 行)
/*backtest
start: 2023-08-13 00:00:00
end: 2023-09-12 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(shorttitle='DMI swings',title='DMI swings', overlay=true, initial_capital = 100, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.1)
//Backtest dates
fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
fromYear = input(defval = 2021, title = "From Year", type = input.integer, minval = 1970)
thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
showDate = input(defval = true, title = "Show Date Range", type = input.bool)
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => true // create function "within window of time"
[pos_dm, neg_dm, avg_dm] = dmi(14, 14)
//Entry
strategy.entry(id="long", long = true, when = avg_dm > 45 and pos_dm < neg_dm and window())
//Exit
strategy.close("long", when = avg_dm > 45 and pos_dm > neg_dm and window())