이중 매끄러운 이동 평균 거래 전략

저자:차오장, 날짜: 2023-10-13 15:45:58
태그:

전반적인 설명

이 전략은 트레이드 신호 필터링을 위한 TDFI 볼륨 검증 지표와 결합한 두 개의 부드러운 이동 평균 시스템을 주요 거래 신호로 활용하여 부드러운 이동 평균의 장점을 활용하고 트렌드 없는 시장에서 잘못된 거래를 줄입니다.

전략 논리

이 전략은 주요 거래 신호로 서로 다른 매개 변수 구성의 매끄러운 이동 평균의 두 세트를 사용한다. 먼저 8주기 빠른 매끄러운 이동 평균이 초기 확인으로 사용되고, 그 다음 약간 느린 16주기 매끄러운 이동 평균이 두 번째 확인으로 작용한다. 빠른 MA가 구매 신호를 할 때, 느린 MA가 마지막 1-2 바 내에서 동일한 방향으로 신호를 내면 긴 포지션을 열린다. 빠른 MA가 판매 신호를 할 때, 느린 MA가 마지막 1-2 바 내에서 동일한 방향으로 신호를 내면 짧은 포지션을 열린다. 두 번째 확인 MA가 방향을 역전할 때 출구가 유발된다. 또한, TDFI 볼륨 지표는 잘못된 가격 신호를 필터링하기 위해 거래 볼륨 뒤에 거래 볼륨을 감지하는 데 사용됩니다. 거래는 기대에 부합할 때만 취한다.

장점

  • 매끄러운 MAs는 중장기 동향을 파악하여 트렌드를 효과적으로 추적하고 시장 소음을 피합니다.
  • 이중 매끄러운 MA 설정은 신호 신뢰성을 향상시키고 트렌드 없는 시장에서 잘못된 거래를 피합니다.
  • 부적절한 손실을 피하기 위해 낮은 부피 신호를 오해하는 볼륨 표시기 도입 필터
  • 높은 매개 변수 최적화 공간, 다른 제품과 시간 프레임에 맞게 조정할 수 있습니다, 매우 적응력

위험성

  • 매끄러운 MAs는 트렌드 반전을 식별하는 데 시간이 오래 걸릴 수 있으며, 잠재적으로 일부 손실을 초래할 수 있습니다.
  • 이중 매끄러운 MAs는 트렌드가 아닌 시장에서 동시에 잘못된 신호를 생성 할 수 있습니다.
  • 부피 표시기는 제한된 효과를 가지고 있으며 모든 잘못된 신호를 필터 할 수 없습니다.

위험을 줄이기 위해 다음과 같은 최적화 방향을 고려할 수 있습니다.

  • 트렌드 강도 지표를 추가하여 트렌드 반전을 식별하는 데 도움이 됩니다.
  • 더 효과적인 빠른 / 느린 구성을 위해 매끄러운 MA 매개 변수를 최적화
  • 잘못된 저음량 신호를 더 잘 필터하기 위해 다른 볼륨 표시기를 테스트하십시오.

최적화 방향

  • 트렌드 반전을 식별하는 데 도움이되는 MACD 등을 추가하십시오.
  • 다른 제품 특성에 맞게 ATR 중지 및 제한값을 조정합니다.
  • 전략 수익을 향상시키기 위해 위치 크기를 증가 시도
  • 안정성을 높이기 위해 백테스트 결과를 기반으로 매개 변수를 최적화

요약

전체적으로 이것은 전형적인 트렌드를 따르는 전략이다. TDFI 볼륨 필터와 결합된 이중 부드러운 MA 시스템은 트렌드 추적 기능을 효과적으로 활용할 수 있으며 트렌드가 아닌 시장에서 잘못된 신호 비율을 줄일 수 있다. 매개 변수 최적화를 통해 다른 시간 프레임과 제품에 적응할 수 있다. 그러나 기계적 응용보다 매개 변수 조정에 더 의존한다. 트렌드 역전 식별과 매개 변수 조정 영향이 부족하다는 점에 유의해야 한다. 전반적으로 명확하고 간결한 접근 방식, 추가 최적화와 연습에 가치가 있다.


/*backtest
start: 2022-10-06 00:00:00
end: 2023-10-12 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Designed per No Nonsense Forex VP rules
//Made to be as modular as possible, so we can swap the indicators in and out.
//Originated from causecelebre
//Tried to put in as much VP rules as possible

///////////////////////////////////////////////////
//Rules Implemented:
///////////////////////////////////////////////////
// - SL 1.5 x ATR
// - TP 1 x ATR
//
// - Entry conditions
//// - Entry within first confirmation cross over and 1 candle of second confirmation + volume
// - Exit conditions
//// - Exit on exit indicator or when baseline or confirmation flip 

///////////////////////////////////////////////////
//Trades entries
///////////////////////////////////////////////////
// - First entry L1 or S1 with standard SL and TP

///////////////////////////////////////////////////
//Included Indicators and settings
///////////////////////////////////////////////////
// - Confirmtion = SSL 8, 16
// - Volume = TDFI 6

///////////////////////////////////////////////////
//Credits
// Strategy causecelebre https://www.tradingview.com/u/causecelebre/
// TDFI causecelebre https://www.tradingview.com/u/causecelebre/
// SSL Channel ErwinBeckers https://www.tradingview.com/u/ErwinBeckers/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// strategy(title="NNFX Strategy 3 Indicator Template | jh", overlay = true, pyramiding=0, initial_capital=20000, currency=currency.USD, calc_on_order_fills=0,default_qty_type=strategy.fixed, default_qty_value=10000)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  **** Set the main stuff  ****
///////////////////////////////////////////////////

//Price
price = close

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ATR stuff
///////////////////////////////////////////////////

slMultiplier = input(1.5, "SL")
tpMultiplier = input(1, "TP")

atrlength = input(title="ATR Length", defval=14, minval=1)
atrsmoothing = input(title="Smoothing", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])

ma_function(source, atrlength) => 
    if atrsmoothing == "RMA"
        rma(source, atrlength)
    else
        if atrsmoothing == "SMA"
            sma(source, atrlength)
        else
            if atrsmoothing == "EMA"
                ema(source, atrlength)
            else
                wma(source, atrlength)

//plot(ma_function(tr(true), atrlength), title = "ATR", color=#991515, transp=0)

atr = ma_function(tr(true), atrlength)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  **** Confirmation 1 Fast ****
///////////////////////////////////////////////////

///////////////////////////////////////////////////
//SSL 6
///////////////////////////////////////////////////

ssllen1=input(title="SSL 1 Length Period", defval=8)
smaHigh1=sma(high, ssllen1)
smaLow1=sma(low, ssllen1)
Hlv1 = na
Hlv1 := close > smaHigh1 ? 1 : close < smaLow1 ? -1 : Hlv1[1]
sslDown1 = Hlv1 < 0 ? smaHigh1: smaLow1
sslUp1   = Hlv1 < 0 ? smaLow1 : smaHigh1

plot(sslDown1, "SSL Down", linewidth=1, color=red)
plot(sslUp1, "SSL Up", linewidth=1, color=lime)

///////////////////////////////////////////////////
//Confirm Signals
///////////////////////////////////////////////////

c_Up = sslUp1
c_Down =sslDown1

//Signals based on crossover
c_cross_Long = crossover(c_Up, c_Down)
c_cross_Short = crossover(c_Down, c_Up)

//Signals based on signal position
c_trend_Long = c_Up > c_Down ? 1 : 0
c_trend_Short = c_Down > c_Up ? 1 : 0

confirm_Long = c_cross_Long
confirm_Short = c_cross_Short

plotshape(c_cross_Long, color = green, style=shape.triangleup, location=location.top)
plotshape(c_cross_Short, color = red, style=shape.triangledown, location=location.top)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  **** Confirmation 2 Slow ****
///////////////////////////////////////////////////

///////////////////////////////////////////////////
//SSL 30
///////////////////////////////////////////////////

///////////////////////////////////////////////////
//SSL
///////////////////////////////////////////////////

ssllen2=input(title="SSL 2 Length Period", defval=16)
smaHigh2=sma(high, ssllen2)
smaLow2=sma(low, ssllen2)
Hlv2 = na
Hlv2 := close > smaHigh2 ? 1 : close < smaLow2 ? -1 : Hlv2[1]
sslDown2 = Hlv2 < 0 ? smaHigh2: smaLow2
sslUp2   = Hlv2 < 0 ? smaLow2 : smaHigh2

plot(sslDown2, "SSL Down", linewidth=1, color=orange)
plot(sslUp2, "SSL Up", linewidth=1, color=blue)

///////////////////////////////////////////////////
//Confirm Signals
///////////////////////////////////////////////////
c2_Up = sslUp2
c2_Down = sslDown2

//Signals based on crossover
c2_cross_Long = crossover(c2_Up, c2_Down)
c2_cross_Short = crossover(c2_Down, c2_Up)

//Signals based on signal position
c2_trend_Long = c2_Up > c2_Down ? 1 : 0
c2_trend_Short = c2_Down > c2_Up ? 1 : 0

confirm2_Long = c2_trend_Long
confirm2_Short = c2_trend_Short

plotshape(c2_cross_Long, color = green, style=shape.triangleup, location=location.bottom)
plotshape(c2_cross_Short, color = red, style=shape.triangledown, location=location.bottom)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  **** Volume Indicator Start ****
///////////////////////////////////////////////////

///////////////////////////////////////////////////
//TDFI
///////////////////////////////////////////////////

lookback = input(6, title = "TDFI Lookback") 
filterHigh = input(0.05, title = "Filter High") 
filterLow = input(-0.05, title = "Filter Low") 

mma = ema(price * 1000, lookback)
smma = ema(mma, lookback)

impetmma = mma - mma[1]
impetsmma= smma - smma[1]
divma = abs(mma - smma)
averimpet = (impetmma + impetsmma) / 2

number = averimpet
pow = 3
result = na

for i = 1 to pow - 1
    if i == 1
        result := number
    result := result * number

tdf = divma * result
ntdf = tdf / highest(abs(tdf), lookback * 3)

///////////////////////////////////////////////////
//Volume Signals
///////////////////////////////////////////////////
v_Long = ntdf > filterHigh ? 1 : 0
v_Short = filterLow > ntdf ? 1 : 0

volumeLong = v_Long
volumeShort = v_Short

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// **************************** Logic to handle NNFX rules ****************************
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Checking for confirmation indication with 1 candle difference for second confirmtion and volume
enterLong   = confirm_Long and (confirm2_Long[0] or confirm2_Long[1])      and (volumeLong[0] or volumeLong[1]) ? 1 : 0
enterShort  = confirm_Short and (confirm2_Short[0] or confirm2_Short[1])   and (volumeShort[0] or volumeShort[1]) ? 1 : 0

exitLong = c_cross_Short or c2_cross_Short ? 1 : 0 
exitShort = c_cross_Long or c2_cross_Long ? 1 : 0 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Entries and Exits
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if (year>2009)

    //Long entries with standard 1.5 ATR for SL, 1 ATR for TP
    long_sl = price - (atr * slMultiplier)
    long_tp = price + (atr * tpMultiplier)

    //Short entries with standard 1.5 ATR for SL, 1 ATR for TP
    short_sl = price + (atr * slMultiplier)
    short_tp = price - (atr * tpMultiplier)

    strategy.close("L1", when = exitLong)
    strategy.close("S1", when = exitShort)

    strategy.exit("L Limit Exit", "L1", stop = long_sl, limit = long_tp)
    strategy.exit("S Limit Exit", "S1", stop = short_sl, limit = short_tp)

    strategy.order("L1", strategy.long, when = enterLong)
    strategy.order("S1", strategy.short, when = enterShort)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//End
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



    




더 많은