트리플 EMA 트레일링 스톱 전략


생성 날짜: 2023-10-17 15:05:41 마지막으로 수정됨: 2023-10-17 15:05:41
복사: 2 클릭수: 715
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

트리플 EMA 트레일링 스톱 전략

개요

이 전략은 전형적인 트리플 지수 이동 평균 거래 전략의 구현이다. 그것은 비교적 빠른 5일 EMA, 중간 빠른 20일 EMA, 그리고 느린 50일 EMA의 교차 상황을 통해 거래 신호를 생성한다. 동시에, 그것은 또한 현재 K 라인 종결 가격보다 하루 전에 종결 가격 상승 또는 하락의 특정 티크를 결합하여 가짜 신호를 필터링한다. 또한, 이 전략은 수익을 잠금하기 위해 중지 손실을 추적한다.

원칙

5일 EMA 상에서 20일 EMA를 통과하고, 세 EMA가 다목렬로 되어있는 경우, 그리고 현재 K 라인 종료 가격이 전날 종료 가격 상승보다 특정 틱을 넘어서면, 더 많이 한다. 5일 EMA 아래에서 20일 EMA를 통과하고, 세 EMA가 공백으로 되어있는 경우, 그리고 현재 K 라인 종료 가격이 전날 종료 가격 하락보다 특정 틱을 넘어서면, 공백한다.

진입 후, 가격이 특정 틱을 초과하면, 추적 스톱 메커니즘을 시작하여 가격 변동에 따라 스톱 라인을 지속적으로 조정하여 더 많은 을 잠금합니다.

장점

  1. 트리플 EMA를 사용하여 거래 신호를 형성하여 시장 소음을 효과적으로 필터링하여 트렌드를 식별할 수 있습니다. 빠른 EMA는 최신 변화를 반영하고, 중속 EMA는 트렌드 방향을 결정하고, 느린 EMA는 흔들림을 필터링합니다.

  2. 현재 K 라인 종료 가격과 전날 종료 가격의 비교를 추가하면 가짜 신호를 더욱 필터링하고 불필요한 거래를 줄일 수 있습니다.

  3. 트래킹 스톱 메커니즘을 사용하여 시장의 움직임에 따라 스톱 라인을 동적으로 조정하여 수익을 최대한 고정 할 수 있습니다.

  4. 이 전략의 매개 변수는 다양하고 주기적으로 최적화될 수 있으며, 일선에서 분선까지 모두 적용된다.

위험

  1. 위기 상황에서 EMA 교차 신호가 자주 발생하여 거래 수수료와 슬라이드 비용을 증가시키는 과도한 거래가 발생할 수 있습니다.

  2. 트래킹 스톱은 큰 흔들림에서 조기 중단될 수 있으며, 전체 트렌드를 유지할 수 없습니다.

  3. EMA 지연 특성은 트렌드 전환점을 놓칠 수 있으며 손실을 초래할 수 있습니다.

  4. EMA 주기 길이나, 스톱로스틱 추적 등과 같은 최적화 파라미터가 필요하며, 다른 품종과 주기별 효과는 큰 차이가 있다.

최적화 방향

  1. MACD, KD 등과 같은 다른 지표와 결합하여 거래 신호를 필터링 할 수 있습니다.

  2. 특정 품종 및 주기 파라미터에 따라 테스트 및 최적화하여 최적의 파라미터 조합을 찾을 수 있다.

  3. 인체 개입이나 기계 학습과 같은 방법을 통해 동적으로 변수를 조정할 수 있다.

  4. 특정 상황에서는 트레이킹 스톱을 종료하고, 전체 포지션을 보유하는 경향을 고려할 수 있다.

  5. 자동 정지와 결합하여 단순한 추적 정지 대신 사용할 수 있다.

요약하다

이 전략은 EMA 교차, 가격 돌파 및 스톱 로드 추적의 세 가지 일반적인 기술 분석 방법을 통합하여 보다 포괄적이고 신뢰할 수 있는 트렌드 추적 거래 시스템을 형성한다. 매개 변수를 최적화하여 다양한 품종과 주기에 적응할 수 있으며, 트렌드가 뚜렷한 시장에서 더 잘 작동한다. 그러나 이 전략에는 전형적인 기술 분석 전략의 약점이 있으며, 더 많은 시장 상황에 대응하기 위해 추가적인 최적화가 필요합니다.

전략 소스 코드
/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-02 12:00:00
period: 1m
basePeriod: 1m
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/
// © Matt Dearden - IndoPilot
// @version=4

/////////////////////////////////////////////////////// Initial Parameters /////////////////////////////////////////////////////// 
SystemName = "Triple EMA Strategy"
ShortSystemName = "TEMA"
InitPosition = 0
InitCapital = 50000
InitCommission = 0.004 //approx value to compensate for Oanda spreads
InitPyramidMax = 0
CalcOnorderFills = true

strategy(title=SystemName, shorttitle=ShortSystemName, overlay=true, pyramiding=InitPyramidMax, 
 default_qty_type=strategy.cash, default_qty_value=InitPosition, commission_type=strategy.commission.percent, 
 commission_value=InitCommission, initial_capital=InitCapital, max_lines_count=500, 
 max_labels_count=500, process_orders_on_close=false, calc_on_every_tick=false) 

///////////////////////////////////////////////////////////// Inputs /////////////////////////////////////////////////////////////

DateFilter = input(false, "═════ Data Filtering ═════") 
InitYear = input(title="Year", type=input.integer, defval=2021, minval=2000, maxval=2021)
InitMonth = input(title="Month (0=ALL)", type=input.integer, defval=0, minval=0, maxval=12)
InitStopLoss = input(title="Stop Loss (ticks)", type=input.integer, defval=100, minval=0, maxval=1000) 
TrailingStopLoss = input(title="Trailing S/L (ticks)", type=input.integer, defval=130, minval=0, maxval=1000) 
InitBuffer = input(title="Buffer (ticks)", type=input.integer, defval=15, minval=0, maxval=1000) 
InitEMA1 = input(title="EMA 1", type=input.integer, defval=5, minval=0, maxval=1000) 
InitEMA2 = input(title="EMA 2", type=input.integer, defval=20, minval=0, maxval=1000) 
InitEMA3 = input(title="EMA 3", type=input.integer, defval=50, minval=0, maxval=1000) 

//////////////////////////////////////////////////////////// Variables ///////////////////////////////////////////////////////////

var StopLoss = float(0.0)
var StartPrice = float(0.0)
//setup multipliers and catch JPY difference
Multiplier = syminfo.currency == "JPY" ? 10 : 1000
//get the daily exchange rate from yesterday
//X_rate = security(AccountCurrency+syminfo.currency, "D", close[1]) 
OrderQty = 1  
Buffer = InitBuffer / (Multiplier * 100)

/////////////////////////////////////////////////////// Triple EMA Strategy //////////////////////////////////////////////////////

EMA1 = ema(close, InitEMA1)
EMA2= ema(close, InitEMA2)
EMA3 = ema(close, InitEMA3)

//entry conditions
longCondition = crossover(EMA1, EMA2) and close > EMA3 and EMA1 > EMA3 and EMA2 > EMA3 and close > (close[1] + Buffer) 
shortCondition = crossunder(EMA1, EMA2) and close < EMA3 and EMA1 < EMA3 and EMA2 < EMA3 and close < (close[1] - Buffer) 

/////////////////////////////////////////////////////// Trailing Stoploss ////////////////////////////////////////////////////////

if (strategy.position_size > 0 and (close > (StartPrice + (TrailingStopLoss / (100 * Multiplier)))))  
    StopLoss := max(StopLoss, close - (TrailingStopLoss / (100 * Multiplier))) 
    strategy.exit("Long Stoploss", "Long") 
    
if (strategy.position_size < 0 and (close < (StartPrice - (InitStopLoss / (100 * Multiplier))))) 
    StopLoss := min(StopLoss, close + (TrailingStopLoss / (100 * Multiplier)))
    strategy.exit("Short Stoploss", "Short") 
    
///////////////////////////////////////////////////////// Setup entries /////////////////////////////////////////////////////////

if (longCondition)
    StartPrice := close
    StopLoss := StartPrice - (InitStopLoss / (100 * Multiplier)) 
    strategy.entry("Long", strategy.long, qty=OrderQty)
    strategy.exit("Long Stoploss", "Long")

if (shortCondition)
    StartPrice := close
    StopLoss := StartPrice + (InitStopLoss / (100 * Multiplier)) 
    strategy.entry("Short", strategy.short, qty=OrderQty)
    strategy.exit("Short Stoploss", "Short")
    
///////////////////////////////////////////////////////// Draw the EMAs /////////////////////////////////////////////////////////
plot(EMA1, "EMA1", color=#00FF00)
plot(EMA2, "EMA2", color=#FF0000)
plot(EMA3, "EMA3", color=#4040FF)