段階的なBB KC トレンド戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-26 15:10:41
タグ:

img

概要

この戦略は,市場動向を特定するためにボリンジャーバンドとケルターチャネル信号の組み合わせを使用する.ボリンジャーバンドは,価格変動範囲に基づいてチャネルを定義する技術分析ツールです.ケルターチャネル信号は,サポートまたはレジスタンスレベルを決定するために価格変動とトレンドを組み合わせます.この戦略は,ボリンジャーバンドとケルターチャネルの間に黄金十字が起こるかどうかを判断することによって,両方の指標の利点を利用し,長期と短期の機会を見つけることができます.また,トレードボリュームを組み込み,シグナルの有効性を検証し,トレンドの開始を効果的に特定し,無効な信号のフィルタリングを最大化することができます.

戦略の原則

  1. 中間,上,下ボリンジャー帯を20期間にわたって計算する.帯幅は2つの標準偏差で定義される.
  2. 中間,上,下ケルトナーチャネルを 20 期間にわたって計算します.チャネル幅は,実際の範囲の 2.2 倍と定義されます.
  3. ケルター・チャネルの上線がボリンジャー・バンド上線を横切って,ボリュームが10期間の移動平均値より大きくなったら,ロングします.
  4. ケルター・チャネルの下線がボリンジャー・バンドの下線を横切って,ボリュームが10期間の移動平均値より大きいとき,ショートします.
  5. 入力から20バー後に出口信号が発せられない場合は すべてのポジションを閉じる.
  6. ロング・トレードでは1.5%,ショート・トレードでは-1.5%のストップ・ロスを設定します. ロング・トレードでは2%のトレリング・ストップ,ショート・トレードでは-2%のトレリング・ストップを設定します.

この戦略は主にボリンジャー帯をベースに波動範囲と勢いを判断する.ケルトナーチャネルは類似した特徴が異なるパラメータがあるため検証ツールとして機能する.これらの2つの指標を組み合わせることで信号の正確性が向上する.取引量を組み込むことも,無効な信号をフィルタリングするのに役立ちます.

強度分析

  1. ボリンジャー帯とケルトナーチャネルの組み合わせの利点を利用し,信号の精度を向上させる.
  2. 取引量によるフィルタリングは,頻繁にラインタッチする不正な信号を減らす.
  3. プログラムされたストップ・ロストとトレーリング・ストップメカニズムによる効果的なリスク管理
  4. 無効なシグナルで強要された利益を取ることから 迅速な出口と損失を制限する

リスク分析

  1. ボリンガー帯とケルターチャネルは 移動平均値と変動率に基づいています. 変動市場では 誤った信号を生成することができます.
  2. 複合メカニズムがないことは,複数のストップアウトが過大損失につながる可能性があることを意味します.
  3. 逆転シグナルが頻繁に見られます パラメータの調整によりトレンド機会が逃れることがあります

ストップ・ロスの範囲を広げたり MACD のような確認指標を追加したりすることで 誤った信号によるリスクが軽減できます

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

  1. テストパラメータが戦略回帰に与える影響,長さ,標準偏差倍数など
  2. 信号確認のための他の指標を追加します.例えば,KDJ,MACD.
  3. 自動パラメータ最適化のために機械学習を使用します

概要

この戦略は,トレードボリュームによって確認されるトレンドを特定するためにボリンジャーバンドとケルトナーチャネルを組み合わせます.パラメータの最適化や指標を追加などのさらなる強化により,より多くの市場体制のために強化されます.理解しやすくカスタマイズ可能なトレード戦略として強力な実行可能性があります.


/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
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/
// © jensenvilhelm

//@version=5
strategy("BB and KC Strategy", overlay=true)

// Define the input parameters for the strategy, these can be changed by the user to adjust the strategy
kcLength = input.int(20, "KC Length", minval=1) // Length for Keltner Channel calculation
kcStdDev = input.float(2.2, "KC StdDev") // Standard Deviation for Keltner Channel calculation
bbLength = input.int(20, "BB Length", minval=1) // Length for Bollinger Bands calculation
bbStdDev = input.float(2, "BB StdDev") // Standard Deviation for Bollinger Bands calculation
volumeLength = input.int(10, "Volume MA Length", minval=1) // Length for moving average of volume calculation
stopLossPercent = input.float(1.5, "Stop Loss (%)") // Percent of price for Stop loss 
trailStopPercent = input.float(2, "Trail Stop (%)") // Percent of price for Trailing Stop
barsInTrade = input.int(20, "Bars in trade before exit", minval = 1) // Minimum number of bars in trade before considering exit

// Calculate Bollinger Bands and Keltner Channel
[bb_middle, bb_upper, bb_lower] = ta.bb(close, bbLength, bbStdDev) // Bollinger Bands calculation
[kc_middle, kc_upper, kc_lower] = ta.kc(close, kcLength, kcStdDev) // Keltner Channel calculation

// Calculate moving average of volume
vol_ma = ta.sma(volume, volumeLength) // Moving average of volume calculation

// Plotting Bollinger Bands and Keltner Channels on the chart
plot(bb_upper, color=color.red) // Bollinger Bands upper line
plot(bb_middle, color=color.blue) // Bollinger Bands middle line
plot(bb_lower, color=color.red) // Bollinger Bands lower line
plot(kc_upper, color=color.rgb(105, 255, 82)) // Keltner Channel upper line
plot(kc_middle, color=color.blue) // Keltner Channel middle line
plot(kc_lower, color=color.rgb(105, 255, 82)) // Keltner Channel lower line

// Define entry conditions: long position if upper KC line crosses above upper BB line and volume is above MA of volume
// and short position if lower KC line crosses below lower BB line and volume is above MA of volume
longCond = ta.crossover(kc_upper, bb_upper) and volume > vol_ma // Entry condition for long position
shortCond = ta.crossunder(kc_lower, bb_lower) and volume > vol_ma // Entry condition for short position

// Define variables to store entry price and bar counter at entry point
var float entry_price = na // variable to store entry price
var int bar_counter = na // variable to store bar counter at entry point

// Check entry conditions and if met, open long or short position
if (longCond)
    strategy.entry("Buy", strategy.long) // Open long position
    entry_price := close // Store entry price
    bar_counter := 1 // Start bar counter
if (shortCond)
    strategy.entry("Sell", strategy.short) // Open short position
    entry_price := close // Store entry price
    bar_counter := 1 // Start bar counter

// If in a position and bar counter is not na, increment bar counter
if (strategy.position_size != 0 and na(bar_counter) == false)
    bar_counter := bar_counter + 1 // Increment bar counter

// Define exit conditions: close position if been in trade for more than specified bars
// or if price drops by more than specified percent for long or rises by more than specified percent for short
if (bar_counter > barsInTrade) // Only consider exit after minimum bars in trade
    if (bar_counter >= barsInTrade)
        strategy.close_all() // Close all positions
    // Stop loss and trailing stop
    if (strategy.position_size > 0)
        strategy.exit("Sell", "Buy", stop=entry_price * (1 - stopLossPercent/100), trail_points=entry_price * trailStopPercent/100) // Set stop loss and trailing stop for long position
    else if (strategy.position_size < 0)
        strategy.exit("Buy", "Sell", stop=entry_price * (1 + stopLossPercent/100), trail_points=entry_price * trailStopPercent/100) // Set stop loss and trailing stop for short position


もっと