该策略运用K线的最高价和最低价的变化判断市场的震荡方向和力度,结合均线判断整体趋势,实现短线操作。主要适用于震荡比较明显的品种。
该策略首先判断K线的最高价和最低价相对前一根K线的变化,如果最高价上涨则记为1,如果最低价下跌则记为-1,否则记为0。然后分别计算一定周期内最高价和最低价的变化均值,判断市场的震荡方向和力度。
同时策略记录最近周期内的最高价和最低价。当均线判断趋势转折时,结合记录的价格判断关键价格位,形成止损和止盈水平。
进入方向按照均线判断,多头在上轨之上买入,空头在下轨之下卖出。止损和止盈水平则通过判断关键价格位形成。
该策略最大的优势在于充分利用短线的震荡特点盈利。通过判断关键价格位形成止损止盈,使得策略在明确的规则下运行。同时结合趋势判断过滤掉不利行情,避免无谓亏损。
该策略主要面临以下风险:
行情不震荡,则无法获利。
价格突破止损位造成不必要的亏损。可以适当放宽止损范围。
错误判断趋势,可能错过行情或做反向操作。可以适当调整均线参数。
该策略可以从以下几个方面进行优化:
调整均线周期,适应不同品种的特点。
优化止盈止损范围,平衡获利和亏损。
增加其他指标判断,避免错误操作。
增加自动止损,控制最大亏损。
该策略总体来说是一个利用短线震荡特点的策略。充分利用价格的小范围运行获取利润。同时严格控制风险,在趋势不利时及时止损。适合较为谨慎追求稳定收益的投资者。如果参数调整适当,在震荡行情中可以获得不错的效果。
/*backtest
start: 2024-01-16 00:00:00
end: 2024-01-16 22:45:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's ZZ-3 Strategy", shorttitle = "ZZ-3 str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
corr = input(0.0, title = "Correction, %")
bars = input(1, minval = 1)
revers = input(false, defval = false, title = "revers")
showll = input(true, defval = true, title = "Show Levels")
showbg = input(false, defval = false, title = "Show Background")
showar = input(false, defval = false, title = "Show Arrows")
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")
//Levels
hbar = 0
hbar := high > high[1] ? 1 : high < high[1] ? -1 : 0
lbar = 0
lbar := low > low[1] ? 1 : low < low[1] ? -1 : 0
uplevel = 0.0
dnlevel = 0.0
hh = highest(high, bars + 1)
ll = lowest(low, bars + 1)
uplevel := hbar == -1 and sma(hbar, bars)[1] == 1 ? hh + ((hh / 100) * corr) : uplevel[1]
dnlevel := lbar == 1 and sma(lbar, bars)[1] == -1 ? ll - ((ll / 100) * corr) : dnlevel[1]
//Lines
upcol = na
upcol := showll == false ? na : uplevel != uplevel[1] ? na : lime
plot(uplevel, color = upcol, linewidth = 2)
dncol = na
dncol := showll == false ? na : dnlevel != dnlevel[1] ? na : red
plot(dnlevel, color = dncol, linewidth = 2)
//Background
size = strategy.position_size
trend = 0
trend := size > 0 ? 1 : size < 0 ? -1 : high >= uplevel ? 1 : low <= dnlevel ? -1 : trend[1]
col = showbg == false ? na : trend == 1 ? lime : trend == -1 ? red : na
bgcolor(col)
//Arrows
longsignal = false
shortsignal = false
longsignal := size > size[1]
shortsignal := size < size[1]
plotarrow(longsignal and showar and needlong ? 1 : na, colorup = blue, colordown = blue, transp = 0)
plotarrow(shortsignal and showar and needshort ? -1 : na, colorup = blue, colordown = blue, transp = 0)
//Trading
lot = 0.0
lot := size != size[1] ? strategy.equity / close * capital / 100 : lot[1]
if uplevel > 0 and dnlevel > 0 and revers == false
strategy.entry("Long", strategy.long, needlong == false ? 0 : lot, stop = uplevel, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, stop = dnlevel, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if uplevel > 0 and dnlevel > 0 and revers == true
strategy.entry("Long", strategy.long, needlong == false ? 0 : lot, limit = dnlevel, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, limit = uplevel, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()