슈퍼트렌드 쌍방향 전략

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

전반적인 설명

이 전략은 현재 트렌드 방향을 결정하고 구매 및 판매 신호를 생성하기 위해 ATR 지표에 기초하여 계산된 상위 및 하위 밴드를 사용합니다. 가격이 상위 밴드를 넘어서면 길고 가격이 하위 밴드를 넘어서면 짧습니다.

전략 논리

  1. 평균 가격 변동 범위를 나타내는 ATR 지표를 계산합니다.
  2. 상단 및 하단 대역은 ATR값을 인수로 곱한 값에 기초하여 계산합니다.
  3. 유행 방향은 가격과 대역의 관계를 기반으로 결정합니다.
    • 가격이 상단 범위를 넘으면 상승 추세입니다.
    • 가격이 하위 범위를 넘으면 하락 추세입니다.
  4. 트렌드가 방향이 바뀌면 구매 및 판매 신호를 생성합니다.
    • 상위 지대 근처에서 구매 신호가 생성됩니다. 추세가 하향에서 상승으로 변할 때.
    • 판매 신호는 추세가 상승 추세에서 하락 추세로 변할 때 하위 계단 근처에서 생성됩니다.
  5. 상부/하부 대역, 트렌드 방향 및 거래 신호를 시각화하십시오.

이점 분석

  • 트렌드를 결정하기 위해 ATR을 사용하면 매개 변수를 조정함으로써 시장 변동성에 대 한 대역을 조정 할 수 있습니다.
  • 트렌드 반전을 적시에 포착합니다.
  • 트렌드 방향에 따라 신호를 필터링하여 가짜 브레이크를 피합니다.
  • 음역과 신호의 명확한 시각화

위험 분석

  • 부적절한 ATR 기간은 가격에서 대역을 분리할 수 있습니다.
  • 너무 큰/작은 곱셈은 더 많은 잘못된 신호와 뒤떨어진 신호를 유발합니다.
  • 부정확한 반전 시기는 반전 거래로 인한 손실로 이어집니다.
  • 다른 필터가 필요해

최적화 방향

  • 시장 변동성에 맞게 ATR 기간의 동적 최적화
  • 다른 제품과 시간 프레임에 대한 매개 변수 조정
  • 트렌드 검증을 위해 볼륨과 같은 다른 지표를 결합하십시오.
  • 매개 변수 최적화를 위해 기계 학습을 활용합니다.

요약

이 전략은 ATR을 기반으로 한 이방향 트렌드를 결정하는 아이디어를 구현합니다. 파업 신호는 가짜 신호를 피하기 위해 트렌드 방향에 의해 생성되고 필터링됩니다. 매개 변수는 다른 시장 환경에 맞춰 조정 할 수 있습니다. 추가 최적화가 필요한 몇 가지 위험이 있습니다. 전반적으로 이것은 연구하고 개선 할 가치가있는 간단하고 실용적인 전략입니다.


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

TradeId = "RVG"

InitCapital = 1000
InitPosition = 1000
InitCommission = 0.075
InitPyramidMax = 1
CalcOnorderFills = true
CalcOnTick = true

//@version=4
// strategy("Supertrend RG", overlay = true,process_orders_on_close=true,commission_type=strategy.commission.percent,commission_value=InitCommission,
//  currency=currency.USD,initial_capital=InitCapital,default_qty_type=strategy.cash, default_qty_value=InitPosition, calc_on_order_fills=CalcOnorderFills, calc_on_every_tick=CalcOnTick,pyramiding=InitPyramidMax)

//
////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE

// From Date Inputs
fromDay = input(defval=1, title="From Day", minval=1, maxval=31)
fromMonth = input(defval=1, title="From Month", minval=1, maxval=12)
fromYear = input(defval=2018, title="From Year", minval=1970)

// To Date Inputs
toDay = input(defval=1, title="To Day", minval=1, maxval=31)
toMonth = input(defval=1, title="To Month", minval=1, maxval=12)
toYear = input(defval=2100, title="To Year", minval=1970)

// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true



Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
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
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")


strategy.entry(TradeId + " Long", true, when=buySignal[1] and time_cond)
strategy.entry(TradeId + " Short", false, when=sellSignal[1] and time_cond)   




더 많은