该策略根据长期趋势判断来进行资产配置和对冲操作。
主要逻辑是:
选择一项基础资产和均线周期及分辨率
计算该资产的简单移动平均线
当价格上穿均线时,表明长期看涨,做多该资产
当价格下穿均线时,表明长期看跌,做空该资产
也可仅做多,或仅做空
通过资产和其移动平均线的关系来判断长期趋势
建立与长期判断相反的头寸进行对冲
该策略对冲了短期波动中的风险,关注资产的长期趋势态势,可获得稳定收益。
简单的均线系统判断长期趋势
长短线配置配对,有效对冲系统性风险
清晰的做多做空信号
均线系统滞后于价格
长期持有带来的资金成本
需要关注多个头寸的风险控制
该策略通过资产的长短线组合进行对冲操作,强调风险管理。但其均线判定和持仓成本仍需关注。
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 1h
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/
// © danilogalisteu
//@version=4
strategy("Long Term L/S", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
base = input("BMFBOVESPA:IBOV")
period = input(5, 'SMA Period', input.integer)
resolution = input(title="SMA Resolution", type=input.resolution, defval='M')
strat = input(title="Strategy", defval="Long/Short", options=["Long Only", "Long/Short", "Short Only"])
strat_val = strat == "Long Only" ? 1 : strat == "Long/Short" ? 0 : -1
base_cl = security((base), resolution, close)
base_ma = sma(base_cl, period)
longCondition = crossover(base_cl, base_ma)
if (longCondition)
if strat_val > -1
strategy.entry("LONG", strategy.long)
if strat_val < 1
strategy.close("SHORT")
shortCondition = crossunder(base_cl, base_ma)
if (shortCondition)
if strat_val > -1
strategy.close("LONG")
if strat_val < 1
strategy.entry("SHORT", strategy.short)
//plot(longCondition?1:0, 'L', color.blue)
//plot(shortCondition?-1:0, 'S', color.red)