Name
动量追踪型双EMA移动平均线交叉策略Momentum-Tracking-Dual-EMA-Crossover-Strategy
Author
ChaoZhang
Strategy Description
该策略是一种趋势跟踪型算法交易策略,它通过计算两条不同参数的EMA均线,并在均线发生Golden Cross(金叉)和Death Cross(死叉)时发出交易信号。该策略同时结合了多个EMA均线进行盈利退出,并设置了止损点以控制风险。
该策略使用4条EMA均线,包括一组快速EMA均线和慢速EMA均线,它们的交叉用于产生买入和卖出信号。此外,该策略还使用了两条介于快慢EMA之间的参数的EMA均线,用于提前部分或全部退出持仓,锁定利润。
具体来说,当快速EMA上穿慢速EMA时,产生买入信号;当快速EMA下穿慢速EMA时,产生卖出信号。这是典型的双EMA移动平均线交叉策略。为了更好地跟踪趋势和提高盈利率,该策略在进入持仓后,会在快速EMA上穿第二条EMA均线或快速EMA下穿第三条EMA均线时,选择性退出部分或全部头寸。
此外,该策略还设置了长线和短线两个止损点,防止亏损扩大。具体来说,多单止损幅度设置为入场价的6%,空单止损幅度设置为入场价的3%。
相比典型的双EMA移动平均线交叉策略,该策略的主要优势有:
-
设置多个EMA均线进行盈利退出,可以更好地锁定利润,防止利润在后续回调中缩水。
-
空头头寸具有较小的止损幅度,可以承受更大的正常行情震荡,防止频繁止损。
-
设置不同的参数EMA均线进行盈利退出,可以根据市场情况,选择最优的退出点。
-
整体策略具有较好的趋势跟踪能力,可以捕捉中长线趋势带来的较大利润。
该策略主要的风险点包括:
-
在震荡行情中,EMA均线生成的交易信号频繁,容易产生过度交易。
-
短线止损点只能防止极端行情,无法防止策略账户大幅回撤。
-
该策略回撤风险仍然存在,当遇到长期调整行情时,收益可能会大幅缩水。
-
该策略对参数调整比较敏感,不当配置可能导致策略失效。
考虑到上述风险,该策略可以从以下几个方面进行优化:
-
增加机器学习算法,辅助判断趋势,降低误交易概率。
-
增加自适应止损机制,可以根据市场波动程度,动态调整止损幅度。
-
设置资金利用率,避免策略账户占用过多资金,增加仓位管理机制。
-
对交易品种进行筛选,选择趋势明显、波动较大的标的进行交易。
-
增加参数优化模块,实现参数的自动优化和更新。
该双EMA移动平均线交叉策略整体上是一个性价比较高的趋势跟踪策略。它具有设置多个EMA均线进行盈利退出、空头小止损、趋势跟踪能力较强等优点。但该策略也存在一定的风险,需要对参数调整进行优化,并辅助以机器学习等算法进一步提高策略稳定性。总体上,该策略适合有一定交易经验的投资者进行算法交易。
||
This strategy is a trend-following algorithmic trading strategy. It calculates two EMA lines with different parameters and generates trading signals when the Golden Cross and Death Cross occur between the two EMAs. The strategy also combines multiple EMA lines for profit exit and sets stop loss points to control risks.
The strategy uses 4 EMA lines, including a fast EMA and a slow EMA, whose crossover is used to generate buy and sell signals. In addition, two EMA lines with parameters between fast and slow EMAs are used to partially or completely exit positions in advance to lock in profits.
Specifically, when the fast EMA crosses above the slow EMA, a buy signal is generated. When the fast EMA crosses below the slow EMA, a sell signal is generated. This is a typical dual-EMA crossover strategy. To better track trends and increase profitability, after entering a position, the strategy will selectively exit part or all of the position when the fast EMA crosses above the second EMA line or when the fast EMA crosses below the third EMA line.
In addition, the strategy sets both long and short stop loss points to prevent excessive losses. Specifically, the stop loss for long positions is set at 6% of the entry price, and 3% for short positions.
Compared with a typical dual-EMA crossover strategy, the main advantages of this strategy include:
-
Setting up multiple EMA lines for profit exit can better lock in profits and prevent profit shrinkage during subsequent pullbacks.
-
The short position has a smaller stop loss, which can withstand greater normal market fluctuations and prevent frequent stop loss.
-
Setting EMA lines with different parameters for profit exit allows choosing the optimal exit point based on market conditions.
-
The overall strategy has good trend-following capability to capture greater profits from mid- to long-term trends.
The main risks of this strategy include:
-
In range-bound markets, the trading signals generated by the EMA lines are frequent, which can lead to over-trading.
-
The short stop loss can only prevent extreme market conditions and cannot prevent significant drawdowns in the strategy account.
-
The risk of drawdowns still exists. Profits may shrink significantly when long-term adjustment occurs.
-
The strategy is sensitive to parameter tuning. Improper configuration may cause strategy failure.
In view of the above risks, the strategy can be optimized in the following aspects:
-
Increase machine learning algorithms to assist in trend judgment and reduce mis-trading probabilities.
-
Increase adaptive stop loss mechanism to dynamically adjust stop loss based on market volatility.
-
Set capital utilization to avoid excessive capital occupation and increase position management mechanism.
-
Select trading products with obvious trends and high fluctuations.
-
Increase parameter optimization module to achieve automatic optimization and update of parameters.
Overall, the dual-EMA crossover strategy is a cost-effective trend-following strategy. It has advantages like multiple EMA lines for profit taking, small short stops, and good trend-following capability. However, there are still some risks with this strategy. It needs further parameter tuning optimization and incorporation of machine learning algorithms to improve stability. In general, this strategy is suitable for investors with some trading experience to carry out algorithm trading.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 6 | Fast_EMA |
v_input_2 | 26 | Slow_EMA |
v_input_3 | 10 | Sell_EMA_Exit |
v_input_4 | 20 | Buy_EMA_Exit |
v_input_5 | 1000 | Order_Value in Pounds |
v_input_6 | Both | Trade Direction |
Source (PineScript)
/*backtest
start: 2023-02-19 00:00:00
end: 2024-02-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RealTraderAkeme
//@version=5
strategy("AKEME_EMA_CROSS_V6", overlay=true)
////////////////////////////////////////////////////////////PARAMETERS/////////////////////////////////////////////////////////////////
emaFast_op = input(title="Fast_EMA", defval=6)
emaSlow_op = input(title="Slow_EMA", defval=26)
emaExit_op = input(title="Sell_EMA_Exit",defval=10)
emabuyExit_op = input(title="Buy_EMA_Exit",defval=20)
Order_Value = input(defval=1000, title="Order_Value in Pounds")
Direction_Of_Trade = input(title="Trade Direction", defval="Both")
////////////////////////////////////////////////////////////INPUTS//////////////////////////////////////////////////////////////////
fastEMA = ta.ema(close, emaFast_op)
slowEMA = ta.ema(close,emaSlow_op)
emaExit = ta.ema(close,emaExit_op)
emabuyExit = ta.ema(close,emabuyExit_op)
Entry_Ratio = strategy.openprofit/Order_Value
//////////////////////////////////////////////////////////GRAPHS//////////////////////////////////////////////////////////////////
plot(fastEMA, color=color.orange, linewidth = 2)
plot(slowEMA,color = color.blue, linewidth = 2)
plot(emaExit,color = color.gray, linewidth = 2)
plot(series=emabuyExit, color= color.rgb(210, 74, 235), linewidth=2)
/////////////////////////////////////////////////////Conditions//////////////////////////////////////////////////////////////////////
longOK = (Direction_Of_Trade == "Long") or (Direction_Of_Trade == "Both")
shortOK = (Direction_Of_Trade == "Short") or (Direction_Of_Trade == "Both")
///////////////////////////////////////////////////////////ENTRIES&EXITS///////////////////////////////////////////////////////////////
longCondition = ta.crossover(fastEMA, slowEMA) and longOK
if (longCondition)
strategy.entry("Buy", strategy.long)
shortCondition = ta.crossunder(fastEMA, slowEMA) and shortOK
if (shortCondition)
strategy.entry("Sell", strategy.short)
if (strategy.position_size > 0 and shortCondition)
strategy.exit(id="exit Buy", stop=close)
if (strategy.position_size < 0 and longCondition)
strategy.exit(id="exit Sell", stop=close)
/////////////////////////////////////////////////////TAKE PROFIT CONDITIONS////////////////////////////////////////////////////////
if ta.crossunder(fastEMA, emabuyExit) and Entry_Ratio > 0.08333
strategy.close("Buy",comment = "Exit")
if ta.crossover(fastEMA, emaExit) and Entry_Ratio > 0.016666
strategy.close("Sell",comment = "Exit")
if Entry_Ratio > 0.4166666 //0.4166666
strategy.close("Buy",comment = "Exit", qty_percent = 100)
if Entry_Ratio > 0.0833333//0.0833333
strategy.close("Sell",comment = "Exit")//50
if Entry_Ratio > 0.1111111//4000
strategy.close("Sell",comment = "Exit", qty_percent = 50)
if ta.crossover(fastEMA, emaExit) and Entry_Ratio > 0.278 //Percentage
strategy.close("Sell",comment = "Exit")
////////////////////////////////////////////STOP LOSS AS PERCENTAGE OF ENTRY CONDITIONS///////////////////////////////////////////
if Entry_Ratio < -0.05555555555
strategy.close("Buy",comment = "Exit")
if Entry_Ratio < -0.027777777777
strategy.close("Sell",comment = "Exit")// The Sell Stoloss is half the buying stoploss.
Detail
https://www.fmz.com/strategy/442860
Last Modified
2024-02-26 16:40:29