力道K线突破策略是一种利用K线形态以及力道指标实现股票买入卖出的量化交易策略。该策略结合多种技术指标识别股价趋势和力道信号,在突破点进行建仓,设置止损止盈退出,可有效控制交易风险。
力道K线突破策略主要基于以下几个要点:
使用商品通道指数(CCI)判断股价是否处于超买超卖区域。当CCI上穿100时视为超买信号,当CCI下穿-100时视为超卖信号。
判断K线形态,识别出突破信号。当出现收盘价高于开盘价的红色K线时判断为上涨趋势,出现收盘价低于开盘价的绿色K线则判断为下跌趋势。
结合成交量指标,只有在成交量放大的情况下才考虑发出买入和卖出信号。
当识别到上涨趋势且CCI指标显示超卖时,进行买入操作。当识别到下跌趋势且CCI指标显示超买时,进行卖出操作。
设置止损止盈点。买入后设置一定比例的止损点以控制下行风险,同时也设置一定比例的止盈点以锁定盈利。
具体来说,该策略使用CCI指标判断超买超卖,K线形态判断趋势方向,volume指标判断力道。在符合条件时,进行 longing(买入开多头)或 shorting(卖出开空头)的操作。通过止损止盈来控制风险和锁定利润。
力道K线突破策略具有以下优势:
结合多种指标进行决策,使交易信号更可靠。CCI指标能确定买卖点,K线则判断趋势方向,volume则反映市场力道。
利用 K线形态辅助判断趋势方向,可以更准确地抓住价格反转机会。例如红色K线结合CCI超卖就是买入时机。
设置止损止盈机制可以有效控制风险,防止亏损扩大,并可以锁定盈利。
只在成交量放大时考虑交易信号,可以过滤掉虚假信号。
策略思路清晰易懂,参数设置灵活,可针对不同股票和市场环境进行优化。
可对策略进行扩展优化,例如加入更多因子、机器学习等,提高策略的稳定性和收益率。
力道K线突破策略也存在以下风险:
CCI指标发出的买卖信号可能出现滞后,导致错过最佳入场点位。可以适当优化CCI的参数以提高灵敏度。
K线形态判断的假突破信号可能造成不必要的损失。可以加入更多指标进行确认,或者调整止损比例。
成交量放大也可能反映出市场操控,需要关注价量之间的关系,防止踩进陷阱。
静态的止损止盈设置可能会过早止损或者漏掉更大的行情。可以考虑动态调整止损止盈比例。
针对个股设置的参数不一定适用于其他股票,需要根据不同股票特点进行测试优化。
长期回测数据不一定代表实盘表现,实盘中需要关注操盘风险。
该策略可以考虑从以下方面进行优化:
对CCI参数进行优化,提高CCI指标对买卖点位的判断灵敏度。
增加其他辅助指标,例如MACD,Bollinger Band等,提高买卖信号的准确性。
加入机器学习算法,使用历史数据训练,对买卖点进行预测。
采用动态止损止盈方式,根据市场波动程度调整止损止盈比例。
优化成交量放大的判断逻辑,防止量价背离。
根据不同股票特点和市场环境,优化参数设置,提高策略稳定性。
添加趋势跟踪机制,优化策略在不同阶段的表现。
改进策略结构,引入模块化管理,提高代码灵活性和可扩展性。
力道K线突破策略整体来说是一种相对简单明确的短线交易策略。它结合了多种常用技术指标的优势,判断逻辑清晰易懂,通过止损止盈控制风险。该策略可根据自身需要进行灵活优化,用于捕捉短线价格反转点,追踪中期趋势。但也需要注意防范指标滞后和假突破的风险。如果系统性优化和严格的资金管理,该策略可以成为量化交易的基础策略之一。
/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 2h
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/
// © vikris
//@version=4
strategy("[VJ]War Machine PAT Intra", overlay=true, calc_on_every_tick = false)
// ********** Strategy inputs - Start **********
// Used for intraday handling
// Session value should be from market start to the time you want to square-off
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session,
defval="0915-1455", confirm=true)
// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
type=input.float, minval=0.0, step=0.1, defval=5.0) * 0.01
shortProfitPerc = input(title="Short Take Profit (%)",
type=input.float, minval=0.0, step=0.1, defval=5.0) * 0.01
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=5.0) * 0.01
shortLossPerc = input(title="Short Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=5.0) * 0.01
trendFactor = input(title="Trend Factor(Lower means trending)", type=input.integer, minval=1, step=1, defval=50)
oversold = input(title="Oversold", type=input.integer, minval=1, step=1, defval=25)
overbought = input(title="Overbought", type=input.integer, minval=1, step=1, defval=75)
// ********** Strategy inputs - End **********
// ********** Supporting functions - Start **********
// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0
// Figure out take profit price
longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
// Determine stop loss price
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)
// ********** Supporting functions - End **********
// ********** Strategy - Start **********
// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)
// Trade only if intraday session is active
//=================Strategy logic goes in here===========================
//Vol Confirmation
vol = volume > volume[1]
//Engulfing candle confirm
bullishEC = close > open[1] and close[1] < open[1]
bearishEC = close < open[1] and close[1] > open[1]
//Candles colors
greenCandle = (close > open)
redCandle = (close < open)
length = input(title="Length", type=input.integer, defval=14, minval=1, maxval=2000)
src = hlc3
upper = sum(volume * (change(src) <= 0 ? 0 : src), length)
lower = sum(volume * (change(src) >= 0 ? 0 : src), length)
_rsi(upper, lower) =>
100.0 - (100.0 / (1.0 + upper / lower))
mf = _rsi(upper, lower)
ci = 100 * log10(sum(atr(1), length) / (highest(length) - lowest(length))) / log10(length)
//tradeSignal = ((rsiOS or rsiOS[1]) and bullishEC) or ((rsiOB or rsiOB[1]) and bearishEC)
//Final Long/Short Condition
longCondition = redCandle and mf < oversold and ci <trendFactor and vol
shortCondition = greenCandle and mf >overbought and ci <trendFactor and vol
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
stop_level = longStopPrice
profit_level = longExitPrice
strategy.entry("My Long Entry Id", strategy.long)
strategy.exit("TP/SL", "My Long Entry Id", stop=stop_level, limit=profit_level)
//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
stop_level = shortStopPrice
profit_level = shortExitPrice
strategy.entry("My Short Entry Id", strategy.short)
strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")
// ********** Strategy - End **********