여러 시간 프레임에 걸쳐 지원/저항 및 동력 지표에 기초한 트렌드 다음 전략

저자:차오장, 날짜: 2024-03-08 17:41:26
태그:

img

전략 개요

이 전략은 트렌드 방향을 포괄적으로 결정하고 트렌드 다음 거래 시스템을 구현하기 위해 여러 시간 프레임에 걸쳐 지원 / 저항 수준, 슈퍼 트렌드 및 이동 평균을 포함한 여러 기술적 지표를 결합합니다. 이 전략의 주요 아이디어는: 먼저, 현재 지원 / 저항 수준을 결정하기 위해 피보트 포인트를 사용하십시오. 다음으로, 현재 트렌드 방향을 식별하기 위해 슈퍼 트렌드 지표를 사용하십시오. 마지막으로, 오차를 필터링하기 위해 이동 평균을 사용하십시오. 동시에 전략은 시간 창을 설정하고 최대 거래 지위를 제한하는 것과 같은 위험 통제 조치를 지원합니다.

전략 원칙

  1. 먼저, 현재 지지/저항 수준을 얻기 위해 지난 일정 기간 동안 가장 높고 가장 낮은 가격에 기초한 중추점을 계산합니다.
  2. 트렌드를 결정하기 위해 슈퍼트렌드 지표를 사용하십시오. 슈퍼트렌드는 동적 지지/저항 수준에서 계산된 트렌드를 따르는 지표입니다.
  3. 스톱 로스를 위해 ATR를 사용하십시오. 이 전략은 원래 슈퍼 트렌드 위에 스톱 로스 수준으로 ATR을 통합합니다.
  4. 유동 평균을 트렌드 필터로 사용하십시오. 트렌드가 상승하고 가격이 유동 평균보다 높을 때만 길게 이동하고 트렌드가 하락하고 가격이 유동 평균보다 낮을 때만 짧게 이동하십시오.
  5. 거래 시간 창을 설정합니다. 중요한 시간점에 거래를 피하기 위해 특정 시간 간격 내에서만 포지션을 열십시오.
  6. 긴 포지션과 짧은 포지션을 별도로 관리합니다. 긴 신호와 짧은 신호는 각각의 오픈 및 종료 논리를 독립적으로 작동시킵니다.

요약하자면, 이 전략은 피보트 포인트 지원/저항, 슈퍼 트렌드 방향, 이동 평균 방향이 모두 일치할 때 지점에 진입하고, 이 조건 중 하나가 무효가 될 때 지점을 닫습니다. 이것은 위험을 제어하면서 트렌드 시장 움직임을 효과적으로 포착합니다.

이점 분석

  1. 지원/저항 수준에 기반한 거래의 장점은 시장에서 수요와 공급의 법칙에 부합하고, 피워트 포인트는 시장 균형을 동적으로 반영할 수 있다는 것입니다.
  2. 슈퍼트렌드는 트렌드를 효과적으로 파악하고 적시에 손실을 멈추게 할 수 있습니다. ATR 스톱 손실은 위험을 더 제어합니다.
  3. 이동 평균 필터링은 역 트렌드 거래를 피합니다. 트렌드와 이동 평균이 동기화 될 때 시장에 진입하면 더 높은 승률이 발생합니다.
  4. 사용자 정의 가능한 거래 시간 창은 시장이 열리고 닫기 전에 중요한 시간점에 거래하는 것을 어느 정도 피합니다.
  5. 롱과 쇼트 신호는 독립적으로 작동하여 롱과 쇼트 포지션을 동시에 보유하여 시장 기회를 더 완벽하게 활용 할 수 있습니다.

위험 분석

  1. 빈번한 거래의 위험: 이 전략은 오스실레이션 시장에서 빈번하게 포지션을 열고 닫을 수 있으며, 과도한 거래 비용을 초래할 수 있습니다.
  2. 역동 트렌드 거래는 여전히 발생할 수 있습니다. 이 전략은 이동 평균 필터링을 채택하지만 이동 평균 자체가 주요 트렌드에 반대되는 경우 여전히 역동 트렌드 거래가 발생할 수 있습니다.
  3. 매개 변수 최적화 문제. 전략은 슈퍼 트렌드의 기간과 곱셈자, 이동 평균의 기간과 같은 많은 매개 변수를 포함합니다. 다른 매개 변수는 다른 결과를 가져올 것이며 최적의 매개 변수 조합을 선택하는 것은 도전입니다.
  4. 극심한 시장 조건에서 실패할 수 있습니다. 급격한 상승과 하락, 유동성 위기 등과 같은 극심한 시장 조건에서 이 전략은 적시에 손실을 막을 수 없을 수 있습니다.

최적화 방향

  1. 추세 판단의 신뢰성을 높이고 거래 빈도를 줄이기 위해 중장기 이동 평균을 더 많이 도입하십시오.
  2. 높은 변동성 시장에서 거래를 줄이기 위해 볼링거 밴드와 같은 변동성 지표를 도입하는 것을 고려하십시오.
  3. 다양한 매개 변수를 최적화하여 최적의 매개 변수 조합을 찾고 전략의 안정성을 향상시킵니다.
  4. 극한 시장 조건 하에서 손실을 막기 위해 위험을 제어하십시오. 또한 가격 격차와 거래량 급증과 같은 비정상적인 시장 변동에 대한 판단을 추가하고 비정상시 거래를 줄이거나 중단하십시오.

요약

이 전략은 마감 위험을 제어하면서 트렌딩 시장에서 효과적으로 이익을 얻기 위해 지원/항항항, 트렌드 추적 및 모멘텀 필터링과 같은 다양한 기술 분석 방법을 통합합니다. 이 전략의 장점은 명확하고 간결한 신호, 명확한 논리 및 중장기 적용에 적합합니다. 그러나이 전략에는 빈번한 거래, 매개 변수 최적화에 어려움을 겪는 것과 극단적인 시장 조건에서 불충분한 위험 통제와 같은 문제도 있습니다. 미래에는 더 많은 기술 지표, 양자 최적화 매개 변수, 하드 스톱 손실 설정 및 비정상적인 시장 조건을 판단하여 추가적으로 개선 될 수 있습니다. 일반적으로이 전략은 비교적 성숙한 트렌드 추종 전략으로 적절한 최적화 및 개선으로 견고한 거래 시스템으로 변할 수 있습니다. 이 아이디어는 참조로 사용될 수 있지만 실제 로직 및 이상적인 시장 특성에 대한 신중한 사용이 필요합니다. 두 가지 주관적 판단과 유기적인 거래 조합이 여전히 필요합니다. 두 가지 거래 전략은 유기적으로 만들어질 때만 창조 될 수 있습니다.


/*backtest
start: 2023-03-02 00:00:00
end: 2024-03-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@rpcoelho
// Based on © Julien_Eche "Pivot Point Supertrend" with optional EMAs ploted
//@version=4

strategy("PPS w/ EMAs", overlay=true)

prd = input(defval = 1, title="Pivot Point Period", minval = 1, maxval = 50)
Factor=input(defval = 4, title = "ATR Factor", minval = 1, step = 0.1)
Pd=input(defval = 72, title = "ATR Period", minval=1)
showpivot = input(defval = false, title="Show Pivot Points")
showlabel = input(defval = true, title="Show Buy/Sell Labels")
showcl = input(defval = false, title="Show PP Center Line")
showsr = input(defval = false, title="Show Support/Resistance")

/////////////////////////////////////////////////////////////////////////
// Switch Board
////////////////////////////////////////////////////////////////////////
// Define the switch board title as a label (since grouping is not available)
//switchboard_group = "████ Switch Board (Turn On/Off Overlay Indicators) ████"
//label.new(bar_index, high, switchboard_group, color=color.red)
// Create input controls for EMA and VWAP switches
switch_ema = input(true, title="EMA")

/////////////////////////////////////////////////////////////////////////
// EMA Selection
////////////////////////////////////////////////////////////////////////

ma_function(source, length, type) =>
    float ma = na
    if type == 'RMA'
        ma := rma(source, length)
    else if type == 'SMA'
        ma := sma(source, length)
    else if type == 'EMA'
        ma := ema(source, length)
    else if type == 'WMA'
        ma := wma(source, length)
    else if type == 'HMA'
        ma := length < 2 ? hma(source, 2) : hma(source, length)
    else
        ma := vwma(source, length)
    ma

// Moving Averages Line Title
//ma_group = "██████████ MAs Line ██████████"

// Inputs for MA 1
len1bool = input(false, title="Show MA 1")
len1 = input(13, title="Length MA 1")
ma_1_type = input("EMA", title="Type MA 1", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma1 = input(title="MA1 Source", type=input.source, defval=close)
ma_1_colour = input(color.rgb(235, 159, 238), title="Color MA 1")

// Inputs for MA 2
len2bool = input(false, title="Show MA 2")
len2 = input(17, title="Length MA 2")
ma_2_type = input("EMA", title="Type MA 2", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma2 = input(title="MA2 Source", type=input.source, defval=close)
ma_2_colour = input(color.rgb(230, 241, 65), title="Color MA 2")

// Inputs for MA 3
len3bool = input(true, title="Show MA 3")
len3 = input(34, title="Length MA 3")
ma_3_type = input("EMA", title="Type MA 3", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma3 = input(title="MA3 Source", type=input.source, defval=close)
ma_3_colour = input(#c7f887, title="Color MA 3")

// Inputs for MA 4
len4bool = input(false, title="Show MA 4")
len4 = input(72, title="Length MA 4")
ma_4_type = input("EMA", title="Type MA 4", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma4 = input(title="MA4 Source", type=input.source, defval=close)
ma_4_colour = input(#2f6999, title="Color MA 4")

// Inputs for MA 5
len5bool = input(true, title="Show MA 5")
len5 = input(144, title="Length MA 5")
ma_5_type = input("EMA", title="Type MA 5", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma5 = input(title="MA5 Source", type=input.source, defval=close)
ma_5_colour = input(color.rgb(13, 156, 37), title="Color MA 5")

// Inputs for MA 6
len6bool = input(true, title="Show MA 6")
len6 = input(610, title="Length MA 6")
ma_6_type = input("EMA", title="Type MA 6", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma6 = input(title="MA6 Source", type=input.source, defval=close)
ma_6_colour = input(color.rgb(173, 161, 152), title="Color MA 6")

// Inputs for MA 7
len7bool = input(true, title="Show MA 7")
len7 = input(8, title="Length MA 7")
ma_7_type = input("EMA", title="Type MA 7", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma7 = input(title="MA7 Source", type=input.source, defval=close)
ma_7_colour = input(color.rgb(68, 39, 231), title="Color MA 7")

// Inputs for MA 8
len8bool = input(true, title="Show MA 8")
len8 = input(21, title="Length MA 8")
ma_8_type = input("EMA", title="Type MA 8", options=["RMA", "SMA", "EMA", "WMA", "HMA", "VWMA"])
src_ma8 = input(title="MA8 Source", type=input.source, defval=close)
ma_8_colour = input(color.white, title="Color MA 8")

ema1 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma1, len1, ma_1_type))
ema2 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma2, len2, ma_2_type))
ema3 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma3, len3, ma_3_type))
ema4 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma4, len4, ma_4_type))
ema5 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma5, len5, ma_5_type))
ema6 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma6, len6, ma_6_type))
ema7 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma7, len7, ma_7_type))
ema8 = security(syminfo.tickerid, timeframe.period, ma_function(src_ma8, len8, ma_8_type))

plot(len1bool and switch_ema ? ema1:na, color=ma_1_colour, linewidth=1, title='MA 1')
plot(len2bool and switch_ema? ema2:na, color=ma_2_colour, linewidth=1, title='MA 2')
plot(len3bool and switch_ema? ema3:na, color=ma_3_colour, linewidth=1, title='MA 3')
plot(len4bool and switch_ema? ema4:na, color=ma_4_colour, linewidth=1, title='MA 4')
plot(len5bool and switch_ema? ema5:na, color=ma_5_colour, linewidth=1, title='MA 5')
plot(len6bool and switch_ema? ema6:na, color=ma_6_colour, linewidth=2, title='MA 6')
plot(len7bool and switch_ema? ema7:na, color=ma_7_colour, linewidth=1, title='MA 7')
plot(len8bool and switch_ema? ema8:na, color=ma_8_colour, linewidth=1, title='MA 8')









// get Pivot High/Low
float ph = pivothigh(prd, prd)
float pl = pivotlow(prd, prd)

// drawl Pivot Points if "showpivot" is enabled
plotshape(ph and showpivot, text="H",  style=shape.labeldown, color=na, textcolor=color.red, location=location.abovebar, transp=0, offset = -prd)
plotshape(pl and showpivot, text="L",  style=shape.labeldown, color=na, textcolor=color.lime, location=location.belowbar, transp=0, offset = -prd)

// calculate the Center line using pivot points
var float center = na
float lastpp = ph ? ph : pl ? pl : na
if lastpp
    if na(center)
        center := lastpp
    else
        //weighted calculation
        center := (center * 2 + lastpp) / 3

// upper/lower bands calculation
Up = center - (Factor * atr(Pd))
Dn = center + (Factor * atr(Pd))

// get the trend
float TUp = na
float TDown = na
Trend = 0
TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up
TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn
Trend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown

// plot the trend
linecolor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : na
plot(Trailingsl, color = linecolor ,  linewidth = 2, title = "PP SuperTrend")
 
plot(showcl ? center : na, color = showcl ? center < hl2 ? color.blue : color.red : na)

// check and plot the signals
bsignal = Trend == 1 and Trend[1] == -1
ssignal = Trend == -1 and Trend[1] == 1
plotshape(bsignal and showlabel ? Trailingsl : na, title="Buy", text="Buy", location = location.absolute, style = shape.labelup, size = size.tiny, color = color.lime, textcolor = color.black, transp = 0)
plotshape(ssignal and showlabel ? Trailingsl : na, title="Sell", text="Sell", location = location.absolute, style = shape.labeldown, size = size.tiny, color = color.red, textcolor = color.white, transp = 0)

//get S/R levels using Pivot Points
float resistance = na
float support = na
support := pl ? pl : support[1]
resistance := ph ? ph : resistance[1]

// if enabled then show S/R levels
plot(showsr and support ? support : na, color = showsr and support ? color.lime : na, style = plot.style_circles, offset = -prd)
plot(showsr and resistance ? resistance : na, color = showsr and resistance ? color.red : na, style = plot.style_circles, offset = -prd)

// Trend Filter from SuperTrend Long Strategy
Periods = input(title="ATR Period", type=input.integer, defval=3)
src = input(hlc3, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=4.0)
changeATR = input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)

// Combine the SuperTrend calculations
atr2 = sma(tr, Periods)
atr = changeATR ? atr(Periods) : atr2

up = src - (Multiplier * atr)
up1 = nz(up[1], up)
up := close[1] > up1 ? max(up, up1) : up

dn = src + (Multiplier * atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn

trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

// Moving Average as Trend Filter
periodes_ma = input(title="Moving Average Period", type=input.integer, defval=20)
src_ma = input(title="Moving Average Source", type=input.source, defval=close)
ma = sma(src_ma, periodes_ma)

// Strategy Entry Conditions
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2017, title = "From Year", minval = 999)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 999)

start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)       

window()  => true

// Combined entry conditions
longCondition = (trend == 1 and trend[1] == -1 and close > ma) or (bsignal and window())
shortCondition = (trend == -1 and trend[1] == 1 and close < ma) or (ssignal and window())

if (longCondition)
    strategy.entry("BUY", strategy.long)

if (shortCondition)
    strategy.close("BUY")
    strategy.entry("SELL", strategy.short)

buy1 = barssince((trend == 1 and trend[1] == -1 and close > ma) or (bsignal and window()))
sell1 = barssince((trend == -1 and trend[1] == 1 and close < ma) or (ssignal and window()))
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(color1)


더 많은