양방향 슈퍼트렌드 전략


생성 날짜: 2023-10-08 15:02:45 마지막으로 수정됨: 2023-10-08 15:02:45
복사: 0 클릭수: 676
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 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)