동적 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
avatar of ianzeng123 ianzeng123
2
집중하다
319
수행원

동적 DCA 기반 암호화폐 양적 거래 전략 동적 DCA 기반 암호화폐 양적 거래 전략

개요

이것은 암호화폐 시장에 특별히 설계된 양적 거래 전략으로, 암호화폐 시장의 높은 변동성을 최대한 활용하여, 지능형 비용 평균 (DCA) 을 통해 가격 회전이 있을 때 동적으로 상장한다. 이 전략은 15분 시간 프레임에 달하며, 암호화폐 시장의 급격한 변동에 효과적으로 대응할 수 있으며, 과도한 거래로 인한 위험을 회피한다.

전략 원칙

이 전략은 크게 네 가지 핵심 모듈을 포함하고 있습니다.

  1. 스마트 입시 시스템: OHLC4 가중평균값을 기반으로 첫 번째 포지션을 구축하여 암호화폐 시장의 높은 변동성에 적응
  2. 동적 상장 메커니즘 (Dynamic Replenishment Mechanism): 가격 회귀 시 안전 주문을 유발하고, 상장량이 깊이 증가함에 따라 확대되어 시장의 변동성을 최대한 활용합니다.
  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