Skip to content

Commit b58acab

Browse files
author
root
committed
update
1 parent f576aa8 commit b58acab

File tree

1,708 files changed

+409569
-2173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,708 files changed

+409569
-2173
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
2+
> Name
3+
4+
10EMA双重交叉趋势追踪策略10EMA-Double-Cross-Trend-Tracking-Strategy
5+
6+
> Author
7+
8+
ChaoZhang
9+
10+
> Strategy Description
11+
12+
![IMG](https://www.fmz.com/upload/asset/13247113d03535be2c3.png)
13+
[trans]
14+
15+
## 概述
16+
17+
该策略是一个基于10EMA和50EMA双重交叉的趋势追踪策略。它结合了小时线的10EMA作为辅助判断,在牛熊交替的市场中 dynamically 找到趋势方向,实现自动追踪止损。
18+
19+
## 策略原理
20+
21+
策略的核心逻辑是基于10EMA和50EMA的金叉死叉。具体来说,当10EMA从下方上穿50EMA形成金叉时,判断行情进入上涨趋势;当10EMA从上方下穿50EMA形成死叉时,判断行情进入下跌趋势。
22+
23+
在金叉死叉后的1-5根K线内开仓做多做空。此外,策略还引入小时线的10EMA作为辅助判断,只有当小时线的10EMA处于上升趋势时才在金叉后开多仓,只有小时线的10EMA处于下降趋势时才在死叉后开空仓,从而过滤掉部分假signals。
24+
25+
在开仓后,策略采用追踪止损+限价停利的出场方式。追踪止损能够锁定利润并最大限度确保交易盈利;限价停利确保在价格达到目标点时关闭头寸获得利润。
26+
27+
## 策略优势
28+
29+
该策略最大的优势在于利用EMA交叉判断主要趋势方向的同时,还引入辅助指标过滤信号,能有效地过滤假交叉从而提高信号的可靠性。此外双重EMA交叉结合追踪止损和限价止盈,既能最大化追踪趋势收益,又能有效控制交易风险,整体风险收益比良好。
30+
31+
相比单一指标策略,该策略能更准确判断趋势方向和 amplitudes。与传统止损止盈相比,该策略采用更为先进的追踪止损技术,能更好地锁定利润。
32+
33+
## 风险分析
34+
35+
该策略主要面临 intermittent whipsaw 和趋势反转的风险。当出现连续的假交叉信号时,可能导致策略被套利。此外,在开仓后价格反转也会产生损失。
36+
37+
为了降低 whipsaw 的风险,策略加入辅助指标进行信号过滤。为了控制趋势反转的风险,策略采用较为宽容的止损范围,同时限价止盈设置也能帮助减少此类风险。当止损被触发时,还可考虑重新进入趋势方向。
38+
39+
## 优化方向
40+
41+
该策略还有几个可优化的方向:第一,可以测试不同参数组合,如EMA周期、开仓延迟根数等,寻找最优参数;第二,可以引入更多辅助指标,如MACD、BOLL等进行信号过滤,提高信号质量;第三,可以优化止损止盈逻辑,如采用时间止损、振荡止损等其他止损方式;第四,可以结合更多行情条件开启策略交易,如只在某些时间段或涨跌幅度下触发信号等。
42+
43+
## 总结
44+
45+
该10EMA双重交叉趋势追踪策略,通过EMA golden cross 和 death cross 判断当前趋势方向,设置追踪止损和限价止盈来锁定利润和控制风险,同时结合辅助指标过滤信号提高信号质量,是一种较为完备的趋势交易策略。相比单一指标和传统止盈止损,该策略具有判断准确、止盈止损优化等优势,能够有效获取趋势收益的同时控制风险,是一种适合常规交易账户的策略。当然该策略也还有一定改进空间,通过参数优化、加入更多辅助指标等方式可进一步增强策略表现。
46+
47+
||
48+
49+
## Overview
50+
51+
This strategy is a trend tracking strategy based on the double cross of 10EMA and 50EMA. It incorporates the 10EMA on the hourly chart as an auxiliary judgement to dynamically find the trend direction in the alternating bull and bear market, and achieve automatic tracking stop loss.
52+
53+
## Strategy Principle
54+
55+
The core logic of the strategy is based on the golden cross and death cross of 10EMA and 50EMA. Specifically, when the 10EMA crosses above the 50EMA to form a golden cross, it is judged that the market has entered an uptrend; when the 10EMA crosses below the 50EMA to form a death cross, it is judged that the market has entered a downtrend.
56+
57+
Open long or short positions within 1-5 bars after the golden cross or death cross. In addition, the strategy also introduces the 10EMA on the hourly chart as an auxiliary judgment. Long positions are opened only when the 10EMA on the hourly chart is in an upward trend after the golden cross, and short positions are opened only when the 10EMA on the hourly chart is in a downward trend after the death cross, thus filtering out some false signals.
58+
59+
After opening positions, the strategy adopts a profit-taking and stop loss method of tracking stop loss + limit order. Tracking stop loss can lock in profits and maximize profitability of transactions; limit orders ensure that positions are closed when prices reach the target to obtain profits.
60+
61+
## Advantage Analysis
62+
63+
The biggest advantage of this strategy is that while using EMA crosses to judge the main trend direction, it also introduces auxiliary indicators to filter signals, which can effectively filter false crosses to improve signal reliability. In addition, the double EMA cross combined with trailing stop loss and limit profit taking can both maximize tracking trend gains and effectively control trading risks with good overall risk-reward ratio.
64+
65+
Compared with single indicator strategies, this strategy can more accurately judge trend direction and amplitudes. Compared with traditional stop loss, this strategy adopts more advanced tracking stop loss technology to better lock in profits.
66+
67+
## Risk Analysis
68+
69+
The main risks this strategy faces are intermittent whipsaws and trend reversals. When consecutive false crossing signals occur, the strategy may be scraped. In addition, price reversals after opening positions can also lead to losses.
70+
71+
To reduce the risk of whipsaws, auxiliary indicators are added to filter the signals. To control the risk of trend reversal, a relatively tolerant stop loss range is adopted, and the limit profit setting also helps reduce this risk. When the stop loss is triggered, it is also possible to consider re-entering the trend direction.
72+
73+
## Optimization Directions
74+
75+
There are several optimization directions for this strategy: first, different parameter combinations such as EMA periods and position delay bars can be tested to find the optimal parameters; secondly, more auxiliary indicators such as MACD and BOLL can be introduced for signal filtering to improve signal quality; thirdly, stop loss and take profit logic can be optimized, such as adopting other stop loss methods like time stop loss and oscillating stop loss; fourthly, more market conditions can be combined to trigger strategy trading signals, such as only triggering signals during certain time periods or fluctuation ranges.
76+
77+
78+
## Summary
79+
80+
This 10EMA double cross trend tracking strategy judges the current trend direction through EMA golden crosses and death crosses, sets up tracking stop loss and limit profit taking to lock in profits and control risks, while combining auxiliary indicators to filter signals and improve signal quality. Compared with single indicator and traditional stop loss strategies, this strategy has advantages like accurate judgement, optimized stop profit mechanism, etc. It can effectively capture trend gains while controlling risks, making it suitable for conventional trading accounts. Of course there is still room for improvement for this strategy, such as further enhancing strategy performance through parameter optimization and introducing more auxiliary indicators.
81+
82+
[/trans]
83+
84+
> Strategy Arguments
85+
86+
87+
88+
|Argument|Default|Description|
89+
|----|----|----|
90+
|v_input_int_1|10|short ema|
91+
|v_input_int_2|50|long ema|
92+
|v_input_int_3|200|hourly 10 ema|
93+
|v_input_1_close|0|Source: close|high|low|open|hl2|hlc3|hlcc4|ohlc4|
94+
|v_input_int_4|false|Offset|
95+
96+
97+
> Source (PineScript)
98+
99+
``` javascript
100+
/*backtest
101+
start: 2022-12-22 00:00:00
102+
end: 2023-12-28 00:00:00
103+
period: 1d
104+
basePeriod: 1h
105+
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
106+
*/
107+
108+
//@version=5
109+
strategy("10ema Strat 9", overlay=true, format=format.price)
110+
//#region // inputs for candles
111+
//time
112+
t1 = time(timeframe.period,"0930-1500") //last hour of market is not ideal for trading
113+
// candle status
114+
bullish = close > open and barstate.isconfirmed
115+
bearish = open > close and barstate.isconfirmed
116+
bullcandle = ta.valuewhen(bullish, close, 0)
117+
bearcandle = ta.valuewhen(bearish, close, 0)
118+
ema1 = input.int(10, minval=1, title="short ema")
119+
ema2 = input.int(50, minval=1, title="long ema")
120+
ema3 = input.int(200, minval=1, title="hourly 10 ema")
121+
//@variable Input for source
122+
src = input(close, title="Source")
123+
offsetema = input.int(title="Offset", defval=0, minval=-500, maxval=500)
124+
sema = ta.ema(src, ema1)//@variable Input for smaller ema1
125+
lema = ta.ema(src, ema2)//@variable Input for longer ema2
126+
hema = ta.ema(src, ema3)// @variable Input for hourly ema3
127+
bullcrosscount = ta.barssince(ta.crossover(sema,lema)) //@variable Input 10/50 cross higher
128+
bearcrosscount = ta.barssince(ta.crossunder(sema,lema)) //@variable Input 10/50 cross lower
129+
ideallong = bullcrosscount <= 5 //number of candles after the cross
130+
idealshort = bearcrosscount <= 5 //number of candles after the cross
131+
132+
emabull = (sema > lema) and bearish and close > sema and close > hema and ideallong and t1 and barstate.isconfirmed
133+
xemabull = ta.barssince(emabull)
134+
dbullema = emabull and emabull[1] and xemabull <=1
135+
bullentry = if dbullema
136+
ta.valuewhen(emabull[1], high + 0.05, 0)
137+
else
138+
ta.valuewhen(emabull, high + 0.05, 0)
139+
bullentryh = dbullema ? bullentry[1] : bullentry
140+
bullentrylow = ta.valuewhen(emabull, low - 0.05, 0)
141+
bullstop = (bullentryh - bullentrylow) <= 1.00 ? bullentryh - 1.00 : (bullentryh - bullentrylow) <= 10.40 ? bullentrylow : na
142+
bulltarget = (bullentryh - bullstop) * 1.62 + bullentryh
143+
144+
// bear setup
145+
emabear = (sema < lema) and bullish and close < sema and close < hema and idealshort and t1 and barstate.isconfirmed
146+
xemabear = ta.barssince(emabear)
147+
dbearema = emabear and emabear [1] and xemabear <=1
148+
bearentry = if dbearema
149+
ta.valuewhen(emabear[1], low - 0.05, 0)
150+
else
151+
ta.valuewhen(emabear, low - 0.05, 0)
152+
bearentryh = dbearema ? bearentry[1] : bearentry
153+
bearentryhigh = ta.valuewhen(emabear, high + 0.05, 0)
154+
bearstop = (bearentryhigh - bearentryh) <= 1.00 ? bearentryh + 1.00 : (bearentryh - bearentryhigh) <= 10.40 ? bearentryhigh : na
155+
beartarget = bearentryh - (bearstop-bearentryh) * 1.62
156+
157+
bullclose = (xemabull <=7) and bullish and bullcrosscount >=1 and barstate.isconfirmed //number of candles for a close above
158+
bearclose = (xemabear <=7) and bearish and bearcrosscount >=1 and barstate.isconfirmed //number of candles for a close below
159+
buyzone = ta.barssince(bullclose)
160+
shortzone = ta.barssince(bearclose)
161+
idealbuy = close >= bullentryh and bullclose and (buyzone<=7)
162+
idealsell = close <= bearentryh and bearclose and (shortzone<=7)
163+
164+
// // bull setup on chart
165+
// if sema > lema and xemabull < 50
166+
// var line line_bullentry = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
167+
// if emabull
168+
// line.set_xy1(line_bullentry, x=bar_index, y=bullentryh)
169+
// line.set_xy2(line_bullentry, x=bar_index, y=bullentryh)
170+
// alert("EMA-bullish", alert.freq_once_per_bar_close)
171+
// line.set_x2(line_bullentry, x=bar_index)
172+
// var line line_bullstop = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
173+
// if emabull
174+
// line.set_xy1(line_bullstop, x=bar_index, y=bullstop)
175+
// line.set_xy2(line_bullstop, x=bar_index, y=bullstop)
176+
// line.set_x2(line_bullstop, x=bar_index)
177+
// var line line_bulltarget = line.new(bar_index, na, bar_index + 1, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
178+
// if emabull
179+
// line.set_xy1(line_bulltarget, x=bar_index, y=bulltarget)
180+
// line.set_xy2(line_bulltarget, x=bar_index, y=bulltarget)
181+
// line.set_x2(line_bulltarget, x=bar_index)
182+
183+
// //bear setup on chart
184+
// if sema < lema and xemabear < 50
185+
// var line line_bearentry = line.new(bar_index, na, bar_index, na, color=color.rgb(0, 200, 0), style=line.style_solid, width=1)
186+
// if emabear
187+
// line.set_xy1(line_bearentry, x=bar_index, y=bearentryh)
188+
// line.set_xy2(line_bearentry, x=bar_index, y=bearentryh)
189+
// alert("EMA-bearish", alert.freq_once_per_bar_close)
190+
// line.set_x2(line_bearentry, x=bar_index)
191+
// var line line_bearstop = line.new(bar_index, na, bar_index, na, color=color.rgb(250, 0, 0), style=line.style_solid, width=1)
192+
// if emabear
193+
// line.set_xy1(line_bearstop, x=bar_index, y=bearstop)
194+
// line.set_xy2(line_bearstop, x=bar_index, y=bearstop)
195+
// line.set_x2(line_bearstop, x=bar_index)
196+
// var line line_beartarget = line.new(bar_index, na, bar_index, na, color=color.rgb(200, 100, 200), style=line.style_solid, width=1)
197+
// if emabear
198+
// line.set_xy1(line_beartarget, x=bar_index, y=beartarget)
199+
// line.set_xy2(line_beartarget, x=bar_index, y=beartarget)
200+
// line.set_x2(line_beartarget, x=bar_index)
201+
202+
//#endregion
203+
//execution
204+
if idealbuy
205+
strategy.close("sell", comment=na)
206+
strategy.entry("buy", strategy.long, limit=bullentryh, stop=bullstop, comment="buy")
207+
strategy.exit("exit","buy", trail_points = low, trail_offset = 5, qty_percent=100, limit=bulltarget, stop=bullstop)
208+
209+
if idealsell
210+
strategy.close("buy",comment=na)
211+
strategy.entry("sell", strategy.short, limit=bearentryh, stop=bearstop, comment="sell")
212+
strategy.exit("exit","sell", trail_points = low, trail_offset = 5, qty_percent=100, limit=beartarget, stop=bearstop)
213+
// strategy.close_all(time == close_day)
214+
//#region // graphical analysis
215+
//Plots
216+
plotshape(emabull, location=location.belowbar, title='emabull')
217+
plotshape(idealbuy, style=shape.circle, color=color.green, title="bull close")
218+
plotshape(emabear, title='emabear')
219+
plotshape(idealsell, location=location.belowbar, style=shape.circle, color=color.red, title="bear close")
220+
221+
// //Dashboard
222+
// var label id = na
223+
// label.delete(id) // Delete last label
224+
// i_offsetLabel = input(15, "Data Dashboard Offset")
225+
// offset = i_offsetLabel * (time - time[1])
226+
// dynamicText = "= Bull Setup ="
227+
// id := label.new(x=time + offset, y=open, xloc=xloc.bar_time, text=dynamicText, color=color.rgb(255, 255, 255), size=size.normal)
228+
// label.set_textcolor(id, color.rgb(0, 0, 0))
229+
// label.set_text(id=id, text=dynamicText)
230+
// label.set_textalign(id, text.align_left)
231+
// label.set_text(id=id, text=dynamicText)
232+
// f_round( _val, _decimals) =>
233+
// _p = math.pow(10, _decimals)
234+
// math.round(math.abs(_val) * _p) / _p * math.sign(_val)
235+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bulltarget,2)) + " :Target"
236+
// label.set_text(id=id, text=dynamicText)
237+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullentryh,2)) + " :Entry"
238+
// label.set_text(id=id, text=dynamicText)
239+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bullstop,2)) + " :Stop"
240+
// label.set_text(id=id, text=dynamicText)
241+
// dynamicText := dynamicText + "\n"
242+
// label.set_text(id=id, text=dynamicText)
243+
// dynamicText := dynamicText + "\n" + "= Bear Setup ="
244+
// label.set_text(id=id, text=dynamicText)
245+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearstop,2)) + " :Stop"
246+
// label.set_text(id=id, text=dynamicText)
247+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(bearentryh,2)) + " :Entry"
248+
// label.set_text(id=id, text=dynamicText)
249+
// dynamicText := dynamicText + "\n" + str.tostring(f_round(beartarget,2)) + " :Target"
250+
// label.set_text(id=id, text=dynamicText)
251+
// //#endregion
252+
```
253+
254+
> Detail
255+
256+
https://www.fmz.com/strategy/437021
257+
258+
> Last Modified
259+
260+
2023-12-29 16:03:55

0 commit comments

Comments
 (0)