取引量に基づくDCA戦略の動的調整

QFL DCA TP SL ATR ADX EMA SMA RSI MACD
作成日: 2024-04-12 17:12:07 最終変更日: 2024-04-12 17:12:07
コピー: 5 クリック数: 995
1
フォロー
1617
フォロワー

取引量に基づくDCA戦略の動的調整

概要

この戦略は,取引量と価格の突破に基づいて動的な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)