ブレイクアウトボラティリティバンド取引戦略


作成日: 2023-10-07 09:59:11 最終変更日: 2023-10-07 09:59:11
コピー: 0 クリック数: 658
1
フォロー
1617
フォロワー

概要

この策略はブリン帯の突破原理に基づいており,価格が上線または下線を完全に突破したときに逆操作を行います.これは,異常な波動の後の回帰均等線の動きを捕捉し,効率的な利益を追求する積極的なトレーダーに適用されます.

原則

この戦略は,ブリン帯を利用して,現在の市場の波動範囲を定義する.価格が完全な陽線柱または陰線柱を形成し,ブリン帯を上線または下線に完全に突破すると,市場が高波動状態に達すると,価格は均線方向に逆転することを示している.

具体的には,戦略は20K線の閉盘価格でブリン帯の中軌道,上軌道,下軌道を計算する.価格が下軌道より低く,閉盤価格が開盤価格より低く,多行シグナルを生成する.価格が上軌道より高く,閉盤価格が開盤価格より高く,空行シグナルを生成する.その後,突破点をストップ・ロズとして利用し,中軌道を最初のターゲット価格平仓とする.

利点

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

  1. ブリン帯は市場波動の程度を判断し,異常状態を効果的に識別する.

  2. 突破点は,リスクを効果的にコントロールするストップポイントとして用いられる.

  3. 中道に戻るには,合理的な目標位置を設定し,過剰な追及と落下を避ける.

  4. 完全なK線フィルタリング偽突破,信号品質の向上.

  5. パラメータ設定が簡単で,実行や最適化も簡単です.

  6. 論理が明快で理解しやすく,コードが簡潔で優雅です.

リスク

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

  1. ブリン帯のパラメータが正しくない場合,失効する可能性があります.

  2. 突破は新しいトレンドの始まりであり,早期脱退の危険性があります.

  3. 中道目標位は保守的になり,持続的な利益を得られないかもしれない.

  4. 巨大突破口は完全に埋められず,滑り落ちる危険性があります.

  5. 金融危機の波動により,不必要な取引が頻発する可能性があります.

最適化の方向

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

  1. トレンドの強さ,パラメータの調整,取引の頻度などを評価する.

  2. 他の指標と組み合わせて最適な入学時間を決定する.

  3. ストップ・ローズは変動に応じて調整されます.

  4. 利潤を上げるために最初の目標の設定を最適化します.

  5. 収入の最適化のために再入学制度に加入する

  6. 信頼性を評価し,取引を誤ってしないようにする.

要約する

この戦略は,ブリン帯突破原理に基づくもので,短期利益を追求する積極的なトレーダーに適している.利点は,リスク管理が明確であること,欠点は,早期退場と利益のスペースが制限されていることである.パラメータ最適化,補助指標などの方法によって効果を向上させることができる.

ストラテジーソースコード
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 3h
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/
// © Bishnu103

//@version=4
strategy(title="Full Candle Outside BB [v1.0][Bishnu103]",shorttitle="OUTSIDE BB",overlay=true,calc_on_every_tick=true,backtest_fill_limits_assumption=2)

// ***********************************************************************************************************************
// input variables
buy_session         = input(title="Buy Session", type=input.session, defval="0915-1430")
exit_inraday        = input(title="Exit Intraday?", type=input.bool, defval=true)
entry_distance      = input(title="Entry distance from alert", minval=1, maxval=10, defval=3)
show_bb_switch      = input(title="Show BB", type=input.bool, defval=true)
//
bbLength            = input(title="BB Length", minval=1, defval=20)
bbStdDev            = input(title="BB StdDev", minval=1, defval=2)

// ***********************************************************************************************************************
// global variables
long_entry          = false
short_entry         = false
long_exit           = false
short_exit          = false

// variable values available across candles
var entry_price     = 0.0  
var sl_price        = 0.0
var exit_price      = 0.0
var candle_count    = 0

// ***********************************************************************************************************************
// function to return bollinger band values based on candle poition passed 
getBB(pos) => [mBB, uBB, lBB] = bb(close[pos], bbLength, bbStdDev)

// function returns true if current time is within intraday byuing session set in input
BarInSession(sess) => time(timeframe.period, sess) != 0

// ***********************************************************************************************************************
// strategy
//
// get current bb value
[mBB_0,uBB_0,lBB_0] = getBB(0)

// check if full candle outside upper BB
outside_uBB = low > uBB_0 and close <= open
outside_lBB = high < lBB_0 and close >= open

// ***********************************************************************************************************************
// entry conditions 
long_entry   := outside_lBB
short_entry  := outside_uBB

// keep candle count since the alert generated so that order can be cancelled after N number of candle calling it out as invalid alert
candle_count := candle_count + 1
if long_entry or short_entry
    candle_count    := 0

// ***********************************************************************************************************************
// risk management
//
// decide entry and sl price
if long_entry
    entry_price := high
    
if short_entry
    entry_price := low
    
if long_entry
    sl_price    := low
    
if short_entry
    sl_price    := high

// first exit is when price hits middle BB, gets updated for each candle based on it's middle BB value
exit_price  := mBB_0

// ***********************************************************************************************************************
// position sizing
price = if close[0] > 25000
    25000
else
    price = close[0]

qty = 25000/price

// ***********************************************************************************************************************
// entry
//if long_entry and strategy.position_size == 0
//    strategy.entry("BUY", strategy.long, qty, stop=entry_price, comment="BUY @ "+ tostring(entry_price)) 
if long_entry and strategy.position_size == 0
    strategy.order("BUY", strategy.long, qty, stop=entry_price, comment="BUY @ "+ tostring(entry_price))

//if short_entry and strategy.position_size == 0
//    strategy.entry("SELL", strategy.short, qty, stop=entry_price, comment="SELL @ "+ tostring(entry_price))
if short_entry and strategy.position_size == 0
    strategy.order("SELL", strategy.short, qty, stop=entry_price, comment="SELL @ "+ tostring(entry_price))

// cancel an order if N number of candles are completed after alert candle
strategy.cancel_all(candle_count > entry_distance)

// if current time is outside byuing session then do not enter intraday trade
strategy.cancel_all(timeframe.isintraday and not BarInSession(buy_session))

// ***********************************************************************************************************************
// exit
if strategy.position_size > 0
    strategy.cancel("EXIT at MBB", true)
    strategy.cancel("EXIT at SL", true)
    strategy.order("EXIT at MBB", strategy.short, abs(strategy.position_size), limit=exit_price, comment="EXIT TG @ "+ tostring(exit_price))
    strategy.order("EXIT at SL", strategy.short, abs(strategy.position_size), stop=sl_price, comment="EXIT SL @ "+ tostring(sl_price))

if strategy.position_size < 0
    strategy.cancel("EXIT at MBB", true)
    strategy.cancel("EXIT at SL", true)
    strategy.order("EXIT at MBB", strategy.long, abs(strategy.position_size), limit=exit_price, comment="EXIT TG @ "+ tostring(exit_price))
    strategy.order("EXIT at SL", strategy.long, abs(strategy.position_size), stop=sl_price, comment="EXIT SL @ "+ tostring(sl_price))

// if intraday trade, close the trade at open of 15:15 candle //!!!!!!!!!!!!!!!!!!!!! TO BE CORRECTED !!!!!!!!!!!!!!!!!!!!!!!
if timeframe.isintraday and exit_inraday and hour == 15 and minute == 00
    strategy.close("BUY",  when=strategy.position_size > 0, qty=strategy.position_size, comment="EXIT @ "+ tostring(close))
    strategy.close("SELL", when=strategy.position_size < 0, qty=strategy.position_size, comment="EXIT @ "+ tostring(close))

// ***********************************************************************************************************************
// plots    
//
// plot BB
[mBBp,uBBp,lBBp] = getBB(0)
p_mBB = plot(show_bb_switch ? mBBp : na, color=color.teal)
p_uBB = plot(show_bb_switch ? uBBp : na, color=color.teal)
p_lBB = plot(show_bb_switch ? lBBp : na, color=color.teal)
fill(p_uBB,p_lBB,color=color.teal,transp=95)