동적 기울기 트렌드 라인 거래 전략

저자:차오장, 날짜: 2024-02-06 11:51:14
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 동적 기울기를 사용하여 가격 트렌드 방향을 결정하고 브레이크아웃 판단과 결합하여 거래 신호를 생성하는 것입니다. 구체적으로, 동적 기울기를 계산하기 위해 서로 다른 기간 동안의 가격 변화에 따라 실시간으로 가격 최고와 최저를 추적하고 트렌드 라인에 대한 가격의 브레이크아웃에 따라 길고 짧은 신호를 결정합니다.

전략 원칙

이 전략의 주요 단계는 다음과 같습니다.

  1. 가장 높고 가장 낮은 가격을 판단합니다. 특정 사이클 (예: 20 바) 에서 가장 높고 가장 낮은 가격을 추적하여 새로운 최고 또는 최저가 도달했는지 여부를 결정합니다.

  2. 동적 기울기를 계산합니다. 새로운 최고 또는 낮은 지점에 도달 할 때 바 번호를 기록하고 특정 주기가 끝난 후 새로운 높은 / 낮은 지점에서 높은 / 낮은 지점까지 동적 기울기를 계산합니다. (예: 9 바).

  3. 트렌드 라인 그래프: 동적 기울기를 기반으로 상승 및 하락 트렌드 라인을 그래프합니다.

  4. 트렌드 라인을 확장하고 업데이트합니다. 가격이 트렌드 라인을 깨면 트렌드 라인을 확장하고 업데이트합니다.

  5. 트레이딩 신호: 트렌드 라인에 대한 가격 브레이크를 기반으로 긴 신호와 짧은 신호를 결정합니다.

전략 의 장점

이 전략의 장점은 다음과 같습니다.

  1. 시장 변화에 따라 유연성을 위해 동적으로 트렌드 방향을 결정합니다.

  2. 합리적으로 멈추는 것을 통제하고 마취를 최소화하십시오.

  3. 쉽게 실행할 수 있는 명확한 트레이딩 신호입니다.

  4. 강력한 적응력을 위해 사용자 정의 가능한 매개 변수

  5. 이해하기 쉽고 더 발전하기 쉬운 깨끗한 코드 구조.

위험 과 해결책

이 전략에는 몇 가지 위험도 있습니다.

  1. 트렌드가 범위를 제한할 때 빈번한 롱과 쇼트. 필터 조건을 추가합니다.

  2. 잠재적으로 더 많은 잘못된 신호가 있습니다.

  3. 시장이 격렬하게 움직일 때 손해를 막는 위험을 감수합니다. 손해를 막는 범위를 확장하십시오.

  4. 제한된 최적화 공간과 수익 잠재력, 단기 거래에 적합합니다.

최적화 방향

전략의 최적화를 위한 분야는 다음과 같습니다.

  1. 필터 신호로 더 많은 기술적 지표를 추가합니다.

  2. 가장 좋은 매개 변수를 위해 매개 변수 조합을 최적화합니다.

  3. 위험을 줄이기 위해 스톱 로스 전략을 개선하려고 노력하십시오.

  4. 입력 가격 범위를 자동으로 조정할 수 있는 기능을 추가합니다.

  5. 더 많은 기회를 발견하기 위해 다른 전략과 결합해보세요.

요약

전체적으로 이것은 동적 기울기 (dynamic slope) 를 사용하여 트렌드와 거래 브레이크아웃을 결정하는 데 기반한 효율적인 단기 전략이다. 정확한 판단, 통제 가능한 리스크를 가지고 있으며 시장에서 단기 기회를 포착하기에 적합하다. 매개 변수 및 필터에 대한 추가 최적화는 승률과 수익성을 향상시킬 수 있다.


/*backtest
start: 2024-01-06 00:00:00
end: 2024-01-19 00:00:00
period: 2h
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/
// © pune3tghai

//Originally posted by matsu_bitmex

//tried adding alerts on plots and cleared the chart for a cleaner view.
//Publishing the script in hope of getting it improved by someone else.

//Added strategy code for easier calculations

//Needs work on TP and SL part.

//P.S - THE ORIGINAL CODE IS MUCH BETTER BUT I have tried to be more usable and understandable.

//@version=4
strategy("TrendLines with Alerts", overlay=true)     //study("TrendLines with Alerts", overlay=true)
//update

length1 = input(20)
check = input(9)
//length2 = input(200)


u=0.0
u := u[1]

l=0.0
l := l[1]

y=0.0
y := y[1]

yl=0.0
yl := yl[1]

angle = 0.0
angle := angle[1]

anglel = 0.0
anglel := anglel[1]

if (highest(length1) == high[check] and highest(length1) == highest(length1)[check] and barssince(barstate.isfirst) > check)
    u := high[check]

    
if (lowest(length1) == low[check] and lowest(length1) == lowest(length1)[check] and barssince(barstate.isfirst) > check)
    l := low[check]
    

    
p = round(barssince(u == high[check]))

pl = round(barssince(l == low[check]))

if p == 0 and barssince(barstate.isfirst) > check
    y := high[abs(p[1]+1+check)]
    
if pl == 0 and barssince(barstate.isfirst) > check
    yl := low[abs(pl[1]+1+check)]    
    

if p == 0
    angle := (u-y)/p[1]

if pl == 0
    anglel := (l-yl)/pl[1]

uppertrend = u+ (p * angle)

lowertrend = l+ (pl * anglel)

extendup = if barssince(barstate.isfirst) > check
    uppertrend[check] + angle[check] * check*2

extenddown = if barssince(barstate.isfirst) > check
    lowertrend[check] + anglel[check] * check*2




//plot(l[offset]-u,color=red)
//plot(u[offset]-l,color = green )
plot(lowertrend, color = color.green, transp=30,offset = -check)
plot(extenddown, color = color.green, transp=100)
plot(uppertrend, color = color.red, transp=30, offset = -check)
plot(extendup, color = color.red, transp=100)
//plot(l[offset], color = red)

l1 = lowertrend
l2 = extenddown
u1 = uppertrend
u2 = extendup



l2sell = crossunder(high, l2)
u2buy = crossover(low, u2)
buy1 = (low<=lowertrend) and open>lowertrend and high>lowertrend and close>lowertrend
buy2 = (low<=extenddown) and open>extenddown and high>extenddown and close>extenddown
buy = buy1 or buy2 or u2buy
plotshape(series=buy, title="Buy", style=shape.triangleup, size=size.tiny, color=color.lime, location=location.belowbar)
sell1 = (high>=uppertrend) and open<uppertrend and low<uppertrend and close<uppertrend
sell2 = (high>=extendup) and open<extendup and low<extendup and close<extendup
sell = sell1 or sell2 or l2sell
plotshape(series=sell, title="Sell", style=shape.triangledown, size=size.tiny, color=color.red, location=location.abovebar)

longCond = buy
shortCond = sell

tp = input(0.2, title="Take Profit")

tpbuyval = valuewhen(buy, close, 1) + (tp/100)*(valuewhen(buy, close, 1))
tpsellval = valuewhen(sell, close, 1) - (tp/100)*(valuewhen(sell, close, 1))


sl = input(0.2, title="Stop Loss")
slbuyval = valuewhen(buy, close, 0) - (sl/100)*(valuewhen(buy, close, 0))
slsellval = valuewhen(sell, close, 0) + (sl/100)*(valuewhen(sell, close, 0))
// === STRATEGY ===
tradeType = input("BOTH", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])

// stop loss
slPoints = input(defval=0, title="Initial Stop Loss Points (zero to disable)", minval=0)
tpPoints = input(defval=0, title="Initial Target Profit Points (zero for disable)", minval=0)

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//

testStartYear = input(2019, "Backtest Start Year", minval=1980)
testStartMonth = input(1, "Backtest Start Month", minval=1, maxval=12)
testStartDay = input(1, "Backtest Start Day", minval=1, maxval=31)
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear = input(9999, "Backtest Stop Year", minval=1980)
testStopMonth = input(12, "Backtest Stop Month", minval=1, maxval=12)
testStopDay = input(31, "Backtest Stop Day", minval=1, maxval=31)
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

//
//set up exit parameters
TP = tpPoints > 0 ? tpPoints : na
SL = slPoints > 0 ? slPoints : na

// Make sure we are within the bar range, Set up entries and exit conditions
if testPeriod() and tradeType != "NONE"
    strategy.entry("long", strategy.long, when=longCond == true and tradeType != "SHORT")
    strategy.entry("short", strategy.short, when=shortCond == true and tradeType != "LONG")
    strategy.close("long", when=shortCond == true and tradeType == "LONG")
    strategy.close("short", when=longCond == true and tradeType == "SHORT")
    strategy.exit("XL", from_entry="long", profit=tpbuyval, loss=slbuyval)
    strategy.exit("XS", from_entry="short", profit=tpsellval, loss=slsellval)

// === /STRATEGY ===
//EOF


////ALERT SYNTEX
//alertcondition(longCond, title="Long", message="Killer Market")
//alertcondition(shortCond, title="Short", message="Poopy Market")

더 많은