自由帯域振動追跡戦略


作成日: 2024-02-04 10:28:24 最終変更日: 2024-02-04 10:28:24
コピー: 0 クリック数: 614
1
フォロー
1617
フォロワー

自由帯域振動追跡戦略

概要

この戦略の主な考えは,ATR指標に基づいて長線と短線のストップを計算し,価格がこれらのストップラインを突破すると取引シグナルを生成することです.それは同時にトレンド追跡と振動キャプチャの機能を持っています.

戦略原則

この策略はATR指標のN周期ATRを係数で掛けることで,長短両辺のストップラインを計算する.具体的計算式は以下の通りである.

长线止损 = 最高价 - ATR * 系数
短线止损 = 最低价 + ATR * 系数

価格が上昇して長線ストップラインを突破すると多めに,価格が下がって短線ストップラインを突破すると空白する.多めに空白した後は,価格の変動をリアルタイムで追跡してストップラインを移動する.

このATR波帯をストップポイントとして設定する方法は,ストップロスのリスクを保証する前提で価格トレンドを十分に捉えることができます.価格がより大きな突破が発生したときにシグナルを生成し,偽突破を効果的に排除できます.

優位分析

この戦略の最大の利点は,自動でストップを調整し,価格の動向を捉えながらリスクをコントロールできる点にある.具体的には以下の通りである.

  1. ATR指数に基づく浮動ストップ設定により,市場の変動に応じてストップ幅を調整し,単一損失を効果的に制御することができる.

  2. 突破式で信号を生成し,部分的なノイズを消し去り,頂上と底の追尾を回避する.

  3. 価格の変動を追跡するストップラインをリアルタイムで調整し,ストップを過度に緩やかにするのを防ぎ,より多くの利益をロックします.

リスク分析

この戦略にはいくつかのリスクがあり,主に止損位設定と信号発生方法に焦点を当てている.具体的リスクポイントは以下の通りである.

  1. ATR周期と係数が不適切である場合,ストップダメージがあまりにも広いか狭すぎる可能性があります.

  2. 突破信号は,トレンドの初期にチャンスを逃す可能性があります.

  3. トレンドの終末のストップ・ローズ・トラッキングは,完ぺきな退出ができないため,遅滞している可能性があります.

対策は,主にパラメータを調整して,止損を合理的にするか,または他の指標でトレンドやシグナルを判断することを補助する.

最適化の方向

この戦略は,以下の点で改善できる:

  1. リスクのコントロールをさらに進めるため,第2層のストップを設定します.

  2. 信号の質を向上させるため,他の指標と組み合わせてトレンドを判断します.

  3. 移動停止戦略を追加し,トレンドがさらに続くと収益を上げます.

  4. ATR周期と係数のパラメータを最適化して,実際の価格変動に近いストップをします.

要約する

この戦略は全体的に非常に実用的で,自動でストップ・ローズを調整してリスクを効果的にコントロールし,トレンド・トラッキングで良い利益を得ることができます.我々は,元の基礎をさらに他の分析方法と組み合わせて,戦略を最適化して改良し,より安定してスマートにすることができます.

ストラテジーソースコード
/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 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/
// © melihtuna
//@version=4
strategy("Chandelier Exit - Strategy",shorttitle="CE-STG" , overlay=true, default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000, currency=currency.USD, commission_value=0.03, commission_type=strategy.commission.percent)

length = input(title="ATR Period", type=input.integer, defval=22)
mult = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=false)
useClose = input(title="Use Close Price for Extremums ?", type=input.bool, defval=true)
highlightState = input(title="Highlight State ?", type=input.bool, defval=true)

atr = mult * atr(length)

longStop = (useClose ? highest(close, length) : highest(length)) - atr
longStopPrev = nz(longStop[1], longStop) 
longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop

shortStop = (useClose ? lowest(close, length) : lowest(length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

var color longColor = color.green
var color shortColor = color.red

longStopPlot = plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)

shortStopPlot = plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)

midPricePlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0, display=display.none, editable=false)

longFillColor = highlightState ? (dir == 1 ? longColor : na) : na
shortFillColor = highlightState ? (dir == -1 ? shortColor : na) : na
fill(midPricePlot, longStopPlot, title="Long State Filling", color=longFillColor)
fill(midPricePlot, shortStopPlot, title="Short State Filling", color=shortFillColor)


long_short = input(true, "Long-Short",type=input.bool, group="Strategy Settings")

start     = input(timestamp("2019-01-01"), "Date", type=input.time, group="Strategy Settings")
finish    = input(timestamp("2025-01-01"), "Date", type=input.time, group="Strategy Settings")   
window()  => true

slRatio=input(5, "Manuel Stop Loss Ratio", type=input.float, minval=0, group="Strategy Settings")
tpRatio=input(20, "Take Profit Ratio", type=input.float, minval=0, group="Strategy Settings")
tsStartRatio=input(10, "Trailing Stop Start Ratio", type=input.float, minval=0, group="Strategy Settings")
tsRatio=input(5, "Trailing Stop Ratio", type=input.float, minval=1, group="Strategy Settings")

lastBuyPrice = strategy.position_avg_price

diffHiPriceRatio = (high-lastBuyPrice)/lastBuyPrice*100
diffLoPriceRatio = (close-lastBuyPrice)/lastBuyPrice*100
posHiRatio=0.0
posHiRatio:= strategy.position_size > 0 ? diffHiPriceRatio > posHiRatio[1] ? diffHiPriceRatio : posHiRatio[1] : 0

s_diffHiPriceRatio = (low-lastBuyPrice)/lastBuyPrice*100
s_diffLoPriceRatio = (close-lastBuyPrice)/lastBuyPrice*100
s_posHiRatio=0.0
s_posHiRatio:= strategy.position_size < 0 ? s_diffLoPriceRatio < s_posHiRatio[1] ? s_diffLoPriceRatio : s_posHiRatio[1] : 0

strategy.entry("LONG", strategy.long, when = window() and buySignal)
strategy.close("LONG", when = window() and sellSignal)
strategy.close("LONG", when = diffLoPriceRatio<(slRatio*(-1)), comment="STOP-LONG")
strategy.close("LONG", when = diffHiPriceRatio>tpRatio, comment="TAKE-PROFIT-LONG")
strategy.close("LONG", when = ((posHiRatio[1]>tsStartRatio) and (posHiRatio[1]-diffHiPriceRatio)>tsRatio), comment="TRAILING-STOP-LONG")

if long_short
    strategy.entry("SHORT", strategy.short, when = window() and sellSignal)
    strategy.close("SHORT", when = window() and buySignal)
    strategy.close("SHORT", when = s_diffLoPriceRatio>(slRatio), comment="STOP-SHORT")
    strategy.close("SHORT", when = s_diffHiPriceRatio<(tpRatio*(-1)), comment="TAKE-PROFIT-SHORT")
    strategy.close("SHORT", when = ((s_posHiRatio[1]*(-1)>tsStartRatio) and ((s_posHiRatio[1]-s_diffLoPriceRatio))*(-1)>tsRatio), comment="TRAILING-STOP-SHORT")