
이 전략은 쌍 EMA 평균선에 기반한 동적 스톱 손실 추적 전략이다. 9일선, 20일선에서 시장 추세 방향을 판단하고, RSI 지표 필터링 가짜 파열과 결합한다. 동적 스톱 손실과 스톱 포지션을 ATR 지표에 사용하면서 계산한다. 이 전략은 중장선 포지션에 적용된다.
이 전략은 9일 EMA를 단기 평균선으로, 20일 EMA를 중기 평균선으로 사용하여 가격 추세를 판단한다. 가격이 단기 평균선을 상회하고 종결 가격이 전날 최고 가격보다 높고 RSI가 30보다 높을 때, 더 많이 한다. 가격이 단기 평균선을 상회하고 종결 가격이 전날 최저 가격보다 낮고 RSI가 70보다 낮을 때, 공백한다.
스톱로스는 클로즈 가격의 ATR값을 1.5배 빼고, 클로즈 가격에 ATR값을 곱한 스톱 계수를 세우고, 트렌드 추적 스톱을 ATR의 2배로 설정한다.
이 전략은 전체적으로 좀 더 안정적인 중·장기선 포지션 전략이다. 이중 EMA 판단 시장의 주요 추세와 결합하여 단기 시장 소음에 영향을 받지 않도록 결정한다. RSI 지표의 포함도 어느 정도 가짜 브레이크를 필터링한다. 또한, 동적 스톱 메커니즘은 이 전략이 시장의 변동 정도에 따라 자신의 스톱 수준을 조정할 수 있도록 한다. 그러나 이 전략에는 일정 수준의 위험도 있다.
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("CJTrade", overlay=true)
short = ema(close, 9)
medium = ema(close, 20)
long = ema(close, 50)
very_long = ema(close, 200)
plot(short, color=color.gray, linewidth=1)
plot(medium, color=color.red, linewidth=1)
plot(long, color=color.black, linewidth=1)
plot(very_long, color=color.blue, linewidth=1)
rsiValue = rsi(close, 14)
near20EMA = close > medium - atr(14)
longCond = crossover(close[1], short) and close >= high[1] and rsiValue < 70 and near20EMA
shortCond = crossunder(close[1], short) and close <= low[1] and rsiValue > 30 and near20EMA
strategy.entry("Long", strategy.long, when=longCond)
strategy.entry("Short", strategy.short, when=shortCond)
atrValue = atr(14)
stopLossLevel = close - atrValue * 1.5
// Dynamic take profit level based on ATR
takeProfitMultiplier = input(2, title="Take Profit Multiplier", minval=0.1, maxval=10, step=0.1)
takeProfitLevel = close + atrValue * takeProfitMultiplier
// Trailing stop loss for long positions
longTrailingStop = close - atrValue * 2
strategy.exit("LongTrailingStop", from_entry="Long", loss=longTrailingStop)
// Trailing stop loss for short positions
shortTrailingStop = close + atrValue * 2
strategy.exit("ShortTrailingStop", from_entry="Short", loss=shortTrailingStop)
strategy.exit("Take Profit/Stop Loss", from_entry="Long", loss=stopLossLevel, profit=takeProfitLevel)
strategy.exit("Take Profit/Stop Loss", from_entry="Short", loss=stopLossLevel, profit=takeProfitLevel)