首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >box.delete[1]工作不正常!方框-空白脚本-文字记录

box.delete[1]工作不正常!方框-空白脚本-文字记录
EN

Stack Overflow用户
提问于 2022-08-22 10:25:56
回答 1查看 80关注 0票数 0

我正在努力改进这个脚本,这标志着差距。我设置了一个函数box.delete1,这样矩形就会随着价格在较低的价差上创新高而褪色,但它会继续绘制新的矩形。当价格再创新高时,每5分钟就会画出新的矩形。你能帮我吗?

价格一碰,一箱一箱

当价格不动盒子时不受影响

如果我改变了UT,它工作的很好,它只是在5分钟,因为我在5分钟,当它触及低点

不受影响在2分钟或15分钟等,只有5分钟

代码语言:javascript
复制
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Asch-

//@version=5
indicator(title='GAP DETECTOR fini DAX DJI', overlay=true, max_bars_back=500, max_lines_count = 500)


var i = input.int(450, "Length ", minval = 1)


///////////// Make a loop to refresh the indicator ? Word when i refresh the indicator or change the UT

length = bar_index > 500 ? i : na

//// not understand useless ?
passed_length = bar_index == 0 ? 500 : length
///// 

width = input.int(2, options=[1, 2, 3, 4, 5])

gap_start = high[length]
gap_end = low[length - 1]


gap_bull = false
gap_bear = false

inf_gap = 0.0
sup_gap = 0.0

if barstate.islast

    for j = 1 to length by 1
        gap_bull := false
        gap_bear = false
        
        inf_gap := 0.0
        sup_gap := 0.0

        if high[j] < low[j - 1]  //bull gap
            gap_start := high[j]
            gap_end := low[j - 1]
            gap_bull := true
            inf_gap := gap_start
            sup_gap := gap_end
            for i = j - 1 to 0 by 1
                sup_gap := math.min(sup_gap, low[i])
                sup_gap
            if (sup_gap - inf_gap) / (syminfo.mintick * 10) < 5  // only gap > 5 pips are considered
                gap_bull := false
                gap_bull

        if low[j] > high[j - 1]  //bear gap
            gap_start := low[j]
            gap_end := high[j - 1]
            gap_bear := true
            inf_gap := gap_end
            sup_gap := gap_start
            for i = j - 1 to 0 by 1
                inf_gap := math.max(inf_gap, high[i])
                inf_gap
            if (sup_gap - inf_gap) / (syminfo.mintick * 10) < 5  // only gap > 5 pips are considered
                gap_bear := false
                gap_bear
/////////////////////////WORK 
        if gap_bull


            label_bull = label.new(bar_index[j], na, 'Bull gap: ' + str.tostring((sup_gap - inf_gap) / (syminfo.mintick * 100)) + ' pips\n' + '[' + str.tostring(inf_gap) + ' ; ' + str.tostring(sup_gap) + ']', color=color.green, textcolor=color.white, style=label.style_label_up, yloc=yloc.belowbar)  
//label.delete(label_bull[1])

            
            boxbull = box.new(left=bar_index[j], top=sup_gap, right=bar_index + 100, bottom=inf_gap, border_width=2)
            box.set_border_color(boxbull, color=color.new(color.green, 50))
            box.set_border_width(boxbull, 1)
            box.set_bgcolor(boxbull, color.new(color.green, 70))
            box.delete(boxbull[1])


        if gap_bear
        
            boxbear = box.new(left=bar_index[j], top=sup_gap, right=bar_index + 100, bottom=inf_gap, border_width=2)
            box.set_border_color(boxbear, color=color.new(color.red, 50))
            box.set_border_width(boxbear, 1)
            box.set_bgcolor(boxbear, color.new(color.red, 70))
            box.delete(boxbear[1])
            
            
            label_bear = label.new(bar_index[j], na, 'Bear gap: ' + str.tostring((sup_gap - inf_gap) / (syminfo.mintick * 100)) + ' pips\n' + '[' + str.tostring(inf_gap) + ' ; ' + str.tostring(sup_gap) + ']', color=color.red, textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar)
            //label.delete(label_bear[1])
           
//line.delete(line_bear_sup[1])

谢谢!

编辑:

数组脚本

代码语言:javascript
复制
//@version=5
indicator('Loop through arrays test')

arr = array.new_int(0)

array.push(arr, 1)
array.push(arr, 2)
array.push(arr, 3)
array.push(arr, 4)
array.push(arr, 5)

lab = ''
for i = 0 to array.size(arr) - 1 by 1
    lab += str.tostring(array.get(arr, array.size(arr) - 1 - i)) + ' '
    lab

l = label.new(bar_index, close, lab)
EN

回答 1

Stack Overflow用户

发布于 2022-08-24 11:26:21

您正在for loop中创建框。命令box.delete(boxbear[1])实际上访问在上一个栏上的循环中创建的最后一个box对象。

如果在for j = 1 to length by 1内部,gap_bull条件每次都是true,那么boxbear = box.new()将为该条创建length数量的框数,在该框中进行计算。box.delete(boxbear[1])将从前一个条形图的循环中删除最后一个,因为[]是序列的历史运算符,该序列由每个条形图的一个值组成。你可以尝试用盒子数组来解决你的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73443623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档