ダブル移動平均ボリンジャーバンドトレンドフォロー戦略


作成日: 2023-11-01 14:15:11 最終変更日: 2023-11-01 14:15:11
コピー: 0 クリック数: 385
1
フォロー
1224
フォロワー

ダブル移動平均ボリンジャーバンドトレンドフォロー戦略

概要

この戦略は,ブリン帯の双均線に基づいてトレンドをフォローする取引決定を行う.それは,ブリン帯の下線の収束と分散を利用して,トレンドの変化を判断し,ブリン帯の下線近くで購入し,上線近くで販売し,低買い高売りを実現し,利益を得て出発する.

戦略原則

この戦略は,ブリンバンドのシンプルブリンバンドと強化ブリンバンドの2つのバージョンを同時に適用する.

簡易ブリン帯は,閉盘価格を使用するSMA計算の中軌道,強化ブリン帯は,閉盘価格を使用するEMA計算中軌道.

上下軌道は中軌道±N倍標準差で計算される.

策略は,ブリン帯の上下軌道間の距離 ((spread) によってトレンドを判断し,スプレッドが設定された値より小さいときは,トレンド区間に入っていることを示し,トレンドフォロー取引を行うことができます。

具体的には,価格が下位に近づく時に多買し,上位に近づく時に平売りする. ストップ・ロスは固定ストップ・パーセンテージで,同時にトラッキング・ストップを有効にするオプションがある.

目標利益は,中線または上線近くの平仓を選択することによる.

この戦略は,損失を防ぐために,利益を確保する場合にのみ売却することを選択することもできます.

優位分析

この戦略の利点は以下の通りです.

  1. 二重ブリン帯の統合により,意思決定の効率化

シンプルブリンバンドと強化ブリンバンドを適用し,2種類のブリンバンドの効果を比較し,より優れたバージョンを選択し,意思決定の効率性を向上させる.

  1. ブリン帯域通路の幅による傾向の程度

ブリン帯の通路が狭くなると,トレンドの動きが表示され,トレンドの動きに合わせて取引が成功する確率は高くなります.

  1. フレキシブルな止損方法

固定パーセンテージのストップを導入し,単発損失を制御する.また,中道または上道近くのストップを選択し,トラッキングストップを有効にすることで,より多くの利益をロックする.

  1. 損失を防ぐための保護機構

利潤が確保された場合にのみ売却すれば,損失の拡大を防ぐことができる.

リスク分析

この戦略には以下のリスクもあります.

  1. リスクの撤回

トレンドトレーディングは,それ自体には,反転のリスクがあり,継続的な損失の心理的プレッシャーが必要である.

  1. 震災のリスク

ブリン帯の通路が広いとき,市場が揺れ込む可能性を示し,この戦略は取引に効果が悪くて,トレンドが再形成されるのを待って取引を一時停止する必要がある.

  1. ストップダメージが発火するリスク

固定パーセンテージストープは過度に激進的であり,ATRストープのようなより穏やかなストープに調整する必要がある.

最適化の方向

この戦略は以下の点で最適化できます.

  1. ブリン帯のパラメータを最適化

異なる平均線パラメータ,標準差倍数をテストして,異なる市場に適したブリン帯パラメータの組み合わせを見つけることができる.

  1. 他の指標と組み合わせたフィルタリング

ブリン帯の信号に基づいて,MACD,KDなどの指標のフィルタリングを加え,振動市場の取引を減らすことができる.

  1. ストップ・ストップ・ロスの最適化

異なる動きのストップをテストしたり,振幅,ATRなどの指標に基づいてストップを最適化したりできます.

  1. 資金管理の最適化

各取引のポジション管理を最適化し,異なる補償戦略をテストする.

要約する

この戦略は,双重ブリン帯の指標の優位性を統合し,ブリン帯通路の幅の判断によりトレンドの程度を判断し,トレンドの間,低吸高抛のトラッキング取引を行う.同時に,科学的ストップダストメカニズムを設定してリスクを制御する.この戦略は,パラメータの最適化と他の指標のフィルタリングと組み合わせることで,さらに安定性を向上させることができる.

ストラテジーソースコード
/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 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/
// © JCGMarkets 

//@version=4
strategy("B.Bands | Augmented | Intra-range | Long-Only", shorttitle = "BB|A|IR|L", initial_capital=5000, commission_value=0.075, slippage = 1, overlay = true)

//Technical Indicators Data
show_simp   = input(false, title="Trade on Simple Bollinger Bands ", type= input.bool, group="Select Strategy System")
show_augm   = input(true, title="Trade on Augmented Bollinger Bands", type= input.bool, group="Select Strategy System") 
periods     = input(20, title="Periods for Moving Average", type =input.integer, minval = 2, step = 1, group="Technical Inputs")
std         = input(2, title="Std", type = input.float, minval=0.1 , step = 0.1, group="Technical Inputs")

// Strategy data
max_spread_bb   = input(20000.0, title="Max Spread Tolerance Beetween Bands", type=input.float, step=0.1, group="Strategy Inputs")
entry_source    = input(close, title="Entry data source", type=input.source, group="Strategy Inputs")
exit_source     = input(high, title="Exit data source", type=input.source, group="Strategy Inputs")
take_profit     = input("middle", title = "Profit to band:", options = ["middle", "opposite"], group="Strategy Inputs")
stop_loss       = input(3.00, title="Stop Loss %", type=input.float, step=0.05, group="Strategy Inputs")
trailing        = input(false, title="Activate trailing stop?", type = input.bool, group="Strategy Inputs")
stop_perc       = input(6.00, title="Trailing %", type=input.float, step=0.125, group="Strategy Inputs") * 0.01
sell_profit     = input(false, title="Only sell in profit (Stop Loss still active) ", type= input.bool, group="Strategy Inputs")


var SL = 0.0
var SLT= 0.0


//Simple BB Calculation -> adapt if needed with different std for upper-lower, sma-ema, etc 
middle_sim = sma(close, periods)

//Augmented BB Calculation -> adapt if needed with different std for upper lower, etc
middle_augm  = ema(close, periods)
middle_upp = ema(high, periods)
middle_low = ema(low, periods)

//Multiplier
dev      = stdev(close, periods) * std

//Upper & Lower Bands
upper = (middle_sim + dev)
lower = (middle_sim - dev)

//Augmented Bands
upper_augm = (middle_upp + dev)
lower_augm = (middle_low - dev)

//Bands Spread
spread   = upper - lower
spread_augm   = upper_augm - lower_augm

//From date
filter_from    =   input(  true,    title="===> From", group="Date Control")
from_y         =   input(  2010,    title = "from year", group="Date Control")
from_m         =   input(     1,    title = "from month", minval =1, maxval=12, group="Date Control")
from_d         =   input(     1,    title = "from day",  minval=1, maxval=31, group="Date Control")

//To date
filter_to   =    input( true,   title="===> To", group="Date Control")
to_y        =    input( 2030,   title = "To year", group="Date Control")
to_m        =    input(    1,   title = "To month", minval =1, maxval=12, group="Date Control")
to_d        =    input(    1,  title = "To day",  minval=1, maxval=31, group="Date Control")

// Date Condition
In_date() =>  true

in_position = strategy.position_size > 0 

// Trailing stop 
SLT := if in_position and In_date()
    stop_inicial = entry_source * (1 - stop_perc)
    max(stop_inicial, SLT[1])
else
    0

slts = (low <= SLT) and (trailing == true)


//Essential Trade logics
entry_long = (entry_source <= lower) and (spread < max_spread_bb)
entry_long_augm = (entry_source <= lower_augm) and (spread_augm < max_spread_bb)

// Simple Bollinger Conditions

if (not in_position and show_simp and In_date())
    if entry_long
        // Trigger buy order
        position_size = round( strategy.equity / close ) // All available equity for this strategy example
        strategy.entry("Entry", strategy.long, qty = position_size )
        SL := close * (1 - (stop_loss / 100)) // You could determine wether or not implement stop loss with bool input and if condition here.


if in_position and show_simp and not sell_profit and In_date()
    //Exits if not sell in profit
    if take_profit == "middle" 
        strategy.exit("Target", "Entry", limit = middle_sim, stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry", limit = upper, stop = SL, comment="Exit")    

if in_position and show_simp and sell_profit and In_date()
    //Exits if sell in profit
    if take_profit == "middle" 
        strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? middle_sim: na), stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry", limit = (strategy.openprofit > 0 ? upper: na), stop = SL, comment="Exit")    



if in_position and show_simp and slts and In_date()
    //Trailing activation
    strategy.close("Entry", comment="SLT")

if not In_date()
    //Exit due out of date range
    strategy.close("Entry", comment="Out of date range")



// Augmented Bollinger Conditions

if (not in_position and show_augm and In_date()) 
    if entry_long_augm
        // Trigger buy order
        position_size = round( strategy.equity / close )
        strategy.entry("Entry_A", strategy.long, qty = position_size )
        SL := close * (1 - (stop_loss / 100) )

if in_position and show_augm and not sell_profit and In_date()
    //Exits and not sell in profit
    if take_profit == "middle"
        strategy.exit("Target", "Entry_A", limit = middle_augm, stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry_A", limit = upper_augm, stop = SL, comment="Exit")            
        

if in_position and show_augm and sell_profit and In_date() 
    //Exit only in profit
    if take_profit == "middle"
        strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? middle_augm:na), stop = SL, comment="Exit")
    if take_profit == "opposite"
        strategy.exit("Target", "Entry_A", limit = (strategy.openprofit > 0 ? upper_augm: na) , stop = SL, comment="Exit") 


if in_position  and show_augm and slts and In_date()
    //Trigger trailing
    strategy.close("Entry_A", comment="SLT")
    
if not In_date()
    //Out of date trigger
    strategy.close("Entry_A", comment= "Out of date range")




// Plotting

plot(in_position ? SL > 0 ? SL : na : na , style = plot.style_circles, color = color.red, title = "Stop Loss")
plot(in_position ? trailing ? SLT > 0 ? SLT : na : na : na , style = plot.style_circles, color = color.blue, title = "Trailing Stop" )

s = plot(show_simp ? upper : na , color = color.aqua)
plot(show_simp ? middle_sim : na , color=color.red)
i = plot(show_simp ? lower : na , color = color.aqua)
fill(s,i, color=color.new(color.aqua,90))


plot(show_augm ? middle_augm : na , color=color.blue)
s_a = plot( show_augm ? upper_augm : na, color=color.orange)
i_a = plot( show_augm ? lower_augm : na, color= color.orange)
fill(s_a,i_a, color=color.new(color.orange, 90))