该策略通过计算两个不同周期的移动平均线,并根据它们的金叉死叉形成买入和卖出信号。
该策略首先允许用户选择移动平均线的类型和长度。类型包括SMA、EMA、VWMA等,长度则决定了均线的周期。
然后根据用户选择计算出两条移动平均线。如果快线从下方上穿慢线,形成金叉,则产生买入信号。如果快线从上方下穿慢线,形成死叉,则产生卖出信号。
这样,当短期平均价格高于长期平均价格时,被视为市场处于上涨趋势,应该买入。当短期价格低于长期价格时,被视为市场处于下跌趋势,应该卖出。
可通过适当优化参数,组合其他指标生成信号,设置止损止盈等方式来控制风险。
该策略整体思路简单清晰,通过计算双均线形成交易信号,可根据市场环境灵活调整参数,和其他策略组合优化,但需要注意防范震荡市场的风险,合理进行资金管理。整体来说是一个值得考虑的选择。
/*backtest
start: 2023-09-09 00:00:00
end: 2023-09-13 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy(title = "Noro's MAs Tests", shorttitle = "MAs tests", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)
len = input(30, defval = 30, minval = 2, maxval = 1000, title = "MA length")
type = input(1, defval = 1, minval = 1, maxval = 7, title = "Type")
src = input(close, defval = close, title = "Source")
//DEMA
dema = 2 * ema(src, len) - ema(ema(close, len), len)
//TEMA
xPrice = close
xEMA1 = ema(src, len)
xEMA2 = ema(xEMA1, len)
xEMA3 = ema(xEMA2, len)
tema = 3 * xEMA1 - 3 * xEMA2 + xEMA3
//KAMA
xvnoise = abs(src - src[1])
nfastend = 0.20
nslowend = 0.05
nsignal = abs(src - src[len])
nnoise = sum(xvnoise, len)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2)
kama = nz(kama[1]) + nsmooth * (src - nz(kama[1]))
//PriceChannel
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2
ma = type == 1 ? sma(src, len) : type == 2 ? ema(src, len) : type == 3 ? vwma(src, len) : type == 4 ? dema : type == 5 ? tema : type == 6 ? kama : type == 7 ? center : 0
plot(ma, color = blue, linewidth = 3, transp = 0)
trend = low > ma ? 1 : high < ma ? -1 : trend[1]
longCondition = trend == 1 and trend[1] == -1
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = trend == -1 and trend[1] == 1
if (shortCondition)
strategy.entry("Short", strategy.short)