2つの移動平均ボリンガーバンドトレンド追跡戦略

作者: リン・ハーンチャオチャン開催日:2023年12月11日 15時10分02秒
タグ:

img

概要

この戦略は,異なるタイムフレームで2つの指数的な移動平均値 (EMA) を計算し,適応ボリンジャー帯を使用してトレンド取引を実行するためにトレンド方向に沿って過剰購入および過剰販売の機会を特定することによって,一般的な市場トレンド方向を決定します.

戦略の論理

  1. 200 期間の EMA と 30 期間の EMA が計算されます. 200 期間の EMA が 30 期間の EMA より大きい場合,長期トレンドは上昇傾向で決定されます.そうでなければ,それは低下傾向で決定されます.

  2. トレンド方向が決定された後,ボリンジャー帯のベースライン,上帯,下帯を計算する.ベースラインは,設定可能な時間枠 (例えば8期) のSMAを採用する.バンド幅は,ベースラインと同期間の最高値と最低値の振幅の設定可能な倍数 (例えば1.3と1.1) である.

  3. 長期トレンドが上昇すると下帯のブレイクアウトはロングエントリー,長期トレンドがダウンすると上帯のブレイクアウトはショートエントリーを示します.

  4. 偽ブレイクをフィルタリングするために,ブレイク前の最後のキャンドルの変化率は設定可能な値を下回る (例えば3%) と,バンド幅は設定可能な値を超える (例えば閉値の2.2%) とチェックします.

  5. ポジションを開いた後,設定可能なストップ・ロース (例えば-3%) とテイク・プロフィート (例えば10%) が設定され,プロフィートをロックします.

戦略 の 強み

  1. 双 EMA は主要なトレンドを定義し,主要なトレンドが不明である場合,不規則なポジション開設を避ける.

  2. 適応ボリンジャー帯はトレンドに沿ってエントリーポイントを設定します. 自動幅調整はトレンドをさらにロックします.

  3. 変化の速さと最小幅の要求は,誤ったブレイクを効果的にフィルターします.

  4. ストップ・ロスの設定と 収益の設定は リスクをコントロールしながら 利益を合理的に固定します

戦略リスク

  1. 双 EMA は,トレンド転換点を正確に特定できず,トレンド転換点での機会を逃しています.

  2. BBパラメータの設定が不適切であれば 誤った信号が発せられる.

  3. 固定ストップ・ロストとテイク・プロフィートは 市場の変動に適応できない.

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

  1. 主要な傾向逆転と二次的な傾向逆転を決定するための他の指標を組み込む.

  2. BBパラメータを動的に調整する

  3. 特定の基準に基づいて ストップ・ロスの条件付きオーダーと 利益を取ります

結論

この戦略は,デュアルEMAを使用して主要なトレンドを判断し,ボリンジャーバンドで機会を特定することによってトレンド取引を実装する.その強みはトレンド利益をロックするために,合理的にエントリー,ストップ損失,利益を得る条件を設定することにある.トレンドターニングポイントと不適切なBBパラメータ設定を把握できないなどのリスクもあります.これらの側面のさらなる最適化により,トレンド利益をよりうまく把握する戦略ができるようになります.


/*backtest
start: 2022-12-04 00:00:00
end: 2023-12-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//////////////////////////////////////////////////////////////////////
// Component Code Start
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2039, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false
// Component Code Stop

strategy("Custom Band Strategy", overlay=true)
source = close //종가 기준

//추세 조건 설정
emaLong = ema(source, input(200, minval=0))
emaShort = ema(source, input(30, minval=0))
trend = if emaShort>=emaLong
    1
else
    -1
    
plot(emaLong, color=red, transp=0)
plot(emaShort, color=blue, transp=0)


//BB 계산(default 14/3.2)
length = input(8, minval=1)

basis = sma(source, length)
plot(basis, color=green, transp=0)
max=highest(abs(source-basis), length)

factor1 = input(1.3, minval=0.5)
factor2 = input(1.1, minval=0.5)

upper = if trend==1
    basis + max*factor1
else
    basis + max*factor2
lower = if trend==-1
    basis - max*factor1
else
    basis - max*factor2

plot1 = plot(upper)
plot2 = plot(lower)
fill(plot1, plot2, transp=80, color=green)

//밴드 이탈 후 재진입 조건 설정
cross_over = (low<=lower and close>=lower) or crossover(close,lower)
cross_under = (high>=upper and close<=upper) or crossunder(close,upper)

//변동율 계산
maxCandle=highest(abs(open-close), length)
    
roc = abs(open-close)/open*100
changerate = input(3, minval=0.0)

//수익률 계산
value = abs(strategy.position_size)*strategy.position_avg_price
roe = strategy.openprofit/value * 100
expRoeL = (upper-lower)/lower*100
expRoeS = (upper-lower)/upper*100
exp = input(2.2, minval=0.0)

target = input(10, minval=0.0)
stop = input(-3, minval=-10.0)

strategy.close_all(when=roc>=changerate and testPeriod())
strategy.close_all(when=roe>=target and testPeriod())
strategy.close_all(when=roe<=stop and testPeriod())

plotchar(crossover(close,lower) and crossunder(close,upper),color=blue, transp=0, text="cross")
plotchar(roc>=changerate,color=red, transp=0, text="roc")
plotchar(roe>=target,color=blue, transp=0, text="target")
plotchar(roe<=stop,color=green, transp=0, text="stop")

minroe = input(2, minval=0.0)

strategy.close_all(when=cross_under and roe>minroe and testPeriod())
strategy.entry("BBandLE", strategy.long, stop=source, oca_name="BollingerBands",  comment="BBandLE", when=(cross_over) and trend==1 and roc<changerate and expRoeL>exp and source>emaLong and strategy.position_size==0 and testPeriod()) //trend==1 and 
//else
strategy.close_all(when=cross_over and roe>minroe and testPeriod())
strategy.entry("BBandSE", strategy.short, stop=source, oca_name="BollingerBands",  comment="BBandSE", when=(cross_under) and trend==-1 and roc<changerate and expRoeS>exp and source<emaLong and strategy.position_size==0 and testPeriod()) //trend==-1 and 

もっと