0

这些问题的目标是找出以下两点改进的解决方案

指标目标

获取轴心线,考虑一系列牛线,在进行修正之前识别低点和高点(当一根柱线低于前一根柱线时)。

最终目标是使用getPivotMTF(多时间框架分析)中的结果,使用函数request.security,在较低时间框架中请求较高时间框架的枢轴。

改进

连接两个或多个高点

图片供参考

简化实施

将逻辑放在更松散的脚本样式中:)。

参考

var INPUT_GROUP_DEBUG = "Debug"
var MAX_OBJ_TO_SHOW = 500

//@version=5
indicator("CDR - Pivot Test", overlay = true, max_bars_back=5000, max_lines_count = 500, max_labels_count = MAX_OBJ_TO_SHOW)

linePivotColorInput = input.color(color.fuchsia, "Pivot Color")
printPivotPoint = input.bool(true, "Print Pivot Points", group = INPUT_GROUP_DEBUG)
printPivotData  = input.bool(false, "Print Bars Data", group = INPUT_GROUP_DEBUG)


// ———————————————————— Pivot {
getBarData() =>

    var bool isHigh = close > open

    var float hHigh      = na
    var int   hHighIndex = na
    var int   hHighTime  = na
    
    var float hLow      = na
    var int   hLowIndex = na
    var int   hLowTime  = na

    pHigh  = high[1] // prefix p = previous
    pLow   = low[1]

    var float price = isHigh ? high : low
    var int index   = bar_index
    var int tm      = time

    if bar_index != 0
    
        if isHigh
        
            if low < pLow
                hLow      := low
                hLowIndex := bar_index
                hLowTime  := time

                isHigh := false

                price  := hHigh
                index  := hHighIndex
                tm     := hHighTime

            else if high > hHigh
                i = (bar_index - index) - 1
                while i > 0
                    if  low[i] < price
                        price  := low[i]
                        index  := bar_index - i
                        tm     := time[i]
                        break
                    i := i - 1            
            
                hHigh      := high
                hHighIndex := bar_index
                hHighTime  := time

        else

            if high > pHigh
                hHigh      := high
                hHighIndex := bar_index
                hHighTime  := time
                
                isHigh := true
                
                price  := hLow
                index  := hLowIndex
                tm     := hLowTime
                
                    
            else if low < hLow
                i = (bar_index - index) - 1
                while i > 0
                    if  high[i] > price
                        price  := high[i]
                        index  := bar_index - i
                        tm     := time[i]
                        break
                    i := i - 1
                    
                hLow      := low
                hLowIndex := bar_index
                hLowTime  := time

    [price, index, tm]
    

getPivot() =>

    [bPrice, bIndex, bTime] = getBarData()
    
    hasNewLine = ta.change(bIndex)

    var float price = na
    var int index   = na
    var int tm      = na
    
    if hasNewLine
        price  := bPrice
        index  := bIndex
        tm     := bTime
        
    [price, index, tm]

[pPrice, pIndex, pTime] = getPivot()


printPivot() =>
    
    previousPrice     = pPrice[1]
    previousTime      = pTime[1]

    if printPivotPoint and ta.change(pPrice)
        line.new(x1    = previousTime,
                y1    = previousPrice,
                x2    = pTime,
                y2    = pPrice,
                xloc  = xloc.bar_time,
                color = linePivotColorInput,
                width = 1, 
                style = line.style_solid)
        
printPivot()

// }


debugPivot() =>

    [htfPrice, htfIndex, htfTime] = request.security(syminfo.tickerid, "60", [pPrice, pIndex, pTime], gaps=barmerge.gaps_on)
    
    if barstate.islast and printPivotData

        i = 0
        iterations = 60
        
        s =      "== Data Current Time Frame ==\n"
        s := s + "\n"
        
        // current time frame data
        while i < iterations - 1
    
            str = "[" + str.tostring(pPrice[i]) + ", "
                      + str.tostring(pIndex[i]) + ", "
                      + str.tostring(pTime[i])  + "]\n"
            s := s + str
            i := i + 1
        
        var label lb = na
        if not(na(lb))
            label.delete(lb)
        style = label.style_label_down
        lb := label.new(bar_index, high, s, style = style, size = size.small, textalign = text.align_left)
    
debugPivot()

4

0 回答 0