トリプル・EMA・プルバック・ブレイクアウト・トレード戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-12 15:12:56
タグ:

この戦略は,トレンドとトレードブレークアウトを決定するために,トリプルEMAの周辺の価格動きを観察します.

戦略論理:

  1. 通常は25~100~200期間の EMAを設定する.

  2. 価格が上/下回りで最速EMAに突入すると 暫定的な上昇/下落を示します

  3. 価格が最速EMAを下回る時,低価格に入ります.

  4. 視覚的な直感のために 色のコードで 購入/販売ゾーンを設定します

  5. リスク管理のために固定ストップ損失とリスク/リターン比を使用する.

利点:

  1. 引き戻し取引はより高い得率を誇ります

  2. トリプル・EMAは 傾向を認識し 挫折を避けます

  3. リスク/リターン比は業績持続性を高めます

リスク:

  1. 長期的撤退は 最適な入場タイミングを逃す可能性があります

  2. EMAの調整は 異なる期間に合わせる必要がありました

  3. 固定ストップは 機械的に過度に作動し カリブレーションが必要です

概要すると,この戦略は,より広範なトレンドを追跡するために三重EMAを使用して引き下げブレイクを取引します.リスクコントロールは,安定した長期的利益を生むのに役立ちますが,パラメータ最適化と引き下げ判断は依然として不可欠です.


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

//@version=5
strategy(title="Pullback", overlay=true, initial_capital=1000, slippage=25)

averageData = input.source(close, title="Source")
target_stop_ratio = input.float(title="Ratio Risk/Reward", defval=2, group="Money Management")
security = input.float(50, title='min of pips (00001.00) for each position', group="Money Management")
risk = input.float(2, title="Risk per Trade %", group="Money Management")

riskt = risk / 100 + 1

ema1V = input.int(25, title="Rapide", group="Ema Period")
ema2V = input.int(100, title="Moyenne", group="Ema Period")
ema3V = input.int(200, title="Lente", group="Ema Period")

ema1 = ta.ema(averageData, ema1V)
ema2 = ta.ema(averageData, ema2V)
ema3 = ta.ema(averageData, ema3V)

useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
     group="Backtest Time Period")
backtestStartDate = input(timestamp("5 June 2022"), 
     title="Start Date", group="Backtest Time Period",
     tooltip="This start date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")
backtestEndDate = input(timestamp("5 July 2022"),
     title="End Date", group="Backtest Time Period",
     tooltip="This end date is in the time zone of the exchange " + 
     "where the chart's instrument trades. It doesn't use the time " + 
     "zone of the chart or of your computer.")

inTradeWindow = true

float pricePullAboveEMA_maxClose = na
float pricePullBelowEMA_minClose = na

if ta.crossover(close, ema1)
    pricePullAboveEMA_maxClose := close
  
else
    pricePullAboveEMA_maxClose := pricePullAboveEMA_maxClose[1]

if close > pricePullAboveEMA_maxClose
    pricePullAboveEMA_maxClose := close

if ta.crossunder(close, ema1)
    pricePullBelowEMA_minClose := close
 
else
    pricePullBelowEMA_minClose := pricePullBelowEMA_minClose[1]

if close < pricePullBelowEMA_minClose
    pricePullBelowEMA_minClose := close

BuyZone = ema1 > ema2 and ema2 > ema3
SellZone = ema1 < ema2 and ema2 < ema3

longcondition = ta.crossover(close, ema1) and pricePullBelowEMA_minClose > ema3 and pricePullBelowEMA_minClose < ema1 
shortcondition = ta.crossunder(close , ema1) and pricePullAboveEMA_maxClose < ema3 and pricePullAboveEMA_maxClose > ema1

float risk_long = na
float risk_short = na
float stopLoss = na
float takeProfit = na
float entry_price = na

risk_long := risk_long[1]
risk_short := risk_short[1]

lotB = (strategy.equity*riskt-strategy.equity)/(close - ema2)
lotS = (strategy.equity*riskt-strategy.equity)/(ema2 - close)

if strategy.position_size == 0 and BuyZone and longcondition and inTradeWindow
    risk_long := (close - ema2) / close
    minp = close - ema2
    if minp > security
        strategy.entry("long", strategy.long, qty=lotB)
    
if strategy.position_size == 0 and SellZone and shortcondition and inTradeWindow
    risk_short := (ema2 - close) / close
    minp = ema2 - close
    if minp > security
        strategy.entry("short", strategy.short, qty=lotS)
    
if strategy.position_size > 0

    stopLoss := strategy.position_avg_price * (1 - risk_long)
    takeProfit := strategy.position_avg_price * (1 + target_stop_ratio * risk_long)
    entry_price := strategy.position_avg_price
    strategy.exit("long exit", "long", stop = stopLoss, limit = takeProfit)
    
if strategy.position_size < 0

    stopLoss := strategy.position_avg_price * (1 + risk_short)
    takeProfit := strategy.position_avg_price * (1 - target_stop_ratio * risk_short)
    entry_price := strategy.position_avg_price
    strategy.exit("short exit", "short", stop = stopLoss, limit = takeProfit)
    
plot(ema1, color=color.blue, linewidth=2, title="Ema Rapide")
plot(ema2, color=color.orange, linewidth=2, title="Ema Moyenne")
plot(ema3, color=color.white, linewidth=2, title="Ema Lente")
p_ep = plot(entry_price, color=color.new(color.white, 0), linewidth=2, style=plot.style_linebr, title='entry price')
p_sl = plot(stopLoss, color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr, title='stopLoss')
p_tp = plot(takeProfit, color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr, title='takeProfit')
fill(p_sl, p_ep, color.new(color.red, transp=85))
fill(p_tp, p_ep, color.new(color.green, transp=85))

bgcolor(BuyZone ? color.new(color.green, 95)  : na)
bgcolor(SellZone ? color.new(color.red, 95)  : na)




もっと