该策略使用5日指数移动平均线(EMA5)和13日指数移动平均线(EMA13)的交叉来产生交易信号。当EMA5上穿EMA13时,产生做多信号;当EMA5下穿EMA13时,产生做空信号。该策略旨在捕捉短期趋势的变化,并利用两条移动平均线的交叉来确定进场和出场点。
该策略的核心是利用两条不同周期的指数移动平均线(EMA)的交叉来产生交易信号。EMA是一种常用的技术指标,它对最近的价格数据赋予更高的权重,因此相比简单移动平均线(SMA)更能及时反映价格的变化。当短期EMA(如EMA5)上穿长期EMA(如EMA13)时,表明价格上涨动能增强,产生做多信号;反之,当短期EMA下穿长期EMA时,表明价格下跌动能增强,产生做空信号。
EMA5与EMA13交叉策略是一种简单易用的趋势跟踪策略,通过两条不同周期EMA的交叉来捕捉价格趋势的变化。该策略优势在于简单、适应性强、及时性高,但同时也存在假信号、滞后性和缺乏止损等风险。为进一步优化策略表现,可以考虑加入趋势过滤、设置止损、优化参数以及结合其他技术指标等方法。在实际应用中,需要根据具体的市场环境和交易品种进行调整和优化。
/*backtest start: 2023-05-11 00:00:00 end: 2024-05-16 00:00:00 period: 2d basePeriod: 1d 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/ // © Milankacha //@version=5 strategy('5-13 EMA by Naimesh ver04', overlay=true) qty = input(1, 'Buy quantity') testStartYear = input(2021, 'Backtest Start Year') testStartMonth = input(1, 'Backtest Start Month') testStartDay = input(1, 'Backtest Start Day') testStartHour = input(0, 'Backtest Start Hour') testStartMin = input(0, 'Backtest Start Minute') testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, testStartHour, testStartMin) testStopYear = input(2099, 'Backtest Stop Year') testStopMonth = input(1, 'Backtest Stop Month') testStopDay = input(30, 'Backtest Stop Day') testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0) testPeriodBackground = input(title='Color Background?', defval=true) testPeriodBackgroundColor = testPeriodBackground and time >= testPeriodStart and time <= testPeriodStop ? #00FF00 : na testPeriod() => true ema1 = input(5, title='Select EMA 1') ema2 = input(13, title='Select EMA 2') //ema3 = input(50, title='Select EMA 3') //SL = input(70, title='Stoploss') //TR = input(250, title='Target') expo = ta.ema(close, ema1) ma = ta.ema(close, ema2) //EMA_50 = ta.ema(close, ema3) //avg_1 = avg (expo, ma) //s2 = ta.cross(expo, ma) ? avg_1 : na //plot(s2, style=plot.style_line, linewidth=3, color=color.red, transp=0) p1 = plot(expo, color=color.rgb(231, 15, 15), linewidth=2) p2 = plot(ma, color=#0db63a, linewidth=2) fill(p1, p2, color=color.new(color.white, 80)) longCondition = ta.crossover(expo, ma) shortCondition = ta.crossunder(expo, ma) if testPeriod() //strategy.entry('Long', strategy.long, when=longCondition) strategy.entry('Short', strategy.short, when=expo<ma) //strategy.close("Long", expo<ma, comment= 'SL hit') strategy.close("Short", expo>ma, comment= 'SL hit') //plotshape(longCondition and close>EMA_50, title='Buy Signal', text='B', textcolor=color.new(#FFFFFF, 0), style=shape.labelup, size=size.normal, location=location.belowbar, color=color.new(#1B8112, 0)) //plotshape(shortCondition and close<EMA_50, title='Sell Signal', text='S', textcolor=color.new(#FFFFFF, 0), style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.new(#FF5733, 0))