本策略采用快速均线和慢速均线的组合来判断趋势方向,以捕捉中长线趋势进行趋势交易。当快速均线上穿慢速均线时做多,当快速均线下穿慢速均线时做空,属于典型的趋势跟踪策略。
该策略主要依靠均线的金叉死叉来判断行情趋势。具体来说,策略使用5周期的快速均线和21周期的慢速均线。
当快速均线上穿慢速均线时,表示市场趋势转多,该策略会在下一根K线开盘时做多;当快速均线下穿慢速均线时,表示市场趋势转空,该策略会在下一根K线开盘时做空。
此外,策略还设置了“bars”参数来过滤假突破。该参数默认值为2,也就是说快速均线需要连续2根K线在慢速均线之上才会发出做多信号,能够有效过滤假突破。
对于加密货币,策略还加入了极值判断逻辑。只有当快速均线和慢速均线同时处于极端区域时,才会发出交易信号。这也是为了进一步避免假突破。
策略退出规则简单直接,当价格触发止损点就会退出当前头寸。
可以通过以下方法降低风险:
该策略可以从以下几个方面进行优化:
可以测试更多组合,找到更适合当前市场的均线参数。例如调整快线为10周期,慢线为50周期。
可以测试加入MACD,KDJ等其他指标,设置更严格的条件,避免假突破。
目前的入场过于简单依赖均线,可以优化为如下:
可以测试其他止损方式,例如随价格追踪止损,避免止损过早被触发。
当头寸止损后,可以重新入场,这样可以减少停在场外错过趋势的情况。
本策略作为一个基础的趋势跟踪策略,核心思路简单直接,采用双均线判断趋势方向,以及移动止损来控制风险。优点是容易理解和实现,可以顺应趋势获利,风险也可以得到控制。但同时也存在一些缺陷,在盘整市场中信号不准,而且止损容易过早被触发等问题。这需要我们在实盘中不断调整优化,加入其他技术指标进行过滤,使策略更加适应不同市场环境。总的来说,本策略作为趋势跟踪入门策略还是非常适合新手的,值得学习和运用。但我们也要注意其局限性,并不断学习其他更高级的策略思路。只有不断优化策略,才能在复杂多变的市场中持续获得稳定收益。
/*backtest
start: 2023-08-21 00:00:00
end: 2023-09-20 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy(title = "Noro's Trend MAs Strategy v2.3", shorttitle = "Trend MAs str 2.3", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)
//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needex = input(true, defval = true, title = "Need extreme? (crypto/fiat only!!!)")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
src = close
//PriceChannel 1
lasthigh = highest(src, slowlen)
lastlow = lowest(src, slowlen)
center = (lasthigh + lastlow) / 2
//PriceChannel 2
lasthigh2 = highest(src, fastlen)
lastlow2 = lowest(src, fastlen)
center2 = (lasthigh2 + lastlow2) / 2
//Trend
trend = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend[1]
//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0
//Fast RSI
fastup = rma(max(change(close), 0), 2)
fastdown = rma(-min(change(close), 0), 2)
fastrsi = fastdown == 0 ? 100 : fastup == 0 ? 0 : 100 - (100 / (1 + fastup / fastdown))
//CryptoBottom
mac = sma(close, 10)
len = abs(close - mac)
sma = sma(len, 100)
max = max(open, close)
min = min(open, close)
//Signals
up1 = trend == 1 and (low < center2 or usefastsma == false) and redbars == 1
dn1 = trend == -1 and (high > center2 or usefastsma == false) and greenbars == 1
up2 = high < center and high < center2 and bar == -1 and needex
dn2 = low > center and low > center2 and bar == 1 and needex
up3 = close < open and len > sma * 3 and min < min[1] and fastrsi < 10 ? 1 : 0
//Lines
plot(center2, color = red, linewidth = 3, transp = 0, title = "Fast MA")
plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA")
//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 80)
//Trading
stoplong = up1 == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn1 == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]
if up1 or up2 or up3
strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
strategy.exit("Stop Long", "Long", stop = stoplong)
if dn1
strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
strategy.exit("Stop Short", "Short", stop = stopshort)
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()