動的DCAに基づく暗号通貨定量取引戦略

DCA TP SO (Safety Orders) API OHLC4 HL2 HL3 ROI
作成日: 2025-02-19 16:59:45 最終変更日: 2025-02-27 17:56:06
コピー: 1 クリック数: 462
2
フォロー
319
フォロワー

動的DCAに基づく暗号通貨定量取引戦略 動的DCAに基づく暗号通貨定量取引戦略

概要

これは,暗号通貨市場のために特別に設計された量化取引戦略であり,暗号通貨市場の高波動性の特性を最大限に活用し,スマートなコスト平均 ((DCA) を使って,価格の逆転時に動的に加仓する.この戦略は15分間の時間枠で動作し,暗号通貨市場の急速な変動に効果的に対応し,過剰取引によるリスクを回避します.

戦略原則

戦略は主に4つのコアモジュールで構成されています.

  1. スマートエントリーシステム:OHLC4加重平均価格に基づいて最初のポジションを設立し,暗号通貨市場の高波動性に対応
  2. ダイナミック補償機構: 価格の回復時に安全注文を誘発し,補償量は深度が増加するにつれて拡大し,市場の変動を最大限に活用する
  3. リスク管理システム:ピラミッド式加仓と柔軟なレバレッジ調整によるリスク/利益の最適化
  4. 急速ストップコントロール:手数料の最適化を含む,仮想通貨市場の急速な変動特性を対象に設計されたストップメカニズム

戦略的優位性

  1. 市場適応性:暗号通貨市場の高波動性特性を最適化する
  2. リスク分散: 動的分量投資による仮想通貨市場の突発リスクの軽減
  3. 利回り効率:仮想通貨市場の価格変動を最大限に活用する
  4. 自動実行:主要な暗号取引所のAPIへのアクセスをサポートする
  5. 資金効率化:スマート・レバレッジ・マネジメントによる仮想通貨取引の資金利用効率化

戦略リスク

  1. 市場リスク:仮想通貨市場の極端な波動が大きな撤退につながる可能性がある
  2. 流動性リスク:一部の小規模仮想通貨は流動性の不足に悩まされる可能性がある
  3. レバレッジリスク:仮想通貨市場の高波動性により,レバレッジ取引のリスクが高まる
  4. 技術的リスク:取引所のAPIの安定性とネットワーク接続の質に依存する
  5. 規制リスク:暗号通貨市場の政策変更が戦略の実行に影響を与える可能性がある

戦略最適化の方向性

  1. 波動度自己適応:暗号通貨市場特有の波動率指標を導入して,パラメータを動的に調整する
  2. 多通貨協同化:単一通貨のリスクを分散させる多通貨の連結取引ロジックを開発する
  3. 市場情緒フィルタリング:暗号通貨市場情緒指標を統合し,入場タイミングを最適化
  4. 取引コストの最適化:スマートルーティングと取引所選択によるコスト削減
  5. リスク予警システム:市場の異常な波動に基づく予警システム

要約する

この戦略は,革新的なDCA方法とダイナミックなリスク管理により,暗号通貨取引のための総合的な自動化ソリューションを提供します.暗号通貨市場は高いリスクがあるものの,慎重に設計されたリスク管理機構と市場適応性の最適化により,戦略はほとんどの市場環境で安定性を保ちます.将来の最適化は,暗号通貨市場の特殊性に対する戦略の適応性の向上に焦点を当てます.

ストラテジーソースコード
/*backtest
start: 2020-08-29 15:00:00
end: 2025-02-18 17:22:45
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"TRB_USDT"}]
*/

//@version=5
strategy('Autotrade.it DCA', overlay=true, pyramiding=999, default_qty_type=strategy.cash, initial_capital=10000, commission_value=0.02)

// Date Ranges
from_month = 1
from_day = 1
from_year = 2021
to_month = 1
to_day = 1
to_year = 9999
start = timestamp(from_year, from_month, from_day, 00, 00)  // backtest start window
finish = timestamp(to_year, to_month, to_day, 23, 59)  // backtest finish window
window = time >= start and time <= finish ? true : false  // create function "within window of time"

source_type = 'OHLC4'
source_function(type) =>
    if type == 'Close'
        close
    else if type == 'Open'
        open
    else if type == 'High'
        high
    else if type == 'Low'
        low
    else if type == 'HL2'
        hl2
    else if type == 'HL3'
        hlc3
    else if type == 'OHLC4'
        ohlc4
    else if type == 'Median Body'
        (open + close) / 2
    else if type == 'Weighted Close'
        (high + low + 2 * close) / 4
    else if type == 'Trend Biased'
        close > open ? (high + close) / 2 : (low + close) / 2
    else if type == 'Trend Biased Extreme'
        close > open ? high : low
truncate(number, decimals) =>
    factor = math.pow(10, decimals)
    int(number * factor) / factor
// Strategy Inputs
price_deviation = input.float(1.0, title='Price deviation to open safety orders (%)', minval=0.0) / 100
take_profit = 1.0 / 100
base_order = 10.0
safe_order = 10.0
safe_order_volume_scale = 1.1
safe_order_step_scale = 1.1
max_safe_order = 30

var current_so = 0
var initial_order = 0.0
var previous_high_value = 0.0
var original_ttp_value = 0.0
// Calculate our key levels
take_profit_level = strategy.position_avg_price * (1 + take_profit)
startTrade = input.int(defval=1, title='Trade Start')
margin = input.float(title='Margin', defval=1, step=1, tooltip='USDT')
leverage = input.int(title='Leverage', defval=50, tooltip='it only used on futures trade')
multi = 1.125
var float multiplier = 1
symbol = str.replace_all(syminfo.ticker, '.P', '')
var float totalMargin = 0.0
var bool isTrade =false
var float totalPrice = 0.0
var int totalTrade = 0
var float totalQtys = 0
var float sellPrice = 0
var float sellQty = 0


// // First Position
if strategy.position_size == 0 and window and source_function(source_type) > 0 and previous_high_value == 0.0
    strategy.entry('No Position', strategy.long, qty=base_order / source_function(source_type))
    initial_order := source_function(source_type)
    current_so := 1
    previous_high_value := 0.0
    original_ttp_value := 0
    original_ttp_value

threshold = 0.0
if safe_order_step_scale == 1.0
    threshold := initial_order - initial_order * price_deviation * safe_order_step_scale * current_so
    threshold
else
    threshold := initial_order - initial_order * ((price_deviation * math.pow(safe_order_step_scale, current_so) - price_deviation) / (safe_order_step_scale - 1))
    threshold

// Average Down
if current_so > 0 and source_function(source_type) <= threshold and current_so <= max_safe_order and previous_high_value == 0.0
    if(startTrade<=current_so)
        margin := math.round(margin * multiplier * 100) / 100
        multiplier *= multi
        totalMargin += margin
        avePrice = (totalPrice/totalTrade)
        qty = margin*leverage/close
        isTrade := true
        totalPrice+=close
        totalTrade+=1
        totalQtys+=qty
        alert('{"category": "linear", "mode": 3, "tradeMode": 0, "symbol": "' + str.tostring(symbol) + '", "leverage": "' + str.tostring(leverage) + '", "side": "Buy", "orderType": "Market", "marketUnit": "quoteCoin", "qty": "' + str.tostring(margin) + '", "reduceOnly": false, "positionIdx": 1 }')
        strategy.entry('Trade # ' + str.tostring(current_so) +"---Margin: $" + str.tostring(margin), direction=strategy.long, qty=safe_order * math.pow(safe_order_volume_scale, current_so - 1) / source_function(source_type))
    else
        strategy.entry('Trade # ' + str.tostring(current_so) +" No position", direction=strategy.long, qty=safe_order * math.pow(safe_order_volume_scale, current_so - 1) / source_function(source_type))
    current_so += 1
    current_so


// Take Profit!
if take_profit_level <= source_function(source_type) and strategy.position_size > 0 or previous_high_value > 0.0
    if(isTrade)
        avePrice = totalMargin * leverage / totalQtys * 1.002  // Include fee directly
        percentGain = math.round((close - avePrice) / avePrice * 100 * 100) / 100
        gain = math.round(percentGain * leverage * totalMargin / 100 * 100) / 100
        isTrade := false
        sellPrice := avePrice*0.95
        sellQty := totalMargin * leverage/sellPrice
        loop = current_so-1
        testQty = sellQty/loop
        strategy.close_all(comment= "Take Profit: $" + str.tostring(gain))
        alert('{"category": "linear", "mode": 3, "tradeMode": 0, "symbol": "' + str.tostring(symbol) + '", "leverage": "' + str.tostring(testQty) + '", "side": "Sell", "orderType": "Market", "marketUnit": "baseCoin", "qty": "' + str.tostring(sellQty) + '", "reduceOnly": true, "positionIdx": 1, "loop": "' + str.tostring(loop) + '" }')
                    
    else
        strategy.close_all(comment='No Position')
    current_so := 0
    previous_high_value := 0
    original_ttp_value := 0
    multiplier:=1
    totalMargin:=0.0
    totalPrice:=0
    totalTrade:=0
    totalQtys:=0