松脚本在transactionview上绘制fib水平的方法

时间:2020-07-01 15:41:42

标签: pine-script

我创建此代码来绘制fib的水平,以查看价格是否超过了这些fib的水平,但是我的代码太长了,有什么方法可以优化下面的水平,

代码按预期工作,但我想以有效的方式减少代码

由于我使用多个if语句,并且每个条形索引使用不同的级别,因此代码变得冗长

请提出建议

level11 = low_range - 1.604 * diff 
level12 = low_range - 1.590 * diff
level13 = low_range - 1.576 * diff
level14 = low_range - 1.562 * diff
level15 = low_range - 1.548 * diff
level16 = low_range - 1.534 * diff
level17 = low_range - 1.520 * diff
level18 = low_range - 1.506 * diff
level19 = low_range - 1.492 * diff
level20 = low_range - 1.478 * diff
level21 = low_range - 1.464 * diff
level22 = low_range - 1.450 * diff
level23 = low_range - 1.436 * diff
level24 = low_range - 1.422 * diff

var label lb11 = na
var line ln11 = na
if crossover(close,level11) and open < level11
    if bar_index <= firstBar + 1
        if (barstate.islast)
            lb11 := label.new(bar_index, high)
            ln11 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln11[1])  
            label.delete(lb11[1])  
            trigger := 'fomred'
                    
line.delete(id=ln11[1])
label.delete(lb11[1])  

var label lb12 = na
var line ln12 = na
if crossover(close,level12) and open < level12
    if bar_index <= firstBar + 2
        if (barstate.islast)
            lb12 := label.new(bar_index, high)
            ln12 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln12[1])  
            label.delete(lb12[1])  
            trigger := 'fomred'
                    
line.delete(id=ln12[1])
label.delete(lb12[1])  

var label lb13 = na
var line ln13 = na

if crossover(close,level13) and open < level13
    if bar_index <= firstBar + 3
        if (barstate.islast)
            lb13 := label.new(bar_index, high)
            ln13 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln13[1])  
            label.delete(lb13[1])  
            trigger := 'fomred'
                    
line.delete(id=ln13[1])
label.delete(lb13[1]) 


var label lb14 = na
var line ln14 = na

if crossover(close,level14) and open < level14
    if bar_index <= firstBar + 4
        if (barstate.islast)
            lb14 := label.new(bar_index, high)
            ln14 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln14[1])  
            label.delete(lb14[1])  
            trigger := 'fomred'
                    
line.delete(id=ln14[1])
label.delete(lb14[1])   

var label lb15 = na
var line ln15 = na
if crossover(close,level15) and open < level15
    if bar_index <= firstBar + 5
        if (barstate.islast)
            lb15 := label.new(bar_index, high)
            ln15 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln15[1])  
            label.delete(lb15[1])  
            trigger := 'fomred'
                    
line.delete(id=ln15[1])
label.delete(lb15[1])  

var label lb16 = na
var line ln16 = na
if crossover(close,level16) and open < level16
    if bar_index <= firstBar + 6
        if (barstate.islast)
            lb16 := label.new(bar_index, high)
            ln16 := line.new(time + 1000 * bar_size, high, time, high, xloc.bar_time, color=color.red)
            line.delete(id=ln16[1])  
            label.delete(lb16[1])  
            trigger := 'fomred'
                    
line.delete(id=ln16[1])
label.delete(lb16[1])   


var label lb17 = na
var line ln17 = na 

0 个答案:

没有答案