ATR と ADX フィルターによる戦略をフォローする二重 EMA クロスオーバー トレンド

作者: リン・ハーンチャオチャン開催日:2023年11月15日 15:53:57
タグ:

img

概要

この戦略は,ATRとADX指標から追加フィルタを備えた,従来の二重EMAクロスオーバーシステムを採用し,強烈なトレンドを追跡し,統合期間におけるリスクを制御する.

戦略の論理

この戦略は主に以下の点に基づいています.

  1. 交差信号を生成するために,より速い8期EMAとより遅い20期EMAを使用します. EMA自体はトレンドフォロープロパティを持っています.

  2. ATR指標は,最近の変動を反映する.ATRを正常化することで,EMAクロスオーバーフィルター条件を動的に調整し,強いトレンド中に要件を低下させ,リスクを制御するために統合中に引き上げることができます.

  3. ADX指標はトレンド強さを決定します. ADX値が30を超えると強いトレンドを示し,タイミングよくストップロスを誘発します.

  4. 長/短エントリータイミングを決定するために,高/低トレンドと組み合わせます.高値の市場では金色のクロスで長,低値の市場では死亡クロスで短です.

  5. ボリュームが膨張すると入力するボリュームフィルターです

  6. ドル強さを判断するために シンプルなUSDインデックスを使います 強いUSDの際にはストップと利益の範囲を拡大します

  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. ドルと市場動向分析の変数を追加します.

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


もっと