이중 EMA 골든 크로스 거래 전략

저자:차오장, 날짜: 2023-12-07 15:08:57
태그:

img

전반적인 설명

이 전략은 이중 EMA 황금 십자, 정상화된 ATR 노이즈 필터 및 ADX 트렌드 지표를 결합하여 거래자에게 더 신뢰할 수있는 구매 신호를 제공합니다. 잘못된 신호를 필터링하고 더 신뢰할 수있는 거래 기회를 식별하기 위해 여러 지표를 통합합니다.

전략 원칙

이 전략은 8주기 및 20주기 EMA를 사용하여 이중 EMA 황금 십자 시스템을 구축합니다. 짧은 기간 EMA가 더 긴 기간 EMA를 넘을 때 구매 신호를 생성합니다.

또한 전략은 필터링을 위한 몇 가지 보조 지표를 설정했습니다.

  1. 14주기 ATR, 시장의 사소한 가격 변동을 필터링하기 위해 정상화.

  2. 트렌드의 강도를 식별하기 위해 14 기간 ADX. 거래는 강한 트렌드에서만 고려됩니다.

  3. 14주기 SMA는 소규모 거래량을 가진 시기를 필터링합니다.

  4. 4/14 기간 슈퍼 트렌드 지표 시장 상승 또는 하락 방향을 판단합니다.

트렌드 방향, 정상화 된 ATR 값, ADX 수준 및 부피 조건이 충족 될 때만 EMA 황금 십자가가 결국 구매 신호를 유발합니다.

전략적 장점

  1. 여러 지표 조합의 신뢰성

    EMA, ATR, ADX 및 슈퍼 트렌드와 같은 지표를 통합하면 강력한 신호 필터링 시스템을 형성하고 더 높은 신뢰성을 제공합니다.

  2. 매개 변수 조정에 더 많은 유연성

    정상화 된 ATR, ADX, 보유 기간 등의 임계 값을 최적화 할 수 있으며 더 많은 유연성을 제공합니다.

  3. 황소 시장과 곰 시장의 구별

    슈퍼 트렌드를 사용하여 황소 시장과 곰 시장을 식별하고 놓친 기회를 피하십시오.

전략 위험

  1. 매개 변수 최적화 어려움

    너무 많은 매개 변수, 최적의 조합을 찾는 데 어려움이 있습니다.

  2. 표시기 고장 위험

    지표의 지연 특성으로 인해 여전히 잘못된 신호가 발생할 위험이 있습니다. 적절한 스톱 로스 이론은 고려되어야합니다.

  3. 거래 빈도가 낮다

    여러 필터로 인해 빈도가 낮고, 거래 기간이 길어질 수 있습니다.

최적화 방향

  1. 매개 변수 조합을 최적화

    최적의 조합을 찾는 것은 많은 백테스팅 데이터를 필요로 합니다.

  2. 기계 학습을 통합

    ML 알고리즘을 사용하여 시간이 지남에 따라 매개 변수를 자동으로 최적화합니다. 적응력을 향상시킵니다.

  3. 더 많은 시장 요인을 고려

    시장 구조, 감정 등의 지표를 결합하면 다양성이 향상됩니다.

결론

이 전략은 트렌드, 변동성 및 볼륨 가격 요인을 포괄적으로 고려합니다. 멀티 지표 필터링 및 매개 변수 조정을 통해 신뢰할 수있는 거래 시스템을 형성합니다. 신뢰성은 높으며 최적화를 통해 더 향상 될 수 있습니다.


/*backtest
start: 2023-11-29 00:00:00
end: 2023-12-06 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/


//Description:
//This strategy is a refactored version of an EMA cross strategy with a normalized ATR filter and ADX control. 
//It aims to provide traders with signals for long positions based on market conditions defined by various indicators.

//How it Works:
//1. EMA: Uses short (8 periods) and long (20 periods) EMAs to identify crossovers.
//2. ATR: Uses a 14-period ATR, normalized to its 20-period historical range, to filter out noise.
//3. ADX: Uses a 14-period RMA to identify strong trends.
//4. Volume: Filters trades based on a 14-period SMA of volume.
//5. Super Trend: Uses a Super Trend indicator to identify the market direction.

//How to Use:
//- Buy Signal: Generated when EMA short crosses above EMA long, and other conditions like ATR and market direction are met.
//- Sell Signal: Generated based on EMA crossunder and high ADX value.

//Originality and Usefulness:
//This script combines EMA, ATR, ADX, and Super Trend indicators to filter out false signals and identify more reliable trading opportunities. 
//USD Strength is not working, just simulated it as PSEUDO CODE: [close>EMA(50)]

//Strategy Results:
//- Account Size: $1000
//- Commission: Not considered
//- Slippage: Not considered
//- Risk: Less than 5% per trade
//- Dataset: Aim for more than 100 trades for sufficient sample size

//Note: This script should be used for educational purposes and should not be considered as financial advice.

//Chart:
//- The script's output is plotted as Buy and Sell signals on the chart.
//- No other scripts are included for clarity.
//- Have tested with 30mins period
//- You are encouraged to play with parameters, let me know if you 

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

// Initialize variables
var bool hasBought = false
var int barCountSinceBuy = 0

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

// Define ATR parameters
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

// Calculate USD strength
// That's not working as usd strenght, since I couldn't manage to get usd strength 
//I've just simulated it as if the current close price is above 50 days average (it's likely a bullish trend), usd is strong (usd_strenth variable is positive)
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

// Market direction using Super Trend indicator
[supertrendValue, supertrendDirection] = ta.supertrend(4, 14)
bool isBullMarket = supertrendDirection < 0
bool isBearMarket = supertrendDirection > 0

// Buy conditions for Bull and Bear markets
buyConditionBull = isBullMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.2
buyConditionBear = isBearMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.5
buyCondition = buyConditionBull or buyConditionBear

// Sell conditions for Bull and Bear markets
sellConditionBull = isBullMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
sellConditionBear = isBearMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
sellCondition = sellConditionBull or sellConditionBear

// Final Buy and Sell conditions
if (buyCondition)
    strategy.entry("Buy", strategy.long)
    positionPrice := close
    hasBought := true
    barCountSinceBuy := 0

if (hasBought)
    barCountSinceBuy := barCountSinceBuy + 1

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

// Final Sell condition
finalSellCondition = sellCondition and hasBought and barCountSinceBuy >= 3 and isVolumeHigh

if (finalSellCondition)
    strategy.close("Buy")
    positionPrice := na
    hasBought := false
    barCountSinceBuy := 0

// Implement stop-loss and take-profit
strategy.exit("Stop Loss", "Buy", stop=longStopLoss)
strategy.exit("Take Profit", "Buy", limit=longTakeProfit)

// 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")


더 많은