Name
动态风险调整杠杆交易系统Dynamic-Risk-Adjusted-Leverage-Trading-System
Author
ChaoZhang
Strategy Description
[trans]
这个交易系统名为“动态风险调整杠杆交易系统”,旨在根据当前市场波动率相对于其历史平均值来管理交易。该系统根据ATR(平均真实范围)指标计算目标开仓数量,并相应调整杠杆。系统采用金字塔加仓开仓方式,允许同时开多个头寸。
系统的具体步骤如下:
-
计算14日ATR周期的ATR值,并将其除以当前收盘价进行标准化。
-
计算标准化ATR的100日简单移动平均值(SMA)。
-
计算标准化ATR与其100日SMA的比率。
-
根据比率的倒数(2 / 比率)确定目标杠杆。
-
通过将目标杠杆乘以5计算目标开仓数量。
-
在图表上绘制目标开仓数量和当前开仓数量。
-
检查是否有买入机会(如果当前开仓数量少于目标数量)或平仓机会(如果当前开仓数量大于目标数量加1)。
-
如果有买入机会,开多单并将交易添加到openTrades数组。
-
如果有平仓机会并且openTrades数组中有交易,平掉最新交易并从数组中删除。
该系统旨在通过动态调整开仓数量和杠杆捕捉市场趋势,使用数组跟踪开仓情况,可更好地控制单笔交易的开平。
该策略具有以下优势:
-
动态调整杠杆和头寸数量,可以根据市场波动率变化调整风险敞口。当波动率较低时,增加杠杆和头寸数量,当波动率较高时,减少杠杆和头寸数量,有效控制风险。
-
使用ATR指标计算目标头寸数量,该指标能反映市场波动性,是动态调整头寸的合理指标选择。
-
采用金字塔加仓方式,同时开多个头寸,能在趋势中获利。
-
使用数组记录每笔开仓交易,可以明确控制单笔交易的开平,避免出现不必要的反向操作。
-
该策略参数较少,容易实现和操作。
-
策略思路清晰易懂,代码结构合理,易于优化和迭代。
该策略也存在一些风险:
-
ATR指标仅反映过去一段时间的波动性,未来波动率变化无法预知,可能导致杠杆调整不当。
-
金字塔加仓方式可能在趋势反转时导致损失积累。
-
数组记录开仓仅适用于简单的开平仓操作,如果开仓逻辑较复杂则需要更复杂的数据结构。
-
目标杠杆和头寸数量的设定需要根据品种特性调整,不宜局限于某个固定参数。
-
单一指标容易产生误导,可以考虑加入其它波动率指标或机器学习算法以提高稳健性。
该策略可以从以下几个方面进行优化:
-
增加止损策略,当亏损达到止损点时主动止损。
-
优化指标参数,测试不同ATR周期参数的效果。
-
尝试不同的开仓策略,如固定数量开仓等,测试效果。
-
增加其它衡量波动率的指标,如布林带WIDTH,KD,RSI等,组合使用。
-
利用机器学习方法预测波动率,代替simplex smoothing方法。
-
优化开仓数量的计算方式,可使用ATR倍数或波动率函数等方式。
-
记录更多开仓细节,如开仓价格、时间等,用于策略分析优化。
-
增加参数优化功能,自动优化找到最佳参数组合。
本策略基于ATR动态调整杠杆和开仓数量,在趋势中进行风险敞口调整,具有一定的优势。但也存在参数设定困难、指标优化空间等问题值得进一步优化。整体来说,该策略思路清晰,易操作易优化,值得深入研究应用。
||
This trading system called “Dynamic Risk-Adjusted Leverage Trading System” aims to manage trades based on current market volatility relative to historical average. The system calculates target number of open trades based on ATR indicator and adjusts leverage accordingly. It opens and closes trades using pyramiding approach, allowing multiple positions at the same time.
The system follows steps below:
-
Calculate 14-period ATR and normalize it by dividing it by closing price.
-
Calculate 100-day Simple Moving Average (SMA) of normalized ATR.
-
Calculate the ratio of normalized ATR to its 100-day SMA.
-
Determine target leverage based on inverse of the ratio (2/ratio).
-
Calculate target number of open trades by multiplying target leverage by 5.
-
Plot target and current open trades on chart.
-
Check if there is chance to buy (if current open trades less than target) or close trade (if current open trades greater than target plus 1).
-
If chance to buy, open long trade and add to openTrades array.
-
If chance to close trade and trades exist in openTrades array, close most recent trade by referencing array and remove from array.
The system aims to capture trends by dynamically adjusting open trades and leverage based on market volatility. It uses array to track open trades for better control.
The advantages of this strategy:
-
Dynamic adjustment of leverage and position size based on market volatility changes can effectively manage risk.
-
Using ATR indicator to calculate target position size, which reflects market volatility, is a reasonable choice.
-
Pyramiding with multiple positions can profit from trends.
-
Recording each trade in array enables explicit control of opening and closing trades.
-
The strategy has few parameters and is easy to implement and operate.
-
The logic is clear and code structure is well organized for easy optimization and iteration.
The risks of this strategy:
-
ATR only reflects past volatility, unable to predict future changes, may lead to improper leverage adjustment.
-
Pyramiding may accumulate losses when trend reverses.
-
Array recording trades only applies to simple open/close operations. More complex data structure needed for complex logic.
-
Target leverage and position size settings need adjustment based on symbol specifics rather than fixed parameters.
-
Reliance on single indicator can be misleading. Other volatility indicators or machine learning algorithms can improve robustness.
The strategy can be optimized in aspects below:
-
Add stop loss to actively cut loss when reaching stop loss level.
-
Optimize indicator parameters by testing different ATR periods.
-
Try other entry strategies like fixed quantity entries and test the results.
-
Add other volatility metrics like Bollinger Bands WIDTH, KD, RSI etc. for combinational use.
-
Use machine learning models to predict volatility instead of simple smoothing.
-
Optimize calculation of position size, such as using ATR multiples or volatility functions.
-
Record more entry details like entry price, time etc. for strategy analysis and optimization.
-
Add parameter optimization for auto-optimization to find optimum parameter sets.
The strategy dynamically adjusts leverage and position size based on ATR to manage risk exposure during trends, and has certain advantages. But challenges like parameter setting difficulty and indicator optimization space remain for further improvements. Overall, the logic is clear and easy to operate and optimize, worthy of in-depth research and application.
[/trans]
Source (PineScript)
/*backtest
start: 2022-10-09 00:00:00
end: 2023-10-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("I11L - Risk Adjusted Leveraging", overlay=false, pyramiding=25, default_qty_value=20, initial_capital=20000, default_qty_type=strategy.percent_of_equity,process_orders_on_close=false, calc_on_every_tick=false)
atr = ta.atr(14) / close
avg_atr = ta.sma(atr,100)
ratio = atr / avg_atr
targetLeverage = 2 / ratio
targetOpentrades = 5 * targetLeverage
plot(targetOpentrades)
plot(strategy.opentrades)
isBuy = strategy.opentrades < targetOpentrades
isClose = strategy.opentrades > targetOpentrades + 1
var string[] openTrades = array.new_string(0)
if(isBuy)
strategy.entry("Buy"+str.tostring(array.size(openTrades)),strategy.long)
array.push(openTrades, "Buy" + str.tostring(array.size(openTrades)))
if(isClose)
if array.size(openTrades) > 0
strategy.close(array.get(openTrades, array.size(openTrades) - 1))
array.pop(openTrades)
Detail
https://www.fmz.com/strategy/429387
Last Modified
2023-10-16 16:00:52