트렌드 블록 전략


생성 날짜: 2023-11-06 09:20:34 마지막으로 수정됨: 2023-11-06 09:20:34
복사: 0 클릭수: 376
1
집중하다
1166
수행원

트렌드 블록 전략

개요

트렌드 덩어리 전략은 가격 변화의 비율이나 점의 점수를 기반으로 대각선 배열을 하는 거래 전략이다. 그것은 차트에 명확하게 지역 추세와 전환점을 표시할 수 있다. 이것은 가격 방향을 추적하는 매우 유용한 도구이다.

원칙

이 전략의 계산은 가격의 변화의 비율 또는 파동점의 편차 (偏差参数) 를 기반으로 하며, 대각선 형태로 차트에 나타난다.

각 줄은 기준 중선, 상한선, 하한선으로 구성됩니다.

  • 기준 중간선은 앞 줄 또는 다음 줄의 상한선 또는 하한선과 같다. 계산을 시작할 때, 기준 중간선은 첫 줄의 초기 값과 같다.

  • 수 파라미터는 가격 변화 방향의 상한선 또는 하한선의 편차량을 결정하며, 회전 파라미터는 가격 변화 방향의 변화를 결정하는 편차량을 결정한다.

새로운 행을 만드는 규칙:

  • 만약 닫기 가격이 상한선 ≥이고 닫기 가격이 상한선>라면, 상한선은 점진적으로 위로 이동할 것이고, 하한선은 또한 위로 이동할 것이지만 그 폭은 작다.

  • 만약 최저 가격이 ≤ 하위선이고 폐쇄 가격이 < 오픈 가격, 하위선은 점진적으로 아래로 이동할 것이고 상위선은 또한 아래로 이동할 것이다. 그러나 그 폭은 작다.

편차량을 조정하여, 차트에서 지역 추세와 전환점을 명확하게 볼 수 있습니다. 이것은 가격 움직임을 추적하는 데 매우 유용한 도구입니다.

우위 분석

  • 가격 변화의 경향을 시각적으로 표시하고, 지지 저항을 명확하게 식별한다.

  • 대각선은 돌파의 강도와 회귀의 범위를 명확하게 나타냅니다.

  • 각선의 기울기를 조정할 필요가 있는 강도의 경향을 식별할 수 있다.

  • 그리고 그 다음에는, 그 다음에는, 그 다음에는, 그 다음에는.

  • 가격의 리듬적 변화를 쉽게 파악하여 입장을 조정할 수 있다.

위험 분석

  • 은 은 은 은 은

  • 동향에서 벗어난 경우와 실제 가격과 다른 방향이 있을 수 있으므로 주의해야 합니다.

  • 그러나, 이 전략은 단독으로 사용할 수 없으며, 다른 지표들과 함께 큰 추세를 판단해야 합니다.

  • 주의해야 할 사항은 변수를 적절하게 조정하지 않으면 거래가 너무 자주 발생할 수 있다는 것입니다.

  • 회전 시 경보 회전이 필요할 가능성이 있으며, 기계적 맹목적으로 추적할 수 없다.

포지션 규모를 적절히 축소할 수 있으며, 다른 지표들을 보조적인 판단으로 참고하여 큰 추세 아래에서 동작할 수 있다.

최적화 방향

  • 포지션 관리 모듈을 추가하여 트렌드의 다른 단계에서 포지션을 동적으로 조정할 수 있습니다.

  • 변동률 지표와 결합하여 변동이 커지면 포지션을 줄일 수 있다.

  • 철수 비율에 따라 중지 손실을 설정하여 단독 손실을 제어 할 수 있습니다.

  • 필터를 추가하여 가격의 오차가 발생하면 거래를 중지할 수 있습니다.

  • 다단계 대각 기울기를 구분하여 다양한 강도의 경향 변화를 식별할 수 있다.

포지션을 동적으로 조정하고, 스톱로스 및 필터 조건을 설정하여 가격 추세를 더욱 안정적으로 추적할 수 있다.

요약하다

트렌드 덩어리 전략은 대각선 직관적으로 가격 트렌드 변화를 활용하여 지지 저항점과 돌파구를 명확하게 식별할 수 있다. 그러나 대각선 독립 판단에 의존할 수 없으며, 다른 지표와 함께 종합 분석을 수행하는 동시에 위험을 제어할 필요가 있다. 이것은 매우 가치있는 보조 도구이며, 거래자가 시장의 리듬을 더 잘 파악할 수 있도록 도와준다. 최적화를 통해 전략을 더 안정적이고 효율적으로 만들 수 있으며, 큰 응용 잠재력을 가지고 있다.

전략 소스 코드
/*backtest
start: 2023-10-06 00:00:00
end: 2023-11-05 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
// **********************************************************************************
// This code is invented and written by @StCogitans.
// The idea presented in this code and the rights to this code belong to @StCogitans.
// © https://www.tradingview.com/u/StCogitans
//
// Description.
// Sizeblock - a price change strategy in the form of diagonal rows.
// **********************************************************************************

// STRATEGY
string NAME        = 'Sizeblock'
string ACRONYM     = 'SB'
bool OVERLAY       = true
int PYRAMIDING     = 0
string QTY_TYPE    = strategy.percent_of_equity
float QTY_VALUE    = 100
float CAPITAL      = 100
string COM_TYPE    = strategy.commission.percent
float COM_VALUE    = 0.1
bool ON_CLOSE      = false
bool BAR_MAGNIFIER = false
bool OHLC          = true
strategy(NAME, ACRONYM, OVERLAY, pyramiding=PYRAMIDING, default_qty_type=QTY_TYPE, default_qty_value=QTY_VALUE, initial_capital=CAPITAL, commission_type=COM_TYPE, commission_value=COM_VALUE, process_orders_on_close=ON_CLOSE, use_bar_magnifier=BAR_MAGNIFIER, fill_orders_on_standard_ohlc=OHLC)

// ARGUMENTS
// Datetime
DTstart  = input(timestamp("01 Jan 2000 00:00 +0000"), 'Start time', group='Datetime')
DTfinish = input(timestamp("01 Jan 2080 23:59 +0000"), 'Finish time', group='Datetime')
DTperiod = true

// Main
dev_source = input.string('Close', title='Source', options=["Close", "HighLow"], tooltip='Price data for settlement.', group='Main')
dev_type   = input.string('Percentage', title='Deviation', options=['Percentage', 'Ticks'], tooltip='The type of deviation to calculate.', group='Main')
dev_value  = input.float(1, title='Quantity', minval=0.001, step=0.01, tooltip='Quantity to be calculated.', group='Main')
dev_back   = input.float(2, title='U-turn', minval=0.001, step=0.01, tooltip='Quantity for reversal.', group='Main')
mode       = input.string('Limit', title='Positions', options=['Limit', 'Market'], tooltip='Limit or market orders.', group='Main')
direct     = input.string('All', title='Direction', options=['All', 'Buy', 'Sell'], tooltip='The type of positions to be opened.', group='Main')
swapping   = input.bool(false, title='Swapping', tooltip='Swap points to open a new position.', group='Main')

// CALCULATION SYSTEM
Assembling(s, t, v, vb) =>

    float a = open
    float b = close
    float c = s == "HighLow" ? math.round_to_mintick(high) : math.round_to_mintick(b)
    float d = s == "HighLow" ? math.round_to_mintick(low) : math.round_to_mintick(b)

    float x = math.round_to_mintick(a)
    x := nz(x[1], x)

    float _v = t == "Ticks" ? syminfo.mintick * v : v
    float _vb = t == "Ticks" ? syminfo.mintick * vb : vb

    float h = t == "Ticks" ? math.round_to_mintick(x + _v) : math.round_to_mintick(x * (1 + _v / 100))
    float l = t == "Ticks" ? math.round_to_mintick(x - _v) : math.round_to_mintick(x * (1 - _v / 100))
    h := nz(h[1], h)
    l := nz(l[1], l)

    if t == "Ticks"
    
        if c >= h and b > a
            while c >= h
            
                x := h
                h := math.round_to_mintick(h + _v)
                l := math.round_to_mintick(x - _vb)
        
        if d <= l and b < a
            while d <= l
            
                x := l
                l := math.round_to_mintick(l - _v)
                h := math.round_to_mintick(x + _vb)

    else if t == "Percentage"
    
        if c >= h and b > a
            while c >= h
        
                x := h
                h := math.round_to_mintick(h * (1 + _v / 100))
                l := math.round_to_mintick(x * (1 - _vb / 100))

        if d <= l and b < a
            while d <= l
        
                x := l
                l := math.round_to_mintick(l * (1 - _v / 100))
                h := math.round_to_mintick(x * (1 + _vb / 100))

    [x, h, l]

[lx, lh, ll] = Assembling(dev_source, dev_type, dev_value, dev_back)

// PLOT
// Lines
plot_up   = plot(lh, color=color.new(color.green, 50), style=plot.style_line, linewidth=1)
plot_main = plot(lx, color=color.new(color.silver, 50), style=plot.style_line, linewidth=1)
plot_down = plot(ll, color=color.new(color.red, 50), style=plot.style_line, linewidth=1)

// Areas
fill(plot_up, plot_main, lh, lx, color.new(color.teal, 80), color.new(color.teal, 80))
fill(plot_main, plot_down, lx, ll, color.new(color.maroon, 80), color.new(color.maroon, 80))

// TRADING
// Alert variables
int Action = -1
int PosType = -1
int OrderType = -1
float Price = -1.0

// Direction variables
bool ifBuy = direct == "All" or direct == "Buy" ? true : false
bool ifSell = direct == "All" or direct == "Sell" ? true : false

// Market entries
if (strategy.closedtrades + strategy.opentrades == 0 or mode == "Market") and DTperiod
    if ((swapping and lx < nz(lx[1], lx)) or (not swapping and lx > nz(lx[1], lx))) and ifBuy
        Action := 1
        PosType := 1
        OrderType := 1
        Price := math.round_to_mintick(close)
        strategy.entry('Long', strategy.long)
    if ((swapping and lx > nz(lx[1], lx)) or (not swapping and lx < nz(lx[1], lx))) and ifSell
        Action := 2
        PosType := 2
        OrderType := 1
        Price := math.round_to_mintick(close)
        strategy.entry('Short', strategy.short)

// Closing positions by market
if DTperiod and mode == "Market"
    if direct == "Buy" and strategy.position_size > 0
        if swapping and lx > nz(lx[1], lx)
            Action := 2
            PosType := 3
            OrderType := 1
            Price := math.round_to_mintick(close)
            strategy.close('Long', comment='Close')
        if not swapping and lx < nz(lx[1], lx)
            Action := 2
            PosType := 3
            OrderType := 1
            Price := math.round_to_mintick(close)
            strategy.close('Long', comment='Close')
    if direct == "Sell" and strategy.position_size < 0
        if swapping and lx < nz(lx[1], lx)
            Action := 1
            PosType := 3
            OrderType := 1
            Price := math.round_to_mintick(close)
            strategy.close('Short', comment='Close')
        if not swapping and lx > nz(lx[1], lx)
            Action := 1
            PosType := 3
            OrderType := 1
            Price := math.round_to_mintick(close)
            strategy.close('Short', comment='Close')

// Limit entries and exits
if swapping and DTperiod and mode == "Limit"
    if strategy.position_size < 0
        Action := 1
        PosType := 1
        OrderType := 2
        Price := ll
        if ifBuy
            strategy.entry('Long', strategy.long, limit=ll)
        else
            PosType := 3
            strategy.exit('Exit', limit=ll)
    if strategy.position_size > 0
        Action := 2
        PosType := 2
        OrderType := 2
        Price := lh
        if ifSell
            strategy.entry('Short', strategy.short, limit=lh)
        else
            PosType := 3
            strategy.exit('Exit', limit=lh)
    if strategy.closedtrades + strategy.opentrades > 0 and strategy.position_size == 0
        if ifBuy
            Action := 1
            PosType := 1
            OrderType := 2
            Price := ll
            strategy.entry('Long', strategy.long, limit=ll)
        if ifSell
            Action := 2
            PosType := 2
            OrderType := 2
            Price := lh
            strategy.entry('Short', strategy.short, limit=lh)
if not swapping and DTperiod and mode == "Limit"
    if strategy.position_size < 0
        Action := 1
        PosType := 1
        OrderType := 2
        Price := lh
        if ifBuy
            strategy.entry('Long', strategy.long, stop=lh)
        else
            PosType := 3
            strategy.exit('Exit', stop=lh)
    if strategy.position_size > 0
        Action := 2
        PosType := 2
        OrderType := 2
        Price := ll
        if ifSell
            strategy.entry('Short', strategy.short, stop=ll)
        else
            PosType := 3
            strategy.exit('Exit', stop=ll)
    if strategy.closedtrades + strategy.opentrades > 0 and strategy.position_size == 0
        if ifBuy
            Action := 1
            PosType := 1
            OrderType := 2
            Price := lh
            strategy.entry('Long', strategy.long, stop=lh)
        if ifSell
            Action := 2
            PosType := 2
            OrderType := 2
            Price := ll
            strategy.entry('Short', strategy.short, stop=ll)

// Everything is closed and canceled
if not DTperiod
    strategy.cancel_all()
    strategy.close_all(comment='Close')

// Alerts
// Convert to string variables
string Action_Txt = Action == 1 ? "Buy" : Action == 2 ? "Sell" : na
string PosType_Txt = PosType == 1 ? "Long" : PosType == 2 ? "Short" : PosType == 3 ? "Flat" : na
string OrderType_Txt = OrderType == 1 ? "Market" : OrderType == 2 ? "Limit" : na
string Price_Txt = Price > 0 ? str.tostring(Price) : na

// Output
if not (Action == nz(Action[1], Action) and Price == nz(Price[1], Price) and OrderType == nz(OrderType[1], OrderType)) and DTperiod
    alert('{"pair": "' + syminfo.ticker + '", "direction": "' + Action_Txt + '", "entertype": "' + OrderType_Txt + '", "position": "' + PosType_Txt + '", "price": "' + Price_Txt + '"}')

// *********************
// Good job, Soldier! ;>
// *********************