Estratégia de tendência de momentum ADX


Data de criação: 2024-01-16 15:57:17 última modificação: 2024-01-16 15:57:17
cópia: 0 Cliques: 762
1
focar em
1617
Seguidores

Estratégia de tendência de momentum ADX

Visão geral

A estratégia baseia-se no indicador ADX para determinar a tendência do mercado, em combinação com o indicador DMI para determinar a direção do vazio, usando o gradiente ADX para determinar a força da tendência, definindo o filtro de valores-chave do ADX para mercados fora de tendência, auxiliando o filtro de sinais de negociação de médias móveis.

Princípio da estratégia

  1. Calcule os indicadores ADX, DI+, DI-
  2. ADX = 0, indicando aumento de tendência; o valor-chave é definido como 23, para filtrar mercados fora de tendência.
  3. O DI+ é maior que o DI-, o que indica que a força de multiplicação é maior do que a força de multiplicação, para ver mais sinais.
  4. Quando o filtro de média móvel é ativado, o sinal de múltiplas cabeças é gerado somente quando o preço de fechamento é superior à média móvel.
  5. Quando a inclinação do ADX é menor que 0, a tendência diminui.

Análise de vantagens

  1. Filtragem de MA auxiliar para reduzir o ruído de negociação em mercados fora de tendência.
  2. A ADX inclinada é um instrumento de discernimento que permite avaliar com precisão a evolução da tendência.
  3. O DI julga a direção em conjunto com o discernimento da ADX, formando um sistema de decisão de negociação de tendências mais completo.
  4. A retracção e a perda de lucro são melhores do que uma simples estratégia de média móvel.

Análise de Riscos

  1. Os indicadores ADX definem diferentes parâmetros, o que pode resultar em grandes diferenças.
  2. O DMI ainda não determinou completamente a direção do voo, podendo emitir um sinal errado.
  3. A falta de uma estratégia eficaz pode levar a um atraso.

Direção de otimização

  1. Optimizar a combinação de parâmetros ADX para encontrar o melhor parâmetro.
  2. Aumentar a estratégia de stop loss para evitar a expansão de perdas individuais.
  3. Tente combinar os sinais de filtragem com outros indicadores, como o RSI, a faixa de Brin.

Resumir

A estratégia aproveita as vantagens do ADX para avaliar a tendência e a força da tendência, em conjunto com a orientação do DMI para avaliar a direção, formando um sistema de acompanhamento de tendências completo. Ao mesmo tempo, a média móvel auxiliar pode filtrar eficazmente o ruído do mercado não-trend. A otimização de parâmetros e combinação de indicadores também pode melhorar ainda mais a estabilidade e a eficiência da estratégia.

Código-fonte da estratégia
/*backtest
start: 2024-01-08 00:00:00
end: 2024-01-15 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © millerrh with inspiration from @9e52f12edd034d28bdd5544e7ff92e 
//The intent behind this study is to look at ADX when it has an increasing slope and is above a user-defined key level (23 default). 
//This is to identify when it is trending.
//It then looks at the DMI levels.  If D+ is above D- and the ADX is sloping upwards and above the key level, it triggers a buy condition.  Opposite for short.
//Can use a user-defined moving average to filter long/short if desried.
// NOTE: THIS IS MEANT TO BE USED IN CONJUNCTION WITH MY "ATX TRIGGER" INDICATOR FOR VISUALIZATION. MAKE SURE SETTINGS ARE THE SAME FOR BOTH.

strategy("ADX | DMI Trend", overlay=true, initial_capital=10000, currency='USD', 
   default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.04)

// === BACKTEST RANGE ===
From_Year  = input(defval = 2019, title = "From Year")
From_Month = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
From_Day   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
To_Year    = input(defval = 9999, title = "To Year")
To_Month   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
To_Day     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
Start  = timestamp(From_Year, From_Month, From_Day, 00, 00)  // backtest start window
Finish = timestamp(To_Year, To_Month, To_Day, 23, 59)        // backtest finish window

// == INPUTS ==
// ADX Info
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Period")
keyLevel = input(23, title="Keylevel for ADX")
adxLookback = input(3, title="Lookback Period for Slope")

// == FILTERING ==
// Inputs
useMaFilter = input(title = "Use MA for Filtering?", type = input.bool, defval = true)
maType = input(defval="EMA", options=["EMA", "SMA"], title = "MA Type For Filtering")
maLength   = input(defval = 200, title = "MA Period for Filtering", minval = 1)

// Declare function to be able to swap out EMA/SMA
ma(maType, src, length) =>
    maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)
maFilter = ma(maType, close, maLength)
plot(maFilter, title = "Trend Filter MA", color = color.green, linewidth = 3, style = plot.style_line, transp = 50)

// Check to see if the useMaFilter check box is checked, this then inputs this conditional "maFilterCheck" variable into the strategy entry 
maFilterCheck = if useMaFilter == true
    maFilter
else
    close

// == USE BUILT-IN DMI FUNCTION TO DETERMINE ADX AND BULL/BEAR STRENGTH
[diplus, diminus, adx] = dmi(dilen, adxlen)

buySignal = (adx[0]-adx[adxLookback] > 0) and adx > keyLevel and diplus > diminus  and close >= maFilterCheck
// buySignalValue = valuewhen(buySignal, close, 0)
shortSignal = (adx[0]-adx[adxLookback] > 0) and adx > keyLevel and diplus < diminus  and close <= maFilterCheck
// shortSignalValue = valuewhen(shortSignal, close, 0)
sellCoverSignal = adx[0]-adx[adxLookback] < 0

// == ENTRY & EXIT CRITERIA
// Triggers to be TRUE for it to fire of the BUY Signal : (opposite for the SELL signal).
// (1): Price is over the 200 EMA line. (EMA level configurable by the user)
// (2): "D+" is OVER the "D-" line
// (3): RSI 7 is under 30 (for SELL, RSI 7 is over 70)
// 1* = The ultimate is to have a combination line of 3 EMA values, EMA 14, EMA 50 and EMA 200 - And if price is over this "combo" line, then it's a strong signal

// == STRATEGY ENTRIES/EXITS == 
strategy.entry("Long", strategy.long, when = buySignal)
strategy.close("Long", when = sellCoverSignal)
strategy.entry("Short", strategy.short, when = shortSignal)
strategy.close("Short", when = sellCoverSignal)
    
// == ALERTS == 
// alertcondition(buySignal, title='ADX Trigger Buy', message='ADX Trigger Buy')
// alertcondition(sellSignal, title='ADX Trigger Sell', message='ADX Trigger Sell')