
该策略运用了阻力突破的价格形态信号和环形停损的风险控制机制。它会在突破阻力位后建仓做多,在突破支撑位后建仓做空。同时设置环形停损和止损,有效控制风险。
该策略主要基于以下几个要点:
使用均线判断趋势方向。策略中设置快慢均线,快线上穿慢线代表长线看涨,下穿代表长线看跌。
阻力突破做多信号。当价格上涨突破近期高点时,视为突破阻力位的信号,做多入场。
支撑突破做空信号。当价格下跌突破近期低点时,视为突破支撑位的信号,做空入场。
设置环形停损。入场后设置止损线,并随价格波动进行调整,实现止损线环绕价格运行。
止损和止盈退出。止损退出可有效控制风险,止盈退出可锁定利润。
具体来说,该策略使用高低价的均值作为价格源,计算快慢EMA判断趋势方向。当快线上穿慢线且出现阻力突破信号时做多,当快线下穿慢线且出现支撑突破信号时做空。入场后以一定周期内最低价作为止损位,并随价格上涨进行调整,设置止盈线锁定利润。有效控制风险的同时获取趋势中的利润。
该策略具有以下几个优势:
获利稳定。跟随趋势操作,能在指数级别的长线趋势中获利。
风险控制良好。设置环形停损和止损,能及时止损退出。
信号准确。阻力位突破做多和支撑位突破做空,信号准确可靠。
简单易操作。指标和信号规则简单清晰,参数设置也不复杂。
适应市场。能够在不同品种和任何市况下运作。
该策略也存在一些风险需要注意:
突破失败风险。阻力支撑位突破后可能出现回调和重试,导致止损。
参数优化风险。参数设置不当可能导致信号频繁或不足。优化过程需谨慎。
指标失效风险。在特殊市况下,EMA指标可能会失效或者延迟。
趋势反转风险。做多做空方向与市场产生背离时,亏损可能加大。
这些风险可以通过参数优化、适当宽止损、严格遵循信号等方法很大程度上得到控制和缓解。
该策略可以从以下几个方面进行进一步优化:
时间周期优化。调整计算均线和价格形态的时间周期参数,寻找最佳组合。
品种适应性优化。根据不同品种的特点,调整参数设置。
止损策略优化。运用更稳定和精确的止损方式,如移动止损、振荡止损等。
止盈策略优化。设置移动止盈或指数型止盈,让利润能更大化。
增加过滤条件。加入交易量、波动率等过滤条件,排除假突破。
增强入场信号。加入更多指标或形态作为入场信号的确认。
该策略整体运作流畅,核心思路清晰,具有较强的稳定性和获利能力。风险控制和指标应用也较为得当,是一款值得运用的突破类量化策略。后续通过参数和模块优化,可以使策略更趋完善,适应更多品种和复杂市场环境。
/*backtest
start: 2023-12-03 00:00:00
end: 2023-12-10 00:00:00
period: 30m
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/
// © EduardoMattje
//@version=4
strategy("Reversal closing price", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10, initial_capital=10000)
src = input(hl2, "Price source")
order_direction = input("Both", "Order direction", options=["Both", "Long", "Short"])
// EMA calculation and plot
ema_long_period = input(80, "EMA long period")
ema_short_period = input(8, "EMA short period")
ema_long = ema(src, ema_long_period)
ema_short = ema(src, ema_short_period)
ema_bull = ema_short > ema_long
ema_bear = ema_short < ema_long
plot(ema_long, "EMA long", ema_bull ? color.green : color.red, 3)
plot(ema_short, "EMA short", ema_bull ? color.green : color.red, 3)
// Settings
risk_reward_ratio = input(2.0, "Risk to reward ratio", minval=1.0, step=0.1)
stop_lookback = input(3, "Stoploss candle lookback", minval=1)
ema_cross_stop = input(true, "Close if EMA crosses in oposite direction")
allow_retracing = input(true, "Allow price retracing")
// RCP calculation
rcp_bull = low[0] < low[1] and low[0] < low[2] and close[0] > close[1]
rcp_bear = high[0] > high[1] and high[0] > high[2] and close[0] < close[1]
// Order placement
in_market = strategy.position_size != 0
long_condition = rcp_bull and ema_bull and not in_market and order_direction != "Short"
short_condition = rcp_bear and ema_bear and not in_market and order_direction != "Long"
bought = strategy.position_size[0] > strategy.position_size[1] and strategy.position_size[1] == 0
sold = strategy.position_size[0] < strategy.position_size[1] and strategy.position_size[1] == 0
closed = not in_market and in_market[1]
long_position = strategy.position_size > 0
short_position = strategy.position_size < 0
buy_price = high + syminfo.mintick
sell_price = low - syminfo.mintick
if long_condition
strategy.entry("Long", true, stop=buy_price)
if short_condition
strategy.entry("Short", false, stop=sell_price)
if allow_retracing
better_price_long = barssince(closed) > barssince(long_condition) and barssince(long_condition) >= 1 and not in_market and ema_bull and buy_price < valuewhen(long_condition, buy_price, 0) and buy_price[0] < buy_price[1]
if better_price_long
strategy.cancel("Long")
strategy.entry("Long", true, stop=buy_price)
better_price_short = barssince(closed) > barssince(short_condition) and barssince(short_condition) >= 1 and not in_market and ema_bear and sell_price > valuewhen(short_condition, sell_price, 0) and sell_price[0] > sell_price[1]
if better_price_short
strategy.cancel("Short")
strategy.entry("Short", false, stop=sell_price)
// Stoploss orders
stop_price = long_position ? valuewhen(bought, lowest(stop_lookback)[1] - syminfo.mintick, 0) : short_position ? valuewhen(sold, highest(3)[1] + syminfo.mintick, 0) : na
stop_comment = "Stoploss triggered"
strategy.close("Long", low <= stop_price, stop_comment)
strategy.close("Short", high >= stop_price, stop_comment)
plot(stop_price, "Stop price", color.red, 2, plot.style_linebr)
// EMA cross close orders
if ema_cross_stop
if long_position and ema_bear
strategy.close("Long", comment=stop_comment)
if short_position and ema_bull
strategy.close("Short", comment=stop_comment)
// Take profit orders
stop_ticks = abs(strategy.position_avg_price - stop_price)
take_profit_price = long_position ? valuewhen(bought, strategy.position_avg_price + stop_ticks * risk_reward_ratio, 0) : short_position ? valuewhen(sold, strategy.position_avg_price - (stop_ticks * risk_reward_ratio), 0) : na
target_comment = "Take profit"
strategy.close("Long", high >= take_profit_price, target_comment)
strategy.close("Short", low <= take_profit_price, target_comment)
plot(take_profit_price, "Target price", color.green, 2, plot.style_linebr)