量に基づくダイナミックDCA戦略

作者: リン・ハーンチャオチャン,日付: 2024-04-12 17:12:07
タグ:QFLDCATPSLATRADXエイマSMARSIマックド

img

概要

この戦略は,価格ブレイクを使用するボリュームベースのダイナミックDCA戦略である. 最新の価格低値を特定し,価格がその低値を下回り,取引量が増加するとポジションを構築し始める. 価格が低下し続けると,戦略は,設定された総ポジション数に達するまで浮動損失の大きさに基づいて各ポジションの量を動的に調整する. 同時に,戦略は,歴史的な価格減少パーセントの中位値に基づいて利益を得る価格を設定する.

戦略の原則

  1. 最新の低価格を特定し,それをサポートレベルとして扱うために,ta.pivotlow() 関数を使用します.
  2. サポートレベルを突破した後の過去価格下落パーセントを計算し,安全距離と利益率の基準として中位数を取ります.
  3. 価格がサポートレベルを下回り,相対取引量は設定倍数より大きいとき,ポジション構築信号を起動します.
  4. 設定された総ポジション数に基づいて,総資金を等しい割合に分けます.ポジションが構築されるたびに,現在のポジション数に基づいてポジションサイズを動的に調整し,ポジションサイズが指数関数的に増加します.
  5. ポジション構築プロセス中に,変動損失が設定された値に達した場合,ポジションの総数に達するまでポジションを追加し続けます.
  6. 価格が引き上げられたら,すべてのポジションを閉じる.

戦略 の 利点

  1. ダイナミックなポジションサイズ調整: 価格の下落時の浮動損失に基づいてそれぞれのポジションのサイズをダイナミックに調整することで,戦略はリスクを制御し,価格がリバウンドしたときにもより大きな利益を実現します.
  2. 歴史データに基づくパラメータ設定: サポートレベルを突破した後の過去価格下落パーセントの中位値を計算し,安全距離と利益率の基準として使用することで,戦略パラメータは実際の市場状況により密接に一致します.
  3. ポジションの総数を制限する: ポジションの総数を設定することで,戦略は全体的なリスク露出を制御し,過剰なポジショニングによる過度の損失を回避する.

戦略リスク

  1. サポートレベルの失敗リスク: 市場が極端な状況に陥り,サポートレベルを突破した後も価格が急落し続ける場合,戦略のポジション増強メカニズムは重大な損失をもたらす可能性があります.
  2. パラメータ設定リスク: 戦略のパフォーマンスは,パラメータ設定に大きく依存します.パラメータが正しく設定されていない場合,戦略のパフォーマンスが低下する可能性があります.
  3. テイク・プロフィート価格設定リスク: テイク・プロフィート価格が高く設定された場合,潜在的な利益が失われる可能性があります. 低すぎると,ポジションが早すぎるほど閉じて,価格リバウンドを完全に活用する機会が失われます.

戦略の最適化方向

  1. より多くの指標を導入する: ポジション構築シグナルを決定する際に,RSIやMACDなどのより多くの技術指標を導入して信号の精度を向上させることができます.
  2. 資金管理の最適化:市場の変動や口座のリスク耐性などの要因に基づいて,リスクをよりよくコントロールするために,各ポジションの資金の割合を動的に調整する.
  3. アダプティブ・テイク・プロフィート・ストップ・ロース: 市場の変動の変化に基づいて,テイク・プロフィート・ストップ・ロースの割合を動的に調整し,市場の変化により良く適応します.

概要

この戦略は,ポジションのサイズを動的に調整し,歴史的なデータに基づいてパラメータを設定することで,価格リバウンド中により大きな利益を追求しながらリスクを制御することを目的としています.しかし,戦略のパフォーマンスはパラメータ設定と市場状況に大きく依存しており,リスクは依然として存在しています.より多くの指標を導入し,マネーマネジメントを最適化し,適応型テイク・プロフィートとストップ・ロスを使用することで,戦略のパフォーマンスをさらに改善することができます.


/*backtest
start: 2024-04-04 00:00:00
end: 2024-04-11 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AHMEDABDELAZIZZIZO

//@version=5

strategy("Qfl Dca strategy", overlay=true)

// Parameters
swing = input(3 , title = "Swing Points")
mediandropmult = input.float(1.1, "Median drop Mult", step=0.1 , tooltip = "The script Calculate The Median Drop for all last Bases That Was cracked you can Increase or decrease it")
floatinglossvalue = input(-5 , "Floating Loss" , tooltip = "Position Floating Loss to start firs DCA order")
num_orders = input(5 , "Number of all orders" , tooltip = " The number of orders is including the base order and the DCA orders the script will alculate every order qty based on the orders number So that the position size doubles with every order")
length = input(20, title="Length of relative volume" ,tooltip =  " the length of relative volume indicator")
mult = input(2.0, title="Volume Multiplier" , tooltip = "you can adjust the relative volume multiplier to find best parameter")
tpmult = input.float(1, step=0.1 ,title = "Take Profit Multiplier" ,tooltip =  " By default, the script is set to take profits based on the same median drop percent you can adjust it as you like")



// Pivot Calculation
p = ta.pivotlow(low, swing, swing)
v = ta.valuewhen(p, low[swing], 0)

// Variables
var float[] lows = array.new_float()
var float chn = na

// Calculate drops
if v < v[1]
    chn := (v[1] - v) / v[1] * 100
    if array.size(lows) < 4000
        array.push(lows, chn)
    else
        array.shift(lows)
        array.push(lows, chn)

mediandrop = array.avg(lows)
maxdrop = array.max(lows)
mindrop = array.min(lows)

// Table display
textcolor = color.white
// tabl = table.new(position=position.top_right, columns=4, rows=4)
// table.cell(table_id=tabl, column=1, row=1, text="Avg Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=2, row=1, text="Min Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=3, row=1, text="Max Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=1, row=2, text=str.tostring(mediandrop), width=10, text_color=textcolor)
// table.cell(table_id=tabl, column=2, row=2, text=str.tostring(mindrop), width=10, text_color=textcolor)
// table.cell(table_id=tabl, column=3, row=2, text=str.tostring(maxdrop), width=10, text_color=textcolor)

// Plot support
t = fixnan(ta.pivotlow(low, swing, swing))
plot(t, color=ta.change(t) ? na : #03f590b6, linewidth=3, offset=-(swing), title="Support")

// Calculate relative volume
avgVolume = ta.sma(volume, length)
relVolume = volume / avgVolume

// Base Activation
var bool baseisactive = na
if not na(p)
    baseisactive := true

// Buy Signal Calculation
buyprice = v * (1 - (mediandrop / 100) * mediandropmult)
signal = close <= buyprice and relVolume > mult and baseisactive

// Take Profit Calculation
tpsl = (mediandrop / 100)
tp = (strategy.position_avg_price * (1 + (tpsl * tpmult)))

// Position Sizing
capital_per_order(num_orders, equity) =>
    equity / math.pow(2, (num_orders - 1))

equity_per_order = capital_per_order(num_orders, strategy.equity)

qty_per_order(equity_per_order, order_number) =>
    equity_per_order * order_number / close

// Calculate floating loss
floatingLoss = ((close - strategy.position_avg_price) / strategy.position_avg_price) * 100

// Strategy Entries
if signal and strategy.opentrades == 0
    strategy.entry("Buy", strategy.long, qty=qty_per_order(equity_per_order, 1))
    baseisactive := false

for i = 1 to num_orders -1
    if signal and strategy.opentrades == i and floatingLoss <= floatinglossvalue
        strategy.entry("Buy", strategy.long, qty=qty_per_order(equity_per_order, i), comment="DCA Order" + str.tostring(i))
        baseisactive := false

// Strategy Exit
strategy.exit("exit", "Buy", limit=tp)

// Plot
plot(strategy.position_avg_price, color=color.rgb(238, 255, 0), style=plot.style_linebr, linewidth=2)


関連性

もっと