ダブルEMA高速ラインと低速ラインのクロスオーバー戦略


作成日: 2024-02-22 16:18:39 最終変更日: 2024-02-22 16:18:39
コピー: 0 クリック数: 726
1
フォロー
1617
フォロワー

ダブルEMA高速ラインと低速ラインのクロスオーバー戦略

概要

ダブルEMAクロスオーバー戦略 (Dual EMA Crossover Strategy) は,2つの異なる周期のEMA平均線クロスオーバーをベースにポジション開設とポジションの開設を行う量化取引戦略である.この戦略はシンプルで有効で,容易に理解でき,量化取引の一般的な戦略である.

戦略原則

この戦略は,2つのEMA平均線,25周期のEMA線を快線として,50周期のEMA線を遅線として使用する. 速線で遅線を横切るときは,多行し,速線の下で遅線を横切るときは,空行する.

オーバーした後に,ストップをエントリー価格の2%に設定し,ストップはエントリー価格の2%に設定し,ストップまたはストップに達したときにポジションを平らげる.空白を同理する.

この戦略の核心は,市場トレンドと逆転を判断するために,EMAの快慢線の交差を利用することである. 上を走る時,牛市と多を判断し,下を走る時,熊市と空を判断する. 利益とリスクを制御するために,ストップ・ロスの設定する.

優位分析

双EMA速慢線交差策には以下の利点がある.

  1. 思考が明確で 論理がシンプルで 実行が理解しやすい
  2. 速線と遅線を組み合わせることで,中短線のトレンドを捉えることができます.
  3. 市場転換点を把握できるのは,順調に,時間内にできる.
  4. リスクがコントロールされ,ストップ・ストップ・損失の設定は合理的です.

全体として,この戦略は,市場を明確に論理的に判断し,EMA自身の優位性を利用し,リスクが制御可能な前提で,良い中短線利益を得ます.

リスク分析

双重EMAの横断策にはいくつかのリスクがあります.

  1. 市場が急激に波動する時には,EMA線交差信号は正確ではない可能性があり,その誤判の可能性がある.
  2. ストップ・ストップ・ロスの設定が不合理である場合,より大きな市場状況を見逃したり,より大きな損失を負う可能性があります.
  3. 取引費用やスライドポイントの影響も無視できない.

これらのリスクは以下の方法で最適化できます.

  1. EMAの交差の誤判信号を避けるために,他の指標と組み合わせて市場を判断する.
  2. 利益とリスクのバランスをとるため,ストップ・ストップ・損失の設定点をテストし,最適化します.
  3. 低手数料の取引プラットフォームを選択し,適切な取引量を拡大してください.

最適化の方向

この戦略には以下の主要な最適化方向があります.

  1. EMAの周期パラメータを最適化し,最適なパラメータ組み合わせを探します.
  2. 取引ポートフォリオを構成し,精度を高めます.
  3. 動的に調整するストップ・ストップ・ポイント。損失が一定幅に達するとストップ・ポイントの追跡が拡大され,利益が一定幅に達するとストップ・ポイントの移動など。
  4. 多頭市場と空頭市場を区別し,指向取引を行う.

これらの最適化は,戦略をシンプルで明快に保ちながら,収益率と勝利率を向上させることができます.

要約する

双EMA快慢線交差戦略は,全体的に非常に実用的な量化取引戦略である.それは理解し,実行しやすく,市場動向を効果的に把握している.また,パラメータの調整と組み合わせによって,収益率をさらに向上させるための一定の最適化スペースがある.このシンプルで直接的な戦略の考え方は,投資家が学び,適用する価値があります.

ストラテジーソースコード
/*backtest
start: 2024-01-22 00:00:00
end: 2024-02-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// SEMA-X(SEMA CROSS) [AB] : Simple EMA cross strategy Alert & Backtest
// 1. 2 EMA cross
// 2. Next candle entry
// 3. TP & SL

//@version=5
strategy("SEMA-X", "SEMA-X", overlay=false, margin_long=1,
 initial_capital=1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100,
 commission_type=strategy.commission.percent, commission_value=0.075, slippage=3)

//****************************************************************************//
// Input
//****************************************************************************//
// EMA length
emaLen25 = input.int(25, "Short", minval=1, confirm=true, group="[EMA]----------", inline="1")
emaLen50 = input.int(50, "Long",  minval=1, confirm=true, group="[EMA]----------", inline="1")

// TP & SL
isLong   = input.bool(true, "Long - ",    confirm=true, group="[TP & SL(%)]----------", inline="1")
tpLong   = input.float(2, "TP", minval=0, confirm=true, group="[TP & SL(%)]----------", inline="1")*0.01
slLong   = input.float(2, "SL", minval=0, confirm=true, group="[TP & SL(%)]----------", inline="1")*0.01
isShort  = input.bool(false, "Short - ",  confirm=true, group="[TP & SL(%)]----------", inline="2")
tpShort  = input.float(2, "TP", minval=0, confirm=true, group="[TP & SL(%)]----------", inline="2")*0.01
slShort  = input.float(2, "SL", minval=0, confirm=true, group="[TP & SL(%)]----------", inline="2")*0.01

// Backtest period
sTime = input(timestamp("0001-01-01"), "Start", group="[Backtest]----------")
eTime = input(timestamp("9999-01-01"), "End",   group="[Backtest]----------")
inDateRange   = true
periodBg      = input.bool(false, "Backtest BGcolor", confirm=true, group="[Backtest]----------", inline="1")
bgLong        = input.bool(false, "Position BGcolor", confirm=true, group="[Backtest]----------", inline="1")
periodBgColor = periodBg and inDateRange ? color.new(color.green, 95) : na
bgcolor(periodBgColor, title="Backtest BGcolor")
bgColorLong   = bgLong and strategy.position_size>0 ? color.new(color.green, 95) : na
bgcolor(bgColorLong, title="Position BGcolor")

// IRISBOT
exchange = input.string("binance",  "Exchange", confirm=true, group="[IRISBOT]----------", inline="2", options=["binance", "bybit", "upbit"])
account  = input.string("account1", "Account",  confirm=true, group="[IRISBOT]----------", inline="2")
symbol   = input.string("BTC/USDT", "Symbol",   confirm=true, group="[IRISBOT]----------", inline="3")
strategy = input.string("sema-x",   "Strategy", confirm=true, group="[IRISBOT]----------", inline="3")
token    = input.string("token",    "Token",    confirm=true, group="[IRISBOT]----------", inline="4")
stRatio  = input.float(100.0,       "Ratio(%)", confirm=true, group="[IRISBOT]----------", inline="5", tooltip="하나의 거래소에서 이 전략을 몇 % 비중으로 투자할 것인가?") * 0.01
leverage = input.float(1,           "Leverage", confirm=true, group="[IRISBOT]----------", inline="5")
isPlotMsg = input.bool(false, "View alert msg", confirm=true, group="[IRISBOT]----------", inline="6")

//****************************************************************************//
// Process
//****************************************************************************//
ema25=ta.ema(close, emaLen25)
ema50=ta.ema(close, emaLen50)

// Entry condition
longCondition  = isLong and ta.crossover(ema25, ema50)
shortCondition = isShort and ta.crossunder(ema25, ema50)

// Entry price
var price=0.0
var pricePlot=0.0
if (longCondition or shortCondition) and strategy.position_size == 0
    price:=close
pricePlot:=price
if (strategy.position_size==0)
    pricePlot:=na

// Amount
amount = str.tostring(stRatio*100)

// IRISBOT alert msg (for auto trading, you can change this for autoview, tvextbot, thanksbot, etc webhookbot)
msgLong  = '{"exchange":"'+exchange+'","account":"'+account+'","strategy":"'+strategy+'","symbol":"'+symbol+'","type":"market","side":"buy","amount":"'+amount+'%","leverage":"'+str.tostring(leverage)+'","token":"'+token+'"}'
msgShort = '{"exchange":"'+exchange+'","account":"'+account+'","strategy":"'+strategy+'","symbol":"'+symbol+'","type":"market","side":"sell","amount":"'+amount+'%","leverage":"'+str.tostring(leverage)+'","token":"'+token+'"}'
msgExit  = '{"exchange":"'+exchange+'","account":"'+account+'","strategy":"'+strategy+'","symbol":"'+symbol+'","type":"market","side":"close","token":"'+token+'"}'

// Entry signal
if inDateRange
    strategy.entry("L", strategy.long,  when=longCondition,  comment="L", alert_message=msgLong)
    strategy.entry("S", strategy.short, when=shortCondition, comment="S", alert_message=msgShort)
    strategy.exit("XL", "L", profit=price*tpLong/syminfo.mintick,  loss=price*slLong/syminfo.mintick,  comment="X", alert_message=msgExit)
    strategy.exit("XS", "S", profit=price*tpShort/syminfo.mintick, loss=price*slShort/syminfo.mintick, comment="X", alert_message=msgExit)

//****************************************************************************//
// Plot
//****************************************************************************//
// Alert msg plot
var msgTable = table.new(position = position.bottom_right, columns = 2, rows = 3, bgcolor = color.new(color.blue, 80), border_width = 1)
if isPlotMsg
    if isLong
        table.cell(msgTable, 0, 0, "Long",  text_halign = text.align_left)
        table.cell(msgTable, 1, 0, msgLong,  text_halign = text.align_left)
    
    if isShort
        table.cell(msgTable, 0, 1, "Short", text_halign = text.align_left, bgcolor=color.new(color.red, 80))
        table.cell(msgTable, 1, 1, msgShort, text_halign = text.align_left, bgcolor=color.new(color.red, 80))
    
    if isLong or isShort
        table.cell(msgTable, 0, 2, "Exit",  text_halign = text.align_left, bgcolor=color.new(color.purple, 80))
        table.cell(msgTable, 1, 2, msgExit,  text_halign = text.align_left, bgcolor=color.new(color.purple, 80))

// EMA
e0=plot(ema25, "Short", color.green)
e1=plot(ema50, "Long", color.red)
fill(e0, e1, ema25>ema50 ? color.new(color.green, 50) : color.new(color.red, 50), "EMA BG")

// TP & SL
p0=plot(pricePlot, "Entry", color.black, style=plot.style_linebr)
p1=plot(pricePlot*(strategy.position_size>0 ? 1+tpLong : 1-tpShort), "TP", color.new(color.green, 50), style=plot.style_linebr)
p2=plot(pricePlot*(strategy.position_size>0 ? 1-slLong : 1+slShort), "SL", color.new(color.red, 50), style=plot.style_linebr)
fill(p0, p1, color.new(color.green, 80), "TP BG")
fill(p0, p2, color.new(color.red, 80), "SL BG")