이중 이동 평균 및 모멘텀 브레이크 전략

저자:차오장, 날짜: 2024-02-06 14:39:22
태그:

img

전반적인 설명

이 전략은 12일 EMA와 26일 EMA의 황금 십자가를 입점 신호로 사용합니다. 가짜 브레이크오웃을 필터링하기 위해 MACD는 시장 트렌드와 RSI를 과잉 구매 / 과잉 판매 수준에 대해 판단하는 데 적용됩니다. 저항 이상의 가격 브레이크오웃도 확인으로 사용됩니다.

전략은 세 가지 선택적 인 스톱 손실 방법을 제공합니다. 후속 스톱 손실, 이동 평균 스톱 및 이동 평균 크로스 오버 스톱. 두 가지 수익 목표가 설정됩니다.

전략 논리

  1. 입력 신호
    • 12일 EMA와 26일 EMA의 골든 크로스
    • MACD는 긍정이고 MACD 라인은 신호 라인의 위입니다.
    • 미리 설정된 범위 내의 RSI
  2. 입국 확인
    • 선택: 동적 저항 이상 가격 파업
  3. 손실 중지
    • 엔트리 가격과 미리 설정된 비율에 기초한 트래일링 스톱 로스
    • 7일 SMA 아래로 닫습니다.
    • 12일 및 26일 EMA 사이의 하락적 크로스
  4. 이윤 을 취하라
    • 2단계 취득 목표, 첫 번째 목표에서 부분적인 입장을 종료 하 고 두 번째에 모든

장점

  1. MA 시스템은 잘못된 신호를 필터링하여 입력 정확도를 향상시킵니다.
  2. 다른 트레이더 스타일에 대한 여러 스톱 로스 옵션
  3. 동적 후속 정지 제어 위험
  4. 단계적으로 수익을 가져다가 수익을 얻습니다.

위험성

  1. 시장의 변동으로 더 많은 잘못된 신호가 나타납니다.
  2. 후속 스톱은 강한 실행 후 침투 할 수 있습니다.
  3. 트렌드 반전 때 제때 빠져나오지 못하면

해결책:

  1. 실제 트렌드를 판단하기 위해 MACD를 사용
  2. 후속 비율 조정
  3. 다른 정지 방법 또는 정지 조합을 사용

강화

  1. 최고의 성능을 위해 MA 매개 변수를 최적화
  2. 다른 정류장을 테스트하고 가장 좋은 방법을 찾습니다
  3. 더 나은 보상을 위해 수익 수준을 조정
  4. 다른 지표와 함께 필터를 추가
  5. 다른 제품과 시간 프레임에 맞게 사용자 정의

결론

이 전략은 엔트리 신호를 위해 MA 시스템을 사용하며 MACD, RSI 등에 의해 추가 필터를 사용합니다. 정지 및 수익 목표 모두 다른 트레이더 스타일과 일치하도록 최적화됩니다. 성능을 더욱 향상시키기 위해 엔트리 타이밍, 정지 방법, 수익 수준을 최적화 할 수있는 많은 공간이 있습니다.


/*backtest
start: 2023-01-30 00:00:00
end: 2024-02-05 00:00:00
period: 1d
basePeriod: 1h
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/
// © AbdulRahimShama
//@version=5


strategy('12/26-IT strategy', overlay=true,initial_capital = 100000)



Show_Only_12_26_Crossover_Entry = input.bool(true, group = "Entry_Exit Criteria")
Show_12_26_Crossover_and_resistance_Entry = input.bool(false, group = "Entry_Exit Criteria")


Show_TSL_StopLoss = input.bool(true, group = "Entry_Exit Criteria")
Show_Crossdown_StopLoss = input.bool(true, group = "Entry_Exit Criteria")
Show_SMA7_StopLoss = input.bool(false, group = "Entry_Exit Criteria")



////////////////////////////////////////////////
////////////////TARGETS INPUT
////////////////////////////////////////////////

////////Target1

TargetPerc1 = input.float(title="Target (%)", minval=0,defval=5, group="Target-1") / 100
TargetPrice1 = strategy.position_avg_price * (1 + TargetPerc1)
Target1_exit_qty = input.int(50, group="Target-1",tooltip = "% qty to sell when Target1 is reached")



////////Target2

TargetPerc2 = input.float(title="Target (%)", minval=0,defval=10, group="Target-2") / 100
TargetPrice2 = strategy.position_avg_price * (1 + TargetPerc2)
Target2_exit_qty = input.int(100, group="Target-2",tooltip = "% qty to sell when Target2 is reached")



////////////////////////////////////////////////
////////////////TRAILING STOP LOSS
////////////////////////////////////////////////


TSLsource = input(low, title="TSL Source", group="Trailing StopLoss")

longTrailPerc = input.float(title='Trail Long Loss (%)', minval=0.0, step=0.1, defval=1, group="Trailing StopLoss") * 0.01

TrailStopPrice = 0.0

TrailStopPrice := if strategy.position_size > 0
    sPIVOT_highValue = TSLsource * (1 - longTrailPerc)
    math.max(sPIVOT_highValue, TrailStopPrice[1])
else
    0

TSL = close < TrailStopPrice
plot(series=strategy.position_size > 0 and Show_TSL_StopLoss ? TrailStopPrice : na, color=color.new(color.fuchsia, 0), style=plot.style_linebr, linewidth=2, title='Trailing StopLoss')




////////////////////////////////////////////////
////////////////Moving Averages
////////////////////////////////////////////////



EMA_12=ta.ema(close, 12)
EMA_26=ta.ema(close, 26)
EMA_21=ta.ema(close,21)

plot(EMA_12, title="EMA_12", color=color.rgb(0, 255, 0), offset=0, linewidth=1)
plot(EMA_26, title="EMA_26", color=color.rgb(0, 0, 255), offset=0, linewidth=1)
plot(Show_SMA7_StopLoss ? ta.sma(close,7) : na, title="SMA_7", color=color.rgb(255, 0, 0), offset=0, linewidth=1)



////////////////////////////////////////////////
////////////////RESISTANCE INPUT and PLOTTING
////////////////////////////////////////////////

CrossOverLookbackCandles = input.int(10, group= "RESISTANCE")

resistanceSRC = input(high, group= "RESISTANCE")
resistanceLEFT = input(10, group= "RESISTANCE")
resistanceRIGHT = input(10, group= "RESISTANCE")

hih = ta.pivothigh(resistanceSRC, resistanceLEFT, resistanceRIGHT)
top = ta.valuewhen(hih, resistanceSRC[resistanceRIGHT], 0)

res = plot(top, color=top != top[1] ? na : color.new(#00ff00, 50), offset=-resistanceLEFT, linewidth=2, title="Resistance Line")

EMA_12_Low = ta.lowest(EMA_12, CrossOverLookbackCandles)
EMA_26_Low = ta.lowest(EMA_26, CrossOverLookbackCandles)


////////////////////////////////////////////////
////////////////RSI INPUT and PLOTTING
////////////////////////////////////////////////
RSI = ta.rsi(close, 14)
RSILowerRange = input.int(50, tooltip = "RSI value should be ABOVE this value for entry", group = "RSI")
RSIUpperRange = input.int(70, tooltip = "RSI value should be BELOW this value for entry", group = "RSI")



////////////////////////////////////////////////
////////////////MACD
////////////////////////////////////////////////
fast_length = 12
slow_length = 26
MACD_src = close
signal_length = 9

fast_ma = ta.ema(MACD_src, fast_length)
slow_ma = ta.ema(MACD_src, slow_length)
macd = fast_ma - slow_ma
signal = ta.ema(macd, signal_length)
hist = macd - signal



////////////////////////////////////////////////
////////////////ENTRY CRITERIA
////////////////////////////////////////////////


BUYVALUE= input(100000, tooltip = "Buy qty displayed on chart will be based on this value")

BASEENTRY = macd > signal and RSI > RSILowerRange and RSI < RSIUpperRange and close > EMA_21 and close > ta.sma(close, 7)


Entry= ta.crossover(EMA_12, EMA_26) and BASEENTRY
Entry2 = ta.crossover(close, top) and EMA_12_Low < EMA_26_Low and EMA_12 > EMA_26 and RSI < 70

////////////////////////////////////////////////
////////////////BUY SELL STRATEGY
////////////////////////////////////////////////

if ((Entry and Show_Only_12_26_Crossover_Entry))
    strategy.entry("buy", strategy.long, qty=BUYVALUE/close)

if (Entry2 and Show_12_26_Crossover_and_resistance_Entry)
    strategy.entry("buy", strategy.long, qty=BUYVALUE/close)

strategy.exit("Tg1", "buy", limit=TargetPrice1, qty_percent = Target1_exit_qty)
strategy.exit("Tg2", "buy", limit=TargetPrice2, qty_percent = Target2_exit_qty)



if TSL and Show_TSL_StopLoss and close < EMA_12 
    strategy.close_all ("sl")

if ta.crossunder(EMA_12, EMA_26) and Show_Crossdown_StopLoss
    strategy.close_all ("sl")

if ta.crossunder(close, ta.sma(close, 7)) and Show_SMA7_StopLoss
    strategy.close_all ("sl")




더 많은