이 전략은 이동 평균과 상대적으로 강한 지표의 장점을 최대한 활용하여 트렌드를 식별하고 추적합니다. 트렌드를 판단하고 엔트리 / 출구의 시점을 선택할 수 있도록 두 가지 지표만 필요합니다. 이 전략은 중·장선 가격 트렌드를 포착하여 단기 시장 소음으로 인해 오해받지 않도록합니다.
이 전략은 3개의 다른 주기의 EMA 평균선을 사용한다. EMA-A는 가장 짧은 주기이고, EMA-B는 가장 긴 주기이다. 짧은 주기 EMA-A 위에 긴 주기 EMA-B를 뚫을 때, 가격이 상승 추세에 있다는 것을 나타낸다. 이 때 더 많이 할 수 있다. 반대로, EMA-A 아래에 EMA-B를 뚫을 때, 가격이 하향 추세로 바뀌는 것을 나타낸다. 이 때 공백을 할 수 있다.
이 전략은 또한 RSI 지표와 결합하여 출구 시점을 설정합니다. 다수 상위 포지션이 있을 때, RSI가 70 라인을 넘으면 상위 포지션이 됩니다. 공백 상위 포지션이 있을 때, RSI가 30 라인을 넘으면 상위 포지션이 됩니다. 이것은 트렌드 수익을 고정하고 손실이 더 확장되는 것을 방지합니다.
RSI 파라미터를 최적화하거나 추가 필터 조건을 추가하여 이러한 위험을 줄일 수 있습니다. 또한 트렌드, 지지 저항과 같은 기술 분석 방법을 결합하여 전략 성능을 향상시킬 수 있습니다.
이 전략은 트렌드 추적과 오버 바이 오버 소드 지표를 통합하여, 단지 두 가지의 간단한 지표만 필요하면 트렌드에 대한 판단과 포착이 가능합니다. 매개 변수 최적화 및 규칙 최적화를 통해 단순하면서 효과를 크게 향상시킬 수 있습니다. 그것은 매우 실용적인 트렌드 추적 전략 템플릿이며, 중장선 투자자에게 적합합니다.
/*backtest
start: 2023-08-26 00:00:00
end: 2023-09-25 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/
//@author Alorse
//@version=5
// strategy(title='Tendency EMA + RSI [Alorse]', shorttitle='Tendece EMA + RSI [Alorse]', overlay=true, pyramiding=0, currency=currency.USD, default_qty_type=strategy.percent_of_equity, initial_capital=1000, default_qty_value=20, commission_type=strategy.commission.percent, commission_value=0.01)
// Bollinger Bands
len = input.int(14, minval=1, title='Length', group='RSI')
src = input.source(close, 'Source', group='RSI')
rsi = ta.rsi(src, len)
// Moving Averages
len_a = input.int(10, minval=1, title='EMA A Length', group='Moving Averages')
out_a = ta.ema(close, len_a)
plot(out_a, title='EMA A', color=color.purple)
len_b = input.int(20, minval=1, title='EMA B Length', group='Moving Averages')
out_b = ta.ema(close, len_b)
plot(out_b, title='EMA B', color=color.orange)
len_c = input.int(100, minval=1, title='EMA C Length', group='Moving Averages')
out_c = ta.ema(close, len_c)
plot(out_c, title='EMA B', color=color.green)
// Strategy Conditions
stratGroup = 'Strategy'
showLong = input.bool(true, title='Long entries', group=stratGroup)
showShort = input.bool(false, title='Short entries', group=stratGroup)
closeAfterXBars = input.bool(true, title='Close after X # bars', tooltip='If trade is in profit', group=stratGroup)
xBars = input.int(24, title='# bars')
entryLong = ta.crossover(out_a, out_b) and out_a > out_c and close > open
exitLong = rsi > 70
entryShort = ta.crossunder(out_a, out_b) and out_a < out_c and close < open
exitShort = rsi < 30
bought = strategy.opentrades[0] == 1 and strategy.position_size[0] > strategy.position_size[1]
entry_price = ta.valuewhen(bought, open, 0)
var int nPastBars = 0
if strategy.position_size > 0
nPastBars := nPastBars + 1
nPastBars
if strategy.position_size == 0
nPastBars := 0
nPastBars
if closeAfterXBars
exitLong := nPastBars >= xBars and close > entry_price ? true : exitLong
exitLong
exitShort := nPastBars >= xBars and close < entry_price ? true : exitShort
exitShort
// Long Entry
strategy.entry('Long', strategy.long, when=entryLong and showLong)
strategy.close('Long', when=exitLong)
// Short Entry
strategy.entry('Short', strategy.short, when=entryShort and showShort)
strategy.close('Short', when=exitShort)