line.new 仅适用于extend.right

问题描述 投票:0回答:1
仅当我添加

line.new(....)

 时,
extend = extend.right
才会绘制线条。我需要它作为趋势而不是水平线。


maxBack = input.int(defval = 10, title = "maxBack", minval = 1)


float highMain = ta.highest(maxBack)
float lowMain = ta.lowest(maxBack)

int iHighMain = 0
int iLowMain = 0

bool we_work = barstate.islast
if(we_work)
    for i=2 to maxBack+2
        if(iHighMain==0 and high[i] == highMain)
            iHighMain := i
        if(iLowMain==0 and low[i] == lowMain)
            iLowMain := i

    for i=iHighMain+1 to 1000
        if(close[i]<high[iHighMain] and  close[i]>low[iHighMain])
            line.new(x1 = i, y1 = close[i], x2 = iHighMain, y2 = close[i], width = 3, color=color.yellow)
            break
    for i=iLowMain+1 to 1000
        if(close[i]<high[iLowMain] and  close[i]>low[iLowMain])
            line.new(x1 = i, y1 = close[i], x2 = iLowMain, y2 = close[i], width = 3, color=color.yellow)
            break

如何修复绘制趋势线而不是水平线?

pine-script pine-script-v5
1个回答
0
投票

尝试 x1 = bar_index

for i=iHighMain+1 to 1000
    if(close[i]<high[iHighMain] and  close[i]>low[iHighMain])
        line.new(x1 = bar_index - iHighMain, y1 = close[i], x2 = bar_index - i, y2 = close[i], width = 3, color=color.yellow)
        break
for i=iLowMain+1 to 1000
    if(close[i]<high[iLowMain] and  close[i]>low[iLowMain])
        line.new(x1 = bar_index - iHighMain, y1 = close[i], x2 = bar_index - i, y2 = close[i], width = 3, color=color.yellow)
        break

test

© www.soinside.com 2019 - 2024. All rights reserved.