移動平均帯の破裂戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-17 18:33:57
タグ:

概要

この戦略は,移動平均値を用い,価格チャネルを形成し,価格がチャネル帯を突破するとシグナルを生成する.これはパラメータチューニングを通じて簡単なロング/ショートポジションを達成できる典型的なトレンドフォロー戦略である.

戦略の論理

  1. SMA/EMA/WMA/RMAのようなオプションで移動平均を計算します

  2. 上部帯は移動平均の一定パーセント増加である.下部帯は一定パーセント減少である.

  3. 上部帯以上でロング,下部帯以下でショートする. ロングのみ,ショートのみ,または双方向取引のオプション.

  4. ストップ・ロスはエントリー価格の一定パーセント増加です.ストップ・ロスはエントリー価格の一定パーセント減少です.

利点分析

  1. 移動平均値を用いて 傾向決定を実装するのは簡単です

  2. 調整可能なパラメータは,異なる保持期間とリスク優先順位に対応します.

  3. 選択的な長/短方向は,様々な市場状況に適応する.

  4. 固定パーセントのストップ・ロストとテイク・プロフィートは 制御性を可能にします

リスク分析

  1. 傾向が急激に変わると 罠にかかれやすい

  2. パラメータの調整が正しくない場合,過剰取引または遅れのリスクがあります.

  3. 固定パーセントのストップ損失/利益は柔軟性がない.

  4. 双方向取引で取引頻度と手数料の増加

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

  1. 移動平均パラメータを最適化して遅延とノイズをバランスする

  2. チャンネルの帯域幅を最適化して 市場の波動率に合わせる

  3. 異なるストップ・ロスをテストし 利益を取ります ダイナミック・ストップはより効果的です

  4. トレンドと振動指標を追加して,市場全体的な状況を測定します.

  5. 重要なイベントの影響を避けるために時間フィルターを導入します

概要

戦略は,移動平均チャネルを通じて単純なトレンドをたどるのに,より強力なパラメータ最適化とリスク管理が必要です.その後,戦略論理をさらに改善するために,より多くの技術指標を導入することができます.


/*backtest
start: 2023-08-17 00:00:00
end: 2023-09-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_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/
// © TaylorTneh
//@version=4

// strategy("Moving Average Band Taylor V1",shorttitle="MA Band+",overlay=true,default_qty_type=strategy.cash,default_qty_value=1000,initial_capital=1000,currency=currency.USD,commission_value=.1)

price = input(close, title="Source")
mabtype = input(title="Moving Average Type", defval="RMA", options=["SMA", "EMA", "RMA", "WMA"])
malen = input(10, "MA Period : 10")
magap = input(0.6, "Band Gap : 0.6", minval = -10, maxval = 10, step = 0.1)
mabup = if mabtype == "SMA"
    sma(high, malen)
else
    if mabtype == "EMA"
        ema(high, malen)
    else
        if mabtype == "WMA"
            wma(high, malen)
        else
            if mabtype == "RMA"
                rma(high, malen)
                    
mabdn = if mabtype == "SMA"
    sma(low, malen)
else
    if mabtype == "EMA"
        ema(low, malen)
    else
        if mabtype == "WMA"
            wma(low, malen)
        else
            if mabtype == "RMA"
                rma(low, malen)
                    
upex = mabup * (1 + magap/100)
dnex = mabdn * (1 - magap/100)
plot(upex, "Upper MA Band", color.orange)
plot(dnex, "Lower MA Band", color.orange)


//-------------------------------------------- (Strategy)
strategy.entry("Long", strategy.long, stop = upex)
strategy.entry("Short", strategy.short, stop = dnex)
//Long Only//strategy.entry("Long", strategy.long, stop = upex)
//Long Only//strategy.exit("Short", stop = dnex)
//Short Only//strategy.entry("Short", strategy.short, stop = dnex)
//Short Only//strategy.exit("Long", stop = upex)


//-------------------------------------------- (Take Profit & Stop Lose)
stopPer = input(500.0, title='# Stop Loss %', type=input.float) / 100
takePer = input(500.0, title='# Take Profit %', type=input.float) / 100
//Determine where you've entered and in what direction
longStop = strategy.position_avg_price * (1 - stopPer)
shortStop = strategy.position_avg_price * (1 + stopPer)
shortTake = strategy.position_avg_price * (1 - takePer)
longTake = strategy.position_avg_price * (1 + takePer)
if strategy.position_size > 0 
    strategy.exit(id="L-TP/SL", stop=longStop, limit=longTake)
if strategy.position_size < 0 
    strategy.exit(id="S-TP/SL", stop=shortStop, limit=shortTake)


//-------------------------------------------- (Sample Time Filter Strategy)
//fromyear = input(2018, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
//toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
//frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
//tomonth = input(10, defval = 10, minval = 01, maxval = 12, title = "To Month")
//fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
//today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//strategy.entry("Long", strategy.long, stop = upex, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
//strategy.entry("Short", strategy.short, stop = dnex, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
//--------------------------------------------


もっと