이중 EMA 크로스오버 트렌드 ATR 및 ADX 필터와 전략에 따라

저자:차오장, 날짜: 2023-11-15 15:53:57
태그:

img

전반적인 설명

이 전략은 트렌드 추적을 위한 고전적인 듀얼 EMA 크로스오버 시스템을 사용하며, ATR 및 ADX 지표의 추가 필터를 사용하여 강력한 트렌드를 추적하고 통합 과정에서 위험을 제어합니다.

전략 논리

이 전략은 주로 다음을 기반으로 합니다.

  1. 크로스오버 신호를 생성하기 위해 더 빠른 8주기 EMA와 더 느린 20주기 EMA를 사용합니다. EMA 자체는 트렌드를 따르는 특성을 가지고 있습니다.

  2. ATR 지표는 최근 변동성을 반영합니다. ATR을 정상화하면 EMA 크로스오버 필터 조건의 동적 조정, 강한 추세 중 요구 사항을 낮추고 고집 중 리스크를 제어 할 수 있습니다.

  3. ADX 지표는 트렌드 강도를 결정합니다. 30 이상의 ADX 판독은 강력한 트렌드를 제안하며, 적시에 스톱 로스를 촉구합니다.

  4. 올/곰 추세와 결합하여 긴/단기 입시 시기를 결정합니다. 올 시장에서 황금 십자가에 장거리, 곰 시장에서 죽음의 십자가에 단기.

  5. 부피가 늘어나면 볼륨 필터를 입력합니다.

  6. 간단한 USD 인덱스를 사용하여 USD 강도를 결정하고, USD 강세를 유지하는 동안 Stop and Take Profit 범위를 확장합니다.

  7. 슈퍼트렌드 지표를 사용하여 추가 장기/단기 지원에 대한 전체 시장 방향을 결정합니다.

이 전략은 트렌드와 오스실레이션 지표를 결합하여 파러미터를 동적으로 조정하여 트렌드를 추적하고 위험을 제어합니다.

전략 의 장점

  1. 이중 EMA 시스템은 트렌드 결정을 제공하며 EMA 매끄러움은 잘못된 브레이크를 필터링합니다.

  2. ATR 표준화된 필터는 다양한 시장 환경에 대한 유연성을 허용합니다.

  3. ADX와 부피는 통합 과정에서 을 피하기 위해 추가 검사를 제공합니다.

  4. USD와 슈퍼 트렌드를 고려하면 거시 트렌드에 대한 결정 정확도가 향상됩니다.

  5. 리스크 관리는 USD 강도에 따라 자동으로 조정됩니다.

  6. 간단한 골든/죽은 크로스 신호와 스톱/프로피트 로직은 실행과 백테스트를 쉽게 합니다.

전략 의 위험

  1. 이중 EMA는 트렌드 전환점을 감지하는 데 지연합니다.

  2. 잘못된 ATR 매개 변수 선택은 너무 공격적이거나 보수적일 수 있습니다.

  3. ADX 매개 변수는 최적화해야 합니다. 고점을 잘못 설정하면 트렌드를 놓칠 수 있습니다.

  4. USD 및 슈퍼 트렌드 트렌드 결정은 정확하지 않을 수 있습니다.

  5. 너무 긴 스톱 손실은 손실을 증가시킵니다. 너무 넓은 위험은 윙사입니다.

개선 방법

  1. 더 나은 변동점 검출을 위해 MACD와 같은 지표를 추가하는 것을 고려하십시오.

  2. 더 많은 역사적인 데이터에 대한 ATR 매개 변수를 최적화합니다.

  3. 다른 ADX 매개 변수를 테스트하고 높은 포인트 임계치를 최적화합니다.

  4. USD 및 시장 트렌드 분석에 더 많은 변수를 추가합니다.

  5. 백테스트 통계에 의해 최적의 스톱 로스 비율을 계산합니다.

  6. 후속 또는 촛불 정지 실험.

  7. 진입 크기와 보유 기간을 최적화하십시오.

결론

이 전략은 고전적인 이중 EMA 시스템을 여러 보조 지표와 통합하여 상당히 견고한 트렌드 다음 접근을 위해 매개 변수 최적화를 사용합니다. 리스크를 제어하는 동시에 변화하는 시장 환경에 유연하게 적응하여 트렌드를 추적합니다. 중지 및 지표 매개 변수의 추가 테스트 및 최적화는 결과를 향상시킬 수 있습니다. 개념은 배우고 개선할 가치가 있습니다.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Refactored Advanced EMA Cross with Normalized ATR Filter, Controlling ADX", shorttitle="ALP V5", overlay=true)

// Initialize variables to track if a buy order has been placed and number of periods since the last buy
var bool hasBought = false
var int barCountSinceBuy = 0

// Define EMA periods
emaShort = ta.ema(close, 8)
emaLong = ta.ema(close, 20)

// Define ATR period and normalization
atrLength = 14
atrValue = ta.atr(atrLength)
maxHistoricalATR = ta.highest(atrValue, 20)
minHistoricalATR = ta.lowest(atrValue, 20)
normalizedATR = (atrValue - minHistoricalATR) / (maxHistoricalATR - minHistoricalATR)

// Define ADX parameters
adxValue = ta.rma(close, 14)
adxHighLevel = 30
isADXHigh = adxValue > adxHighLevel

// Initialize risk management variables
var float stopLossPercent = na
var float takeProfitPercent = na
var float trailingStop = na

// Calculate USD strength (simplified)
usd_strength = close / ta.ema(close, 50) - 1

// Adjust risk parameters based on USD strength
if (usd_strength > 0)
    stopLossPercent := 3
    takeProfitPercent := 6
else
    stopLossPercent := 4
    takeProfitPercent := 8

// Initialize position variable
var float positionPrice = na

// Volume filter
minVolume = ta.sma(volume, 14) * 1.5
isVolumeHigh = volume > minVolume



// Piyasa yönü için süper trend göstergesi
[supertrendValue, supertrendDirection] = ta.supertrend(4, 14)  // Use a factor of 3 and ATR period of 10
bool isBullMarket = supertrendDirection < 0
bool isBearMarket = supertrendDirection > 0

// Yükselen piyasa için alım koşulu
buyConditionBull = isBullMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.2
// Düşen piyasa için alım koşulu
buyConditionBear = isBearMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.5
// Genel alım koşulu
buyCondition = buyConditionBull or buyConditionBear

// Yükselen ve düşen piyasalar için farklı satış koşulları
sellConditionBull = isBullMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
sellConditionBear = isBearMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
// Genel satış koşulu
sellCondition = sellConditionBull or sellConditionBear


// Buy condition
if (buyCondition)
    strategy.entry("Buy", strategy.long)
    positionPrice := close
    hasBought := true // Set the flag to true when a buy order is placed
    barCountSinceBuy := 0 // Reset the bar counter when a buy order is placed

// Increase the bar counter if a buy has been executed
if (hasBought)
    barCountSinceBuy := barCountSinceBuy + 1

// Calculate stop-loss and take-profit levels
longStopLoss = positionPrice * (1 - stopLossPercent / 100)
longTakeProfit = positionPrice * (1 + takeProfitPercent / 100)


// Final Sell condition, now also checks if a buy has occurred before and if at least 5 periods have passed
finalSellCondition = sellCondition and hasBought and barCountSinceBuy >= 3 and isVolumeHigh

if (finalSellCondition)
    strategy.close("Buy")
    positionPrice := na
    hasBought := false // Reset the flag when a sell order is placed
    barCountSinceBuy := 0 // Reset the bar counter when a buy order is closed

// Implement stop-loss, take-profit, and trailing stop
strategy.exit("Stop Loss", "Buy", stop=longStopLoss)
strategy.exit("Take Profit", "Buy", limit=longTakeProfit)
//strategy.exit("Trailing Stop", "Buy", trail_price=close, trail_offset=trailingStop * close / 100)


var label l = na

if (buyCondition)
    l := label.new(bar_index, high, text="buy triggered " + str.tostring(usd_strength))
    label.delete(l[1])

if (finalSellCondition)
    l := label.new(bar_index, high, text="sell triggered " + str.tostring(usd_strength))
    label.delete(l[1])

// Plot signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=finalSellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")


더 많은