DCAボット戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-26 17:28:27
タグ:

概要

これは,初期エントリー後にポジションにスケールするドルコスト平均化 (DCA) メカニズムのバックテスト戦略である.事前に設定された価格偏差パーセントとピラミッドルールに基づいてポジションに追加することができます.この戦略には,利益を取ることと利益を取ることを後押しする機能も含まれます.

戦略の論理

ストラテジーは,バックテストタイムフレーム内で0を超えると,最初に閉じる価格でロングポジションを開く.このエントリー価格はベース価格bo_levelとして記録される.その後,セーフティオーダー (so) が存在しない場合,現在のキャンドルに可能なすべての出口オーダーを置く.具体的には,セーフティオーダーの価格は,最後のセーフティオーダーの価格 latest_so_levelとセーフティオーダーのステップスケール safe_order_step_scaleに基づいて計算される.これは最大セーフティオーダーのカウント max_safe_orderに達するまでループされる.

保有ポジションの間,ポジションサイズが0以上である場合,取利益価格 take_profit_level はベース価格と目標取利益パーセントに基づいて計算されます.追利益が無効になっている場合,この固定取利益価格が使用されます.そうでなければ,最高価格 ttp_max はキャンドル高値に基づいて更新され,追利益の取利益価格を追います.

利点分析

  • DCAメカニズムを利用して,価格が下がるとコストを平均して,システムリスクをカバーします.

  • 入場規則の柔軟な構成のためのカスタマイズ可能なパラメータをサポートし,異なる資産と取引スタイルのための利益戦略を取ります.

  • 価格の動きに基づいて自動的に利益を取ることを調整する機能が組み込まれています 早期の利益を取ることを回避します

  • 柔軟なバックテストパラメータ設定により,異なるタイムフレームデータをテストし,戦略のパフォーマンスを評価することが容易になります.

  • 3コマでライブボットを直接設定できます.

リスク分析

  • DCAは,市場が下落を続けると,ポジションと損失がさらに増加するリスクがあります.合理的なピラミッドルールが必要です.

  • 市場波動に適応できず 早期または遅刻した退出のリスクがあります.

  • バックテストの過剰なフィットリスク,トランザクションコストの影響を受けるライブパフォーマンスなど 適切な評価が必要です

  • プラットフォームの安定リスク 実行失敗 監視が必要

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

  • ダイナミックに価格偏差を調整し,ピラミッド規則を最適化します.

  • より科学的な利得率を決めるため 変動指標を組み込む

  • 特定の資産の取引セッションに基づいて 合理的なバックテスト時間枠を設定します

  • ストップロスを導入し,ポジションを大幅に下げると損失を削減します.

  • マシン学習を利用して パーマータを動的に最適化します

結論

DCAのバックテストは,DCAのバックテストの1つである.DCAのバックテストは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.DCAは,DCAのバックテストの1つである.


/*backtest
start: 2023-09-18 00:00:00
end: 2023-09-25 00:00:00
period: 15h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rouxam

// Author: rouxam
// Inspired by the original work of ericlin0122

//@version=4
// strategy("Backtesting 3commas DCA Bot", overlay=true, pyramiding=99, process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.1)

// Strategy Inputs
price_deviation         = input(1.0, type=input.float,  title='Price deviation to open safety orders (%)', minval=0.0, step=0.1)/100
take_profit             = input(1.0, type=input.float,  title='Target Take Profit (%)', minval=0.0, step=0.1)/100
ttp                     = input(0.5, type=input.float,  title='Trailing Take Profit (%) [0 = Disabled]', minval=0.0, step=0.1)/100
base_order              = input(10.0, type=input.float, title='base order') 
safe_order              = input(20.0, type=input.float, title='safe order') 
safe_order_volume_scale = input(2.0, type=input.float,  title='Safety order volume scale', step=0.1) 
safe_order_step_scale   = input(1.5, type=input.float,  title='Safety order step scale', step=0.1) 
max_safe_order          = input(5,                      title='Max safe order', minval=1, maxval=99, step=1) 

// Date Inputs
from_month = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
from_day   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
from_year  = input(defval = 2021, title = "From Year")
to_month   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
to_day     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
to_year    = input(defval = 9999, title = "To Year")
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"

var bo_level = 0.0
var latest_so_level = 0.0
var next_so_level = 0.0
var ttp_active = false
var ttp_max = 0.0
var ttp_level = 0.0
var take_profit_level = 0.0

if strategy.position_size <= 0.0
    ttp_max := 0.0
    ttp_active := false


// First Position
if(strategy.opentrades == 0 and window and close > 0)
    // Place Buy Order ASAP
    bo_level := open
    strategy.entry("BO", limit=bo_level, long=strategy.long, qty=base_order/bo_level)
    latest_so_level := open

// Dollar Cost Averaging
place_safety_orders = latest_so_level == bo_level
if place_safety_orders
    // Placing all possible exit orders on that candle
    for i = 1 to max_safe_order
        next_so_level := latest_so_level * (1 - price_deviation * pow(safe_order_step_scale,  i - 1))
        so_name = "SO" + tostring(i) 
        strategy.entry(so_name, long=strategy.long, limit=next_so_level, qty=safe_order * pow(safe_order_volume_scale, i - 1)/next_so_level)
        latest_so_level := next_so_level

// Take Profit
if strategy.position_size > 0
    take_profit_level := strategy.position_avg_price * (1 + take_profit)
    if ttp <= 0.0
        // No trailing take profit
        strategy.exit(id="TP", limit=take_profit_level)
    else
        // Trailing take profit
        if take_profit_level <= close
            ttp_max := max(high, ttp_max)
            ttp_active := true
        if ttp_active 
            // Update exit order
            ttp_level := ttp_max * (1 - ttp)
            strategy.exit(id="TTP", stop=ttp_level)


もっと