適応性波動性ブレイクアウト取引戦略

作者: リン・ハーンチャオチャン開催日:2023年4月12日14時34分13秒
タグ:

img

概要

この戦略は,価格突破点に基づいて市場動向を特定し,短期的な価格逆転機会を把握するために適応指標を使用して全体的な傾向を決定する.価格はベースラインチャネルを突破したとき,購入/売却信号を生成する.この戦略は,非常に不安定な暗号通貨の取引に適している.

戦略の論理

  1. 極端な価格点をチャネル境界として識別します.価格が新しい高値や低値に達すると,これらのポイントをチャネル境界として設定します.
  2. アダプティブ・ボラティリティ・MA指標を計算し,全体的なトレンド方向を決定する.より高いMA値は,現在市場が波動的段階にあることを示します.
  3. 価格がチャネルの上位を突破すると 購入信号を生成し 価格がチャネル下位を突破すると 販売信号を生成します
  4. ロングポジションのストップ・ロスはエントリー価格より1%下です.

利点分析

  1. 価格チャネルは適応性があり,トレンド逆転点を正確に決定することができます.
  2. 波動性指標は,全体的な傾向を判断し,波動性のある市場の全体像を見逃すのを避けます.
  3. 逆転戦略として,短期的な価格ブランスを捕捉するのに適しています.

リスク分析

  1. 持続的なダウントレンドでは,複数のストップ・ロスは発生し,大きな損失をもたらす可能性があります.
  2. 取引コストを増加させる. 取引コストを増加させる.
  3. 手動で入場時間を決定する必要があります. 完全に自動化された取引には過剰なリスクがあります.

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

  1. 総合的な傾向をより良く判断するために MA パラメータを最適化します.
  2. 容積が尽きるシナリオでは逆転信号を避けるために容積指標を組み込む.
  3. 動的パラメータ最適化を可能にするために機械学習モデルを追加します

概要

この戦略の全体的な論理は明確で,いくつかの実用的な価値があります.しかし,特定の市場条件で大きな損失を防ぐために,取引リスクは依然として制御されるべきです.次のステップには,戦略パラメータと取引信号をより信頼性のあるものにするために,全体的な枠組み,指標パラメータ,リスク制御などの複数の次元を最適化することが含まれます.


/*backtest
start: 2023-11-03 00:00:00
end: 2023-12-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version = 4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingGroundhog



//  ||---   Cash & Date:
cash_amout = 10000
pyramid_val = 1
cash_given_per_lot = cash_amout/pyramid_val
startDate = input(title="Start Date",defval=13)
startMonth = input(title="Start Month",defval=9)
startYear = input(title="Start Year",defval=2021)
afterStartDate = (time >= timestamp(syminfo.timezone,startYear, startMonth, startDate, 0, 0))
//  ||------------------------------------------------------------------------------------------------------



//  ||---   Strategy:
strategy(title="TradingGroundhog - Strategy & Fractal V1 - Short term", overlay=true, max_bars_back = 4000, max_labels_count=500, commission_type=strategy.commission.percent, commission_value=0.00,default_qty_type=strategy.cash, default_qty_value= cash_given_per_lot, pyramiding=pyramid_val)
//  ||------------------------------------------------------------------------------------------------------



//  ||---   Fractal Recognition:
filterBW = input(true, title="filter Bill Williams Fractals:")
filterFractals = input(true, title="Filter fractals using extreme method:")
length = input(2, title="Extreme Window:")
regulartopfractal = high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0]
regularbotfractal = low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0]
billwtopfractal = filterBW ? false : (high[4] < high[2] and high[3] < high[2] and high[2] > high[1] and high[2] > high[0] ? true : false)
billwbotfractal = filterBW ? false : (low[4] > low[2] and low[3] > low[2] and low[2] < low[1] and low[2] < low[0] ? true : false)
ftop = filterBW ? regulartopfractal : regulartopfractal or billwtopfractal
fbot = filterBW ? regularbotfractal : regularbotfractal or billwbotfractal
topf = ftop ? high[2] >= highest(high, length) ? true : false : false
botf = fbot ? low[2] <= lowest(low, length) ? true : false : false
filteredtopf = filterFractals ? topf : ftop
filteredbotf = filterFractals ? botf : fbot
//  ||------------------------------------------------------------------------------------------------------



//  ||---   V1 : Added Swing High/Low Option
ShowSwingsHL = input(true)
highswings = filteredtopf == false ? na : valuewhen(filteredtopf == true, high[2], 2) < valuewhen(filteredtopf == true, high[2], 1) and valuewhen(filteredtopf == true, high[2], 1) > valuewhen(filteredtopf == true, high[2], 0)
lowswings = filteredbotf == false ? na : valuewhen(filteredbotf == true, low[2], 2) > valuewhen(filteredbotf == true, low[2], 1) and valuewhen(filteredbotf == true, low[2], 1) < valuewhen(filteredbotf == true, low[2], 0)
//---------------------------------------------------------------------------------------------------------



//  ||---   V2 : Plot Lines based on the fractals.
showchannel = input(true)
//---------------------------------------------------------------------------------------------------------



//  ||---   ZigZag:
showZigZag = input(true)
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal computation:
istop = filteredtopf ? true : false
isbot = filteredbotf ? true : false
topcount = barssince(istop)
botcount = barssince(isbot)
vamp = input(title="VolumeMA",  defval=2)
vam = sma(volume, vamp)
fractalup = 0.0
fractaldown = 0.0
up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup :=  up ? high[3] : fractalup[1] 
fractaldown := down ? low[3] : fractaldown[1]
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal save:
fractaldown_save = array.new_float(0)
for i = 0 to 4000
    if array.size(fractaldown_save) < 3
        if array.size(fractaldown_save) == 0
            array.push(fractaldown_save, fractaldown[i])
        else 
            if fractaldown[i] != array.get(fractaldown_save, array.size(fractaldown_save)-1)
                array.push(fractaldown_save, fractaldown[i])
if array.size(fractaldown_save) < 3
    array.push(fractaldown_save, fractaldown)
    array.push(fractaldown_save, fractaldown)
fractalup_save = array.new_float(0)
for i = 0 to 4000
    if array.size(fractalup_save) < 3
        if array.size(fractalup_save) == 0
            array.push(fractalup_save, fractalup[i])
        else 
            if fractalup[i] != array.get(fractalup_save, array.size(fractalup_save)-1)
                array.push(fractalup_save, fractalup[i])
if array.size(fractalup_save) < 3
    array.push(fractalup_save, fractalup)
    array.push(fractalup_save, fractalup)
Bottom_1 = array.get(fractaldown_save,  0)
Bottom_2 = array.get(fractaldown_save,  1)
Bottom_3 = array.get(fractaldown_save,  2)
Top_1 = array.get(fractalup_save, 0)
Top_2 = array.get(fractalup_save, 1)
Top_3 = array.get(fractalup_save, 2)
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal Buy Sell Signal:
bool Signal_Test = false
bool Signal_Test_OUT_TEMP = false
var Signal_Test_TEMP = false
longLossPerc = input(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=0.01) * 0.01
if filteredbotf and open < Bottom_1 and (Bottom_1 - open) / Bottom_1 >= longLossPerc
    Signal_Test := true
if filteredtopf and open > Top_1
    Signal_Test_TEMP := true
if filteredtopf and Signal_Test_TEMP
    Signal_Test_TEMP := false
    Signal_Test_OUT_TEMP := true
//----------------------------------------------------------------------------------------------------------



//  ||---   Plotting:
//plotshape(filteredtopf, style=shape.triangledown, location=location.abovebar, color=color.red, text="•", offset=0)
//plotshape(filteredbotf, style=shape.triangleup, location=location.belowbar, color=color.lime, text="•", offset=0)
//plotshape(ShowSwingsHL ? highswings : na, style=shape.triangledown, location=location.abovebar, color=color.maroon, text="H", offset=0)
//plotshape(ShowSwingsHL ? lowswings : na, style=shape.triangleup, location=location.belowbar, color=color.green, text="L", offset=0)
plot(showchannel ? (filteredtopf ? high[2] : na) : na, color=color.black, offset=0)
plot(showchannel ? (filteredbotf ? low[2] : na) : na, color=color.black, offset=0)
plot(showchannel ? (highswings ? high[2] : na) : na, color=color.black, offset=-2)
plot(showchannel ? (lowswings ? low[2] : na) : na, color=color.black, offset=-2)
plotshape(Signal_Test, style=shape.flag, location=location.belowbar, color=color.yellow, offset=0)
plotshape(Signal_Test_OUT_TEMP, style=shape.flag, location=location.abovebar, color=color.white, offset=0)
//----------------------------------------------------------------------------------------------------------



//  ||---   Buy And Sell:
strategy.entry(id="Long", long=true, when = Signal_Test and afterStartDate)
strategy.close_all(when = Signal_Test_OUT_TEMP and afterStartDate)
//----------------------------------------------------------------------------------------------------------    
    

もっと