移動平均とボラティリティに基づくトレンドフォロー戦略


作成日: 2023-09-21 21:32:40 最終変更日: 2023-09-21 21:32:40
コピー: 0 クリック数: 658
1
フォロー
1617
フォロワー

概要

この戦略は,平均線,ブリン帯,時間帯量などの複数の指標を総合的に使用し,価格トレンドの開始と終了を識別し,トレンド追跡操作を行う. 戦略は,複数の指標によって確認され,偽突破を効果的にフィルターすることができます.

戦略原則

戦略は以下の重要なステップからなる:

  1. 速平均線と遅平均線を計算する.平均線は,閉盘価格ではなくVWAPを使用して計算され,実際の取引価格をより正確に反映する.

  2. 平均線の平均値を計算し,その平均値に基づいてブリン帯を描きます.ブリン帯は価格変動率が拡大したかどうかを判断し,トレンドを開始するように指示します.

  3. 時間帯量 (TSV) の指標を導入し,取引量が拡大しているかどうかを判断し,傾向があることを確認する.

  4. 高速平均線で低速平均線を横切ると,価格がブリン上線より高く,TSVが0より大きいとき,買入シグナルが生成される.逆に,売出シグナルが生成される。

  5. 平均線撤退とブリン下線を止損平仓信号として使用する.

戦略的優位性

  • 複数の指標を使用して確認し,偽突破を効果的にフィルターし,トレンドの始まりを識別します.

  • 平均線計算方法は,実際の取引価格をより正確に反映します.

  • 波動率指数と組み合わせたトレンドの有無

  • 取引量指数増加,トレンドの確認

  • 合理的なストップ・アンド・ストップ基準を設定し,リスクを制御する

  • パラメータは,最適な状態に柔軟に調整することができます

戦略リスク

  • 複数の指標の組み合わせで判断し,パラメータの最適化が難しい問題

  • 均質線とブリン帯の両方に遅延があり,十分なタイミングで止まりません.

  • 時間帯量指標はパラメータ設定に敏感であり,異なる市場によって調整する必要があります.

  • 市場をまとめると,偽信号が多く発生する可能性があります.

  • 取引コストの影響を考慮しない場合,実際の利益と損失は回測結果より弱くなる.

戦略最適化の方向性

  • 機械学習でパラメータの組み合わせを 自動的に最適化してみる

  • 動的に移動するストップまたはストップを追跡して,利益をよりよくロックします.

  • 取引量エネルギー指標を導入し,誤った取引を避ける

  • 波動理論と組み合わせて,現在トレンドの早期,中期,後期を判断し,動的に戦略パラメータを調整する

  • 実際の取引コストの影響を考慮し,コスト効率を制御するために最小のストップ幅を設定します.

要約する

この戦略は,多種多様な指標を総合的に考慮して,トレンド認識の優れた能力を提供し,実際のトレンドの開始と終了を効果的に判断できます.パラメータ最適化,ストップ・ロスの最適化,フィルターの最適化により,戦略の安定性をさらに向上させることができます.しかし,全体として,トレンドを追跡する戦略として,その撤回と損失の割合は,依然として一定のリスクを負う必要があります.

ストラテジーソースコード
/*backtest
start: 2022-09-14 00:00:00
end: 2023-09-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4

// Credits

// "Vwap with period" code which used in this strategy to calculate the leadLine was written by "neolao" active on https://tr.tradingview.com/u/neolao/
// "TSV" code which used in this strategy was written by "liw0" active on https://www.tradingview.com/u/liw0. The code is corrected by "vitelot" December 2018.

strategy("HYE Trend Hunter [Strategy]", overlay = true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, commission_value = 0.025, pyramiding = 0)
  
// Strategy inputs 

slowtenkansenPeriod = input(9, minval=1, title="Slow Tenkan Sen VWAP Line Length", group = "Tenkansen / Kijunsen")
slowkijunsenPeriod = input(26, minval=1, title="Slow Kijun Sen VWAP Line Length", group = "Tenkansen / Kijunsen")
fasttenkansenPeriod = input(5, minval=1, title="Fast Tenkan Sen VWAP Line Length", group = "Tenkansen / Kijunsen")
fastkijunsenPeriod = input(13, minval=1, title="Fast Kijun Sen VWAP Line Length", group = "Tenkansen / Kijunsen")
BBlength = input(20, minval=1, title= "Bollinger Band Length", group = "Bollinger Bands")
BBmult = input(2.0, minval=0.001, maxval=50, title="Bollinger Band StdDev", group = "Bollinger Bands")
tsvlength  = input(13, minval=1, title="TSV Length", group = "Tıme Segmented Volume")
tsvemaperiod = input(7, minval=1, title="TSV Ema Length", group = "Tıme Segmented Volume")

// Make input options that configure backtest date range  
 
startDate = input(title="Start Date", type=input.integer,
     defval=1, minval=1, maxval=31, group = "Backtest Range")
startMonth = input(title="Start Month", type=input.integer,
     defval=1, minval=1, maxval=12, group = "Backtest Range")
startYear = input(title="Start Year", type=input.integer,
     defval=2000, minval=1800, maxval=2100, group = "Backtest Range")

endDate = input(title="End Date", type=input.integer, 
     defval=31, minval=1, maxval=31, group = "Backtest Range")
endMonth = input(title="End Month", type=input.integer,
     defval=12, minval=1, maxval=12, group = "Backtest Range") 
endYear = input(title="End Year", type=input.integer,
     defval=2021, minval=1800, maxval=2100, group = "Backtest Range")
     
inDateRange =  true

//Slow Tenkan Sen Calculation

typicalPriceTS = (high + low + close) / 3
typicalPriceVolumeTS = typicalPriceTS * volume
cumulativeTypicalPriceVolumeTS = sum(typicalPriceVolumeTS, slowtenkansenPeriod)
cumulativeVolumeTS = sum(volume, slowtenkansenPeriod)
slowtenkansenvwapValue = cumulativeTypicalPriceVolumeTS / cumulativeVolumeTS

//Slow Kijun Sen Calculation

typicalPriceKS = (high + low + close) / 3
typicalPriceVolumeKS = typicalPriceKS * volume
cumulativeTypicalPriceVolumeKS = sum(typicalPriceVolumeKS, slowkijunsenPeriod)
cumulativeVolumeKS = sum(volume, slowkijunsenPeriod)
slowkijunsenvwapValue = cumulativeTypicalPriceVolumeKS / cumulativeVolumeKS

//Fast Tenkan Sen Calculation

typicalPriceTF = (high + low + close) / 3
typicalPriceVolumeTF = typicalPriceTF * volume
cumulativeTypicalPriceVolumeTF = sum(typicalPriceVolumeTF, fasttenkansenPeriod)
cumulativeVolumeTF = sum(volume, fasttenkansenPeriod)
fasttenkansenvwapValue = cumulativeTypicalPriceVolumeTF / cumulativeVolumeTF

//Fast Kijun Sen Calculation

typicalPriceKF = (high + low + close) / 3
typicalPriceVolumeKF = typicalPriceKS * volume
cumulativeTypicalPriceVolumeKF = sum(typicalPriceVolumeKF, fastkijunsenPeriod)
cumulativeVolumeKF = sum(volume, fastkijunsenPeriod)
fastkijunsenvwapValue = cumulativeTypicalPriceVolumeKF / cumulativeVolumeKF

//Slow LeadLine Calculation
 
lowesttenkansen_s = lowest(slowtenkansenvwapValue, slowtenkansenPeriod)
highesttenkansen_s = highest(slowtenkansenvwapValue, slowtenkansenPeriod)

lowestkijunsen_s = lowest(slowkijunsenvwapValue, slowkijunsenPeriod)
highestkijunsen_s = highest(slowkijunsenvwapValue, slowkijunsenPeriod)

slowtenkansen = avg(lowesttenkansen_s, highesttenkansen_s)
slowkijunsen = avg(lowestkijunsen_s, highestkijunsen_s)
slowleadLine = avg(slowtenkansen, slowkijunsen)

//Fast LeadLine Calculation
 
lowesttenkansen_f = lowest(fasttenkansenvwapValue, fasttenkansenPeriod)
highesttenkansen_f = highest(fasttenkansenvwapValue, fasttenkansenPeriod)

lowestkijunsen_f = lowest(fastkijunsenvwapValue, fastkijunsenPeriod)
highestkijunsen_f = highest(fastkijunsenvwapValue, fastkijunsenPeriod)

fasttenkansen = avg(lowesttenkansen_f, highesttenkansen_f)
fastkijunsen = avg(lowestkijunsen_f, highestkijunsen_f)
fastleadLine = avg(fasttenkansen, fastkijunsen)

// BBleadLine Calculation

BBleadLine = avg(fastleadLine, slowleadLine)

// Bollinger Band Calculation
 
basis = sma(BBleadLine, BBlength)
dev = BBmult * stdev(BBleadLine, BBlength)
upper = basis + dev
lower = basis - dev

// TSV Calculation

tsv = sum(close>close[1]?volume*(close-close[1]):close<close[1]?volume*(close-close[1]):0,tsvlength)
tsvema = ema(tsv, tsvemaperiod)

// Rules for Entry & Exit  

if(fastleadLine > fastleadLine[1] and slowleadLine > slowleadLine[1] and tsv > 0 and tsv > tsvema and close > upper and inDateRange)
    strategy.entry("BUY", strategy.long)
 
if(fastleadLine < fastleadLine[1] and slowleadLine < slowleadLine[1])
    strategy.close("BUY")

// Plots 

colorsettingS = input(title="Solid Color Slow Leadline", defval=false, type=input.bool)
plot(slowleadLine, title = "Slow LeadLine", color = colorsettingS ? color.aqua : slowleadLine > slowleadLine[1] ? color.green : color.red, linewidth=3)

colorsettingF = input(title="Solid Color Fast Leadline", defval=false, type=input.bool)
plot(fastleadLine, title = "Fast LeadLine", color = colorsettingF ? color.orange : fastleadLine > fastleadLine[1] ? color.green : color.red, linewidth=3)

p1 = plot(upper, "Upper BB", color=#2962FF)
p2 = plot(lower, "Lower BB", color=#2962FF)
fill(p1, p2, title = "Background", color=color.blue)