EMAの取引戦略

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

EMAの取引戦略

この戦略は,EMA分析に基づいて取引され,以下のルールがあります.

  • 前日の閉店がEMAより高い場合,ロングを入力します.

  • 現在のキャンドルがEMAを下回る場合,ロングアウト

この戦略の利点:

  • トレンド方向を決定するために EMA を使用する
  • シンプルで明瞭なルール 実行が簡単
  • 最適化のための可変EMA期間

可能性のある問題:

  • 範囲限定の市場において誤った信号に敏感である
  • 遅刻して入ると 捕まえる危険
  • ストップ・ロスはなく,制御不能な損失のリスク
  • 取引頻度やポジションサイズに関する規則がない

EMA戦略は,トレンド市場ではよりうまく機能するが,慎重に使用されるべきである.ストップとフィルターを追加することで戦略を最適化するのに役立ちます.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"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/
// © ericdwyang

//@version=5
strategy("EMA Strat", overlay=true, margin_long=100, margin_short=100)

// EMA Variables
emaInput = input(21, "Length")
ema = ta.ema(close, emaInput)

// Variable Declaration
p = 0

start = false

// Start Date
yearInput = input(2000, "Year")
if (time >= timestamp(2000,01,01,01,01))
    start := true


// Check first candle relative to EMA
if (close > ema and start == true)
    p += 1
    strategy.entry("Long", strategy.long, comment = "Entry")
    

// Candle close above EMA (p + 1, count reset to 0)
above = close[1] > ema[1]
if (above)
    p += 1



// Candle close below EMA (reset p to 0, count -1)
below = close < ema
if (below)
    p := 0
    strategy.close("Long", comment = "Flat")

// // Exit Position
// if (redCount == -2)
//     strategy.close("Long", comment = "Flat")
    
// goLong = p[1] == 0 and p == 1
// flatten = p == 0
    
// // Restablish long    
// if (goLong and start == true)
//     strategy.entry("Long", strategy.long, comment = "Entry")
    

plot(p)
plot(ema)

    

もっと