上向きと下向きのEMAフィルターとセッションタイムフレームを持つクローズ・キャンドル戦略

作者: リン・ハーンチャオチャン開催日:2023年12月27日 14:38:28
タグ:

img

1. 戦略の概要

この戦略は,EMAフィルターとセッションタイムフレームを持つ"Up versus Down Close Candles Strategy"と呼ばれる.これは,EMAフィルターと特定のセッションでの取引を組み合わせて,市場情勢を決定するために,特定の見直し期間にUpとDown Close Candlesの数を数えて,ロングとショートシグナルを識別します.

2. 戦略 論理

基本論理は,最近の回顧期間のアップ・クローズ・カウント (upCloseCount) とダウン・クローズ・カウント (downCloseCount) の数を数えることです.UpCloseCountが大きい場合,それは上昇市場を示します.DownCloseCountが大きい場合は,それは下落市場を示します.EMA指標はフィルターとして使用され,価格 > EMAで長いこと,価格 < EMAで短いことを考慮します.また,セッション1とセッション2を取引セッションとして設定します.

詳細な論理:

inSessionは true (取引セッションでは) と upCloseCount > downCloseCount (より近いキャンドル) と close > ema (EMAよりも高い閉値) と currentSignalは long (既存のポジションがない) で,ロングシグナルが起動します.

ショートシグナルは: inSessionは true と downCloseCount > upCloseCount (さらにダウン Close Candles) と close < ema (EMAよりも低い閉値) と currentSignalが short ではないとき起動します (既存のポジションはありません).

3. 利点 の 分析

  1. 市場情勢とトレンドを把握し,閉店/閉店キャンドルの履歴を比較する
  2. EMAフィルタを使用して,変動市場での取引を避ける
  3. セッションを設定することで,主要取引時間以外の時間に騒音を避ける
  4. トレンドフォローと取引頻度のバランス

4. リスク 分析

  1. 横向市場では誤導されることがあります
  2. 誤ったEMAパラメータは,効果のないフィルターを引き起こす可能性があります.
  3. セッションが正しく設定されていない場合,機会を逃す
  4. イベントによるギャップをキャプチャできない

解決策:

  1. EMA パラメータを最適化
  2. 取引セッションを最適化する
  3. ストップ損失をATRに基づいて追加する.
  4. イベントを特定し,ギャップを回避する

5. 最適化 の 方向性

  1. 取引セッションを最適化する
  2. EMA パラメータを最適化
  3. ATR ベースのストップ損失を追加する
  4. イベントを特定し,ギャップを回避する
  5. より良いフィルターのために他の指標と組み合わせる
  6. 製品間でのテストと調整

6. 概要

この戦略は,前もって設定された取引セッション内で,EMAフィルターを使用して,閉じると閉じるキャンドルを比較してトレンドシグナルを識別する.いくつかのトレンドフォロー効果があるが,偽信号のリスクもあります.パラメータを最適化し,ストップロスを追加し,フィルターを強化し,改善します.バックテストで徹底的に評価します.


/*backtest
start: 2023-11-26 00:00:00
end: 2023-12-26 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Up vs Down Close Candles Strategy with EMA and Session Time Frames", shorttitle="UvD Strat EMA Session", overlay=true)

// User input to define the lookback period, EMA period, and session strings for time frames
int lookback = input(20, title="Lookback Period")
int emaPeriod = input(50, title="EMA Period")
string session1 = input("0900-1200", title="Time Frame 1 Session")
string session2 = input("1300-1600", title="Time Frame 2 Session")

// Calculate the EMA
float ema = ta.ema(close, emaPeriod)

// State variable to track the current signal
var string currentSignal = na

// Counting up-close and down-close candles within the lookback period
int upCloseCount = 0
int downCloseCount = 0

if barstate.isnew
    upCloseCount := 0
    downCloseCount := 0
    for i = 0 to lookback - 1
        if close[i] > close[i + 1]
            upCloseCount += 1
        else if close[i] < close[i + 1]
            downCloseCount += 1

// Define the long (buy) and short (sell) conditions with EMA filter and session time frame
bool inSession = time(timeframe.period, session1) or time(timeframe.period, session2)
bool longCondition = inSession and upCloseCount > downCloseCount and close > ema and currentSignal != "long"
bool shortCondition = inSession and downCloseCount > upCloseCount and close < ema and currentSignal != "short"

// Enter or exit the market based on conditions
if longCondition
    currentSignal := "long"
    strategy.entry("Buy", strategy.long)

if shortCondition
    currentSignal := "short"
    strategy.entry("Sell", strategy.short)

// Exit logic for long and short positions
if currentSignal == "long" and strategy.position_size <= 0
    strategy.close("Sell")

if currentSignal == "short" and strategy.position_size >= 0
    strategy.close("Buy")

plot(ema, color=color.blue, title="EMA")


もっと