该策略是一个基于马丁格尔理论的网格式加仓策略模型,通过在价格下跌时动态调整仓位大小来平衡成本。策略核心是在价格每下跌8%时进行加仓操作,且每次加仓量为上一次的两倍,同时设置5%的获利目标。这种策略特别适合在震荡市场中捕捉价格回归机会。
策略采用了几个关键的技术指标和参数设置: 1. 跌幅监控:使用15根K线作为回溯周期,计算当前价格与最高价的比值来衡量跌幅 2. 加仓机制:当价格下跌8%时触发加仓,每次加仓量是前一次的2倍 3. 成本计算:通过累计成本和数量来动态计算加权平均成本 4. 止盈条件:当价格上涨至平均成本的105%时自动平仓获利 5. 风控机制:设置最大加仓次数为10次,超过后强制平仓止损
该策略通过马丁格尔理论和网格交易的结合,实现了一个自适应性强的交易系统。策略在震荡市场中表现出色,通过科学的仓位管理和风险控制,能够实现稳定收益。但使用时需要注意资金管理和市场环境的适配性,建议在实盘使用前进行充分的回测验证。
/*backtest
start: 2025-01-19 16:30:00
end: 2025-02-18 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Lila Rai's doubling strategy", overlay=true)
// Input for price drop thresholds
dropPercent = 0.95 // 8% drop (100% - 8%)
takeProfitPercent = 1.05 // 5% TP above avg entry
var float avgPrice = na
var int qty = 1 // Start with 1 lot
var float totalCost = 0
var float totalQty = 0
var int doublingCount = 0 // To count the number of times the position size is doubled
// Calculate price movement
lookbackBars = 15 // Assuming 1-minute chart
priceChange = close / ta.highest(close, lookbackBars)
// Buy condition: price drops 8%
if (priceChange < dropPercent)
totalCost := totalCost + close * qty // Add cost of new position
totalQty := totalQty + qty // Update total quantity
avgPrice := totalCost / totalQty // Compute weighted average price
strategy.order("DCA Buy", strategy.long, qty)
qty := qty * 2 // Double the next position size
doublingCount := doublingCount + 1 // Increase the doubling count
// Condition for selling in loss after 5 doublings
if (doublingCount >= 10)
strategy.close("DCA Buy") // Close the position at market price
doublingCount := 0 // Reset the doubling count after selling
qty := 1 // Reset qty to 1 for fresh buying
// Take Profit Condition: 5% above avg price
if (not na(avgPrice))
takeProfit = avgPrice * takeProfitPercent
strategy.exit("Take Profit", from_entry="DCA Buy", limit=takeProfit)
// Reset qty if take profit is hit
if (strategy.position_size == 0)
qty := 1 // Reset qty after exiting in profit
// Plot indicators
plot(avgPrice, title="Average Entry Price", color=color.blue, linewidth=2)
plot(close, title="Close Price", color=color.red, linewidth=1)