Name
带滑点止损的DCA定投策略DCA-Strategy-with-Trailing-Take-Profit
Author
ChaoZhang
Strategy Description
该策略将美元成本平均法(Dollar Cost Averaging, DCA)与交易所平台上的止盈滑点(Trailing Take Profit)功能相结合。它设置了1%的价格偏差用于购买,并针对每次出售目标0.5%的利润。这种微小利润的理由是为了确保交易机器人平稳运行,避免在市场缓慢期被困住的风险。根据回测结果,该机器人已被证明足够适应市场波动和操纵。尽管年化收益率(Annual Percentage Rate, APR)可能不会特别高,但它提供了一个满意和安全的长期投资选择,通常优于传统的买入并持有(Buy and Hold, HODL)策略。
该策略首先设置了滑点止损百分比、最大DCA订单数、价格偏差百分比等可配置参数。然后它会追踪上次买入价格、买入次数、初始买入价格和滑点止损价格等变量。在买入逻辑上,如果当前价格低于上次买入价格的(1 - 价格偏差百分比),且买入次数还没有达到最大DCA订单数,则会发出买入信号并记录本次买入价格。在卖出逻辑上,如果当前价格高于上次买入价格的(1 + 止盈百分比),则会设置一个滑点止损价格。如果价格继续上涨突破该滑点止损价格,则更新滑点止损价格为当前价格的(1 - 滑点百分比)。如果价格下跌突破滑点止损价格,则发出卖出信号,同时重置相关变量,准备开始新一轮的DCA买入。
-
结合了DCA定投和滑点止损,既确保了定期定额买入的成本平均效果,也锁定了部分利润避免回撤。
-
滑点止损机制灵活,可以根据市场情况来调整止盈幅度和滑点比例,降低风险。
-
回测表现优于传统的买入持有策略,年化收益率平稳,适合长线投资。
-
实现简单,参数设置灵活,易于在主流交易所平台上实际应用。
-
DCA买入次数有限,如果行情长期下跌,亏损可能扩大。
-
滑点止损设置不当可能导致利润频繁锁定,或亏损扩大。
-
交易成本会对利润产生一定影响。高滑点止损设置会增加交易次数。
-
需要足够的资金支持频繁的DCA买入。初始资金不足可能导致买入次数不enough。
-
可以设置浮动滑点止损,当利润达到一定比例时逐步减小滑点。
-
结合均线指标,在关键支持位附近加大买入份额。
-
加入重新平衡机制,根据总资产调整每次DCA购买金额。
-
优化参数设置,测试不同持仓周期下的收益率。
该策略整合了DCA定投和滑点止损方法,实现了长期稳定收益的量化交易。回测表现良好,适合那些追求稳健增长的投资者。代码简洁易于理解实现。通过优化参数设置和结合其他指标,可以获得更好的实盘效果。总的来说,该策略为投资者提供了一个相对安全平稳的自动化量化交易方案。
||
This strategy combines Dollar Cost Averaging (DCA) with the trailing take profit feature available on exchange platforms. It sets a 1% price deviation for purchases and targets 0.5% profit on each sale. The rationale for targeting small profits is to ensure smooth operations for the trading bot, avoiding getting stuck during slow market periods. Based on backtesting, this bot has proven to be adaptable enough to withstand market fluctuations and manipulation. While the Annual Percentage Rate (APR) may not be exceptionally high, it offers a satisfactory and secure option for long-term investment, often outperforming the traditional buy and hold (HODL) strategy.
The strategy first sets configurable parameters like trailing stop percentage, max DCA orders, price deviation percentage, etc. It then tracks variables like last buy price, number of buys, initial buy price, trailing stop price, etc. On the buy logic, if the current price is below the last buy price * (1 - price deviation percentage) and the number of buys has not reached max DCA orders, it will issue a buy signal and record the buy price. On the sell logic, if the current price is above the last buy price * (1 + take profit percentage), it will set a trailing stop price. If the price continues to rise above that trailing stop price, the trailing stop is updated to current price * (1 - trailing percentage). If the price drops below the trailing stop price, a sell signal is issued while resetting relevant variables, getting ready for the next round of DCA buys.
-
Combines DCA and trailing stop loss to ensure cost averaging while locking in partial profits to avoid drawdowns.
-
Flexible trailing stop mechanism with adjustable profit taking and trailing percentage to minimize risk.
-
Backtested results outperform buying and holding, with steady annualized returns suitable for long-term investments.
-
Simple to implement with adjustable parameters for easy application across major exchange platforms.
-
Limited number of DCA buys means losses can compound if market trends down for extended periods.
-
Poor trailing stop loss settings may lead to premature profit taking or runaway losses.
-
Trading costs can eat into profits. High trailing stop loss settings increase number of trades.
-
Requires sufficient capital to support frequent DCA buys. Insufficient initial capital limits number of buys.
-
Implement adaptive trailing stops, lowering trailing percentage as certain profit milestones are reached.
-
Incorporate moving averages, increasing buy amounts around key support areas.
-
Add rebalancing mechanism to adjust DCA amounts based on total assets.
-
Optimize parameter settings and test profitability across various holding periods.
This strategy combines DCA and trailing stops for steady algorithmic trading returns over long periods. Backtested results are strong and suitable for investors focused on stable growth. Simple and clean code makes it easy to understand and implement. Further performance gains can be achieved through parameter optimization and incorporating additional indicators. Overall it provides investors with a relatively safe and consistent quantified trading solution.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_float_1 | 0.6 | Take Profit (%) |
v_input_float_2 | 0.1 | Trailing Stop (%) |
v_input_int_1 | 10 | Max DCA Orders |
v_input_float_3 | true | Price Deviation (%) |
Source (PineScript)
/*backtest
start: 2023-02-16 00:00:00
end: 2024-02-22 00:00:00
period: 1d
basePeriod: 1h
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/
// © Stavolt
//@version=5
strategy("DCA Strategy with Trailing Take Profit", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Correctly using input to define user-configurable parameters
takeProfitPercent = input.float(0.6, title="Take Profit (%)", minval=0.1, maxval=5)
trailingPercent = input.float(0.1, title="Trailing Stop (%)", minval=0.05, maxval=1)
maxDCAOrders = input.int(10, title="Max DCA Orders", minval=1, maxval=20)
priceDeviationPercent = input.float(1.0, title="Price Deviation (%)", minval=0.5, maxval=5)
var float lastBuyPrice = na
var int buyCount = 0
var float initialBuyPrice = na
var float trailingStopPrice = na
// Strategy logic here...
// Note: The detailed logic for buying and selling based on the DCA strategy
// needs to be tailored to your specific requirements and tested for correctness.
if (buyCount < maxDCAOrders)
if (na(lastBuyPrice) or close < lastBuyPrice * (1 - priceDeviationPercent / 100))
strategy.entry("Buy", strategy.long)
lastBuyPrice := close
buyCount += 1
if (na(initialBuyPrice))
initialBuyPrice := close
if (not na(lastBuyPrice) and close > lastBuyPrice * (1 + takeProfitPercent / 100))
if (na(trailingStopPrice) or close > trailingStopPrice)
trailingStopPrice := close * (1 - trailingPercent / 100)
if (close < trailingStopPrice)
strategy.close("Buy")
lastBuyPrice := na
trailingStopPrice := na
buyCount := 0
initialBuyPrice := na
Detail
https://www.fmz.com/strategy/442635
Last Modified
2024-02-23 14:01:20