
本策略采用两个移动平均线来判断价格的趋势和突破。当价格上穿上轨时做空,当价格下穿下轨时做多,设置止损exit来控制风险。
本策略具有如下优势:
本策略也存在一些风险:
本策略可以从以下几个方面进行优化:
本策略整体思路清晰易懂,通过双轨系统识别趋势,价格突破判断入场时机,可以过滤噪音实现稳定盈利,也存在一些改进优化的空间。总体而言,是一种可复现的具有实战价值的量化交易策略。
/*backtest
start: 2023-11-13 00:00:00
end: 2023-11-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's Shift MA Strategy v1.0", shorttitle = "Shift MA str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
per = input(3, defval = 1, minval = 1, maxval = 1000, title = "Length")
src = input(ohlc4, title = "Source")
buylevel = input(-5.0, defval = -5.0, minval = -100, maxval = 0, title = "Buy line (lime)")
selllevel = input(0.0, defval = 0.0, minval = -100, maxval = 100, title = "Sell line (red)")
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")
//SMAs
sma = sma(src, per)
buy = sma * ((100 + buylevel) / 100)
sell = sma * ((100 + selllevel) / 100)
plot(buy, linewidth = 2, color = lime, title = "Buy line")
plot(sell, linewidth = 2, color = red, title = "Sell line")
//Trading
size = strategy.position_size
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]
if (not na(close[per])) and size == 0
strategy.entry("L", strategy.long, lot, limit = buy)
if (not na(close[per]))
strategy.entry("Close", strategy.short, 0, limit = sell)
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()