이중 이동평균 트렌드 전략

저자:차오장, 날짜: 2023-09-24 13:14:08
태그:

전반적인 설명

이 전략은 트렌드 방향을 결정하기 위해 장기 RMA와 단기 EMA 크로스오버를 사용한다. 이는 지각 손실을 위해 최근 최고 최고 또는 최저 최저를 추적한다. 또한 잘못된 브레이크를 피하기 위해 RMA 주위에는 거래 금지 구역이 있다.

전략 논리

  1. 긴 기간 RMA와 짧은 기간 EMA를 사용하여 트렌드를 결정합니다. 긴 RMA 아래의 짧은 EMA를 넘어서면 하락 추세를 나타냅니다. 위의 신호를 넘어서면 상승 추세를 나타냅니다.

  2. 가격이 특정 기간 동안 최근 최고 최고치를 넘을 때, 가장 높은 최고치를 Stop Loss로 추적합니다. 가격이 가장 낮은 최저치를 넘을 때, 가장 낮은 최저치를 Stop Loss로 추적합니다.

  3. RMA 주위에는 거래 금지 구역을 설정하십시오. 윙사브를 피하기 위해 가격이 구역 내에있을 때 포지션을 열지 마십시오. 구역 범위는 RMA 가치의 특정 비율에 기반합니다.

  4. 입점 후 수익 비율로 출구 포지션에 수익을 가져가는 가격을 설정합니다.

장점

  1. 이중 이동 평균의 크로스오버는 트렌드 방향을 안정적으로 결정합니다.

  2. 트렌드에 따라 스톱 로스가 움직입니다.

  3. 무역 금지 구역은 가짜 탈출 신호를 필터합니다.

  4. 이윤을 취하는 전략은 수익성있는 거래를 적극적으로 닫을 수 있습니다.

위험성

  1. 이동평균의 크로스오버에 지연하면 손실이 증가할 수 있습니다.

  2. 가격에 너무 가까이 있는 스톱 로스는 소음으로 인해 멈출 수 있습니다.

  3. 무역 금지 구역이 너무 넓으면 기회를 놓칠 수 있습니다.

  4. 제 시간에 멈추지 않으면 더 많은 손실이 발생할 수 있습니다.

가능한 해결책:

  1. 지연을 줄이기 위해 이동 평균 매개 변수를 최적화합니다.

  2. 과도한 감수성을 방지하기 위해 스톱 로스를 약간 넓혀주세요.

  3. 거래 구역을 조정하여 거래가 빠지지 않도록 테스트합니다.

  4. 최대 손실을 제한하기 위해 다른 스톱 손실 메커니즘을 추가합니다.

최적화 방향

  1. 다른 이동 평균 조합을 테스트하여 더 잘 맞을 수 있습니다.

  2. 스프레드, MACD 등을 추가하여 안정성을 향상시킵니다.

  3. 머신러닝을 사용하여 매개 변수를 지능적으로 최적화합니다.

  4. 트렌드 강도를 포함하여 트렌드 반대 거래를 피합니다.

  5. 더 높은 승률을 위해 자금 관리를 최적화하십시오.

요약

이 전략은 트렌드 방향을 결정하기 위해 이중 이동 평균 크로스오버를 사용하며 트렌드 수익을 잠금하기 위해 후속 스톱과 노 트레이드 영역을 결합합니다. 프레임워크는 간단하고 확장 가능합니다. 매개 변수 범위를 조정하고 출구를 최적화하고 추가 필터와 신호를 통합하여 다른 시장에서 견고하게 만들 수 있습니다.


/*backtest
start: 2023-08-24 00:00:00
end: 2023-09-12 00:00:00
period: 3h
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/
// © PatrickGwynBuckley

//@version=5
//var initialCapital = strategy.equity

strategy("PB Trend Scalper", "PB Trend Scalper", overlay = true)
shortma = input.int(55, title="quick ma's")
longma = input.int(100, title="long ma's")
ema55h = ta.ema(high, shortma)
ema55l = ta.ema(low, shortma)
ema200h = ta.rma(high, longma)
ema200l = ta.rma(low, longma)
stock = ta.stoch(close, high, low, 14)

lev = input.int(3, title="leverage")
hhVal = input.int(170, title="Highest high period")
llVal = input.int(170, title="Lowest low period")

hh = ta.highest(high, hhVal)
ll = ta.lowest(low, llVal)
//plot(stock)

plot(hh, color=color.new(color.green, 50))
plot(ll, color=color.new(color.red, 50))
var float downtrade = 0
p = input.float(3.0, title="no trade zone")
l = 3
emadistlong = ema200h + ((ema200h/100)*p)
emadistshort = ema200l - ((ema200h/100)*p)

plot(ema55h)
plot(ema55l)
ntl = plot(emadistlong, color=color.new(color.red, 10))
nts = plot(emadistshort, color=color.new(color.red, 10))
fill(ntl, nts, color=color.new(color.red, 90))

//position size

EntryPrice = close
//positionValue = initialCapital
positionSize = (strategy.equity*lev) / EntryPrice

//plot(strategy.equity)


//standard short

if ema55h < ema200l and close[2] < ema55l and close[1] > ema55l and high[1] < ema55h and close < ema55h and ema55h < emadistshort and strategy.opentrades == 0// and stock > 85 
    strategy.entry("short", strategy.short, qty=positionSize, comment="short")
    downtrade := 1

//reset count    
if (ta.crossunder(ema55h, ema200l)) and downtrade == 1
    downtrade := 0

//standard long    
if ema55l > ema200h and close[2] > ema55h and close[1] < ema55h and low[1] > ema55l and close > ema55l and ema55l > emadistlong and strategy.opentrades <= 1// and stock < 15 
    strategy.entry("long", strategy.long, qty=positionSize, comment="long")
    downtrade := 0

//RESET COUNT ON MA CROSS
if (ta.crossover(ema55l, ema200h)) and downtrade == 0
    downtrade := 1
    
longclose2 = low < ll[1] or low < emadistshort //close < open and open<open[1] and open[2] < open[3] and open[3] < emadistshort//close < ta.lowest(low, 20)//
shortclose2 = high > hh[1] or high>emadistlong//close > open and open>open[1] and open[2]>open[3] and open[3] > emadistlong//high > emadistlong//close > ta.highest(high, 20)//

sl = 3.5
tp = input.float(6.9, title="take profit %")
tp2 = 10


strategy.exit("long exit", "long", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))
strategy.close("long", when = longclose2, comment = "long exit")
//strategy.close("long", when = (downtrade == 1), comment = "long exit")
//strategy.exit("long exit", "long2", profit = (strategy.position_avg_price*(tp2)))//, loss = (strategy.position_avg_price*(sl)))
//strategy.close ("long2", when = longclose2, comment = "long exit")
//strategy.close("long", when = (downtrade == 1), comment = "long exit")

strategy.exit("short exit", "short", profit = (strategy.position_avg_price*(tp)))//, loss = (strategy.position_avg_price*(sl)))//, loss = 300)
strategy.close("short", when = shortclose2, comment = "short exit")
//strategy.close("short", when = (downtrade == 0), comment = "short exit")
//strategy.exit("short exit", "short2", profit = (strategy.position_avg_price*(tp2)))//, loss = (strategy.position_avg_price*(sl)))
//strategy.close ("short2", when = shortclose2, comment = "short exit")
//strategy.close("short2", when = (downtrade == 0), comment = "short exit")

//if (strategy.exit("long exit", "long"))
    //downtrade := 1
//else 
   // downtrade := 0

더 많은