ダイナミック・グロング・トレンド・戦略

作者: リン・ハーンチャオチャン, 開催日:2024年2月29日 11:24:18
タグ:

img

概要

ダイナミック・エングルフィン・トレンド戦略は,トレンド方向のエングルフィン・パターンをベースに長または短ポジションをとる取引戦略である.この戦略は,市場変動を測定するために平均真要範囲 (ATR),市場トレンド方向を決定するためにスーパートレンド指標を使用し,エングルフィン・パターンがトレンド方向に一致するときに取引を行う.ストップ・ロストとテイク・プロフィートのレベルもエングルフィン・パターンをベースに動的に計算される.

戦略の論理

  1. ATRを計算して市場変動を測定する.
  2. スーパートレンド指標を計算して市場傾向を特定します.
  3. 上昇傾向と下降傾向の条件を定義する.
  4. 上昇傾向 (bullish engulfing) と下落傾向 (bearish engulfing) を識別する.
  5. 停止損失 (SL) と取利益 (TP) のレベルを,吸収パターンに基づいて計算する.
  6. トレンド方向に一致するときに取引をします.
  7. 価格がSLまたはTPレベルに達したとき,取引を終了します.
  8. グラフに飲み込むパターンを描いてください

利点分析

この戦略の利点は以下の通りです.

  1. 信号の質を向上させ 流れと吸収パターンを組み合わせます
  2. 正確なエントリでトレンド逆転を特定する能力
  3. より良いタイミングのために 長い/短い信号をクリアします
  4. リスク管理の流れを踏まえて ストップ戦略を展開する
  5. 簡単な最適化のためのモジュールコードフレームワーク

リスク分析

考慮すべきリスクもいくつかあります.

  1. 飲み込むパターンは 偽の脱出になるかもしれません
  2. パターンサイズ,持続時間など,最適なパラメータを決定するのは困難です.
  3. 不完全なトレンド決定は 誤った信号につながるかもしれません
  4. ストップ・ロストとメリット・テイクレベルは,裁量に基づいており,主観的かもしれません.
  5. 性能は過去データに基づくパラメータ調整に依存します

リスクは以下によって軽減できます.

  1. フィルターを追加して 誤った信号を取り除く
  2. 適応型ATRを使用して 安定したパラメータ計算を行う
  3. 機械学習を用いてトレンド決定を改善する
  4. 遺伝子アルゴリズムを使って最適なパラメータを見つけます
  5. 耐久性を確保するために長期間バックテスト

オプティマイゼーションの方向性

さらに最適化できる余地があります.

  1. 機械学習は 傾向の決定を改善します
  2. 新しいパターン認識方法により 飲み込むパターンを よりよく識別できます
  3. 最新のストップ・ロスト/テイク・プロフィート戦略は レベルを動的に最適化できます
  4. 高周波データは 短期的なシステムを開発できます
  5. 異なる楽器のパラメータ調整

結論

ダイナミック・エングルフィン・トレンド戦略は,高品質のエングルフィン・パターンの信号と正確なトレンド決定を組み合わせ,正確なエントリと合理的なストップ損失と利益を引き出す取引システムを生成する.パラメータ,リスク管理および技術統合のさらなる改善は,その安定性と収益性を向上させることができる.構造化されたコードフレームワークは,この戦略を異なる市場でカスタマイズできるようにする.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Malikdrajat


//@version=4
strategy("Engulfing with Trend", overlay=true)

Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)

atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2

up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

// Define Downtrend and Uptrend conditions
downtrend = trend == -1
uptrend = trend == 1


// Engulfing 
boringThreshold = input(25, title="Boring Candle Threshold (%)", minval=1, maxval=100, step=1)
engulfingThreshold = input(50, title="Engulfing Candle Threshold (%)", minval=1, maxval=100, step=1)
stopLevel = input(200, title="Stop Level (Pips)", minval=1)


// Boring Candle (Inside Bar) and Engulfing Candlestick Conditions
isBoringCandle = abs(open[1] - close[1]) * 100 / abs(high[1] - low[1]) <= boringThreshold
isEngulfingCandle = abs(open - close) * 100 / abs(high - low) <= engulfingThreshold

// Bullish and Bearish Engulfing Conditions
bullEngulfing = uptrend and close[1] < open[1] and close > open[1] and not isBoringCandle and not isEngulfingCandle
bearEngulfing = downtrend and close[1] > open[1] and close < open[1] and not isBoringCandle and not isEngulfingCandle

// Stop Loss, Take Profit, and Entry Price Calculation
bullStop = close + (stopLevel * syminfo.mintick)
bearStop = close - (stopLevel * syminfo.mintick)
bullSL = low 
bearSL = high
bullTP = bullStop + (bullStop - low)
bearTP = bearStop - (high - bearStop)

// Entry Conditions
enterLong = bullEngulfing and uptrend
enterShort = bearEngulfing and downtrend

// Exit Conditions
exitLong = crossover(close, bullTP) or crossover(close, bullSL)
exitShort = crossover(close, bearTP) or crossover(close, bearSL)

// Check if exit conditions are met by the next candle
exitLongNextCandle = exitLong and (crossover(close[1], bullTP[1]) or crossover(close[1], bullSL[1]))
exitShortNextCandle = exitShort and (crossover(close[1], bearTP[1]) or crossover(close[1], bearSL[1]))

// Strategy Execution
strategy.entry("Buy", strategy.long, when=enterLong )
strategy.entry("Sell", strategy.short, when=enterShort )

// Exit Conditions for Long (Buy) Positions
if (bullEngulfing and not na(bullTP) and not na(bullSL))
    strategy.exit("Exit Long", from_entry="Buy", stop=bullSL, limit=bullTP)

// Exit Conditions for Short (Sell) Positions
if (bearEngulfing and not na(bearTP) and not na(bearSL))
    strategy.exit("Exit Short", from_entry="Sell", stop=bearSL, limit=bearTP)

// Plot Shapes and Labels
plotshape(bullEngulfing, style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(bearEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red)

// Determine OP, SL, and TP
plot(bullEngulfing ? bullStop : na, title="Bullish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearStop : na, title="Bearish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullSL : na, title="Bullish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearSL : na, title="Bearish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(bullEngulfing ? bullTP : na, title="Bullish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)
plot(bearEngulfing ? bearTP : na, title="Bearish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)



もっと