Pinescript:如果价格高于/低于行,则递归删除行

问题描述

概述

  • 我创建了一个识别分形的脚本
  • 如果确定了分形,则会创建一条线并将其向右延伸
  • 如果价格高于或低于该行的y1值,则该行将被删除

问题-行为/错误不一致

  • 脚本在每日时间段Picture of working example上适用于FX:CADJPY
  • 如果我在同一台仪器上切换到H4时间范围,则Tradingview会说“图纸过多,无法删除最旧的图纸”:Picture of error1
  • 如果我在任何时间段:Picture of error2
  • 打开FX:EURAUD,Tradingview都会说“内部服务器学习错误”

任何帮助将不胜感激。我的头融化了..谢谢。

//@version=4
study("FRACTAL_LINES",shorttitle="FL",overlay=true,precision=0,max_bars_back=5000)
//////////////////////FRACTALS/////////////////////////////////
header_fractals         = input(false,title = "====== Fractal Settings ======")
display_fractals        = input(false,title="Display Fractal triangles")
fractal_join_line       = input(true,title='Display Fractal lines')
extend                  = input(true,title='Extend fractal lines to current bar if they remain uncrossed')

aggressive = false
price = hl2

// fractal calculation
n = 2
header_fractals4 = input(false,title = "========================")

// Identify FRACTAL TOPS
isBWFractalBullish(mode) => ret = mode == 1 ? ((high[n+2] < high[n]) and (high[n+1] < high[n]) and (high[n-1] < high[n]) 
 and (high[n-2] < high[n])) or ((high[n+3] < high[n]) and (high[n+2] < high[n]) 
 and (high[n+1] == high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n])) 
 or ((high[n+4] < high[n]) and (high[n+3] < high[n]) and (high[n+2] == high[n]) 
 and (high[n+1] <= high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n])) 
 or ((high[n+5] < high[n]) and (high[n+4] < high[n]) and (high[n+3] == high[n]) 
 and (high[n+2] == high[n]) and (high[n+1] <= high[n]) and (high[n-1] < high[n]) and (high[n-2] < high[n])) 
 or ((high[n+6] < high[n]) and (high[n+5] < high[n]) and (high[n+4] == high[n]) 
 and (high[n+3] <= high[n]) and (high[n+2] == high[n]) and (high[n+1] <= high[n]) 
 and (high[n-1] < high[n]) and (high[n-2] < high[n])) : false
 
// Identify FRACTAL BOTTOMS
isBWFractalBearish(mode) => ret = mode == -1 ? ((low[n+2] > low[n]) and (low[n+1] > low[n]) and (low[n-1] > low[n]) 
 and (low[n-2] > low[n]))or ((low[n+3] > low[n]) and (low[n+2] > low[n]) and (low[n+1] == low[n]) 
 and (low[n-1] > low[n]) and (low[n-2] > low[n])) or ((low[n+4] > low[n]) and (low[n+3] > low[n]) 
 and (low[n+2] == low[n]) and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n])) 
 or ((low[n+5] > low[n]) and (low[n+4] > low[n]) and (low[n+3] == low[n]) and (low[n+2] == low[n]) 
 and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n])) or ((low[n+6] > low[n]) 
 and (low[n+5] > low[n]) and (low[n+4] == low[n]) and (low[n+3] >= low[n]) and (low[n+2] == low[n]) 
 and (low[n+1] >= low[n]) and (low[n-1] > low[n]) and (low[n-2] > low[n])) : false
 
filteredtopf = isBWFractalBullish(1)
filteredbotf = isBWFractalBearish(-1)

plotshape(filteredtopf and display_fractals,title="Up-Fractal",style=shape.triangleup,location=location.abovebar,offset=-2,color=color.green,transp=0)
plotshape(filteredbotf and display_fractals,title="Down-Fractal",style=shape.triangledown,location=location.belowbar,color=color.red,transp=0)

//// FRACTAL TOPS AND BOTTOMS Plots //////
plot(fractal_join_line ? valuewhen(filteredtopf,high[2],0) : na,title="Fractal Tops",style=plot.style_cross,linewidth=1,color=#b71c1c,transp=0) 
plot(fractal_join_line ? valuewhen(filteredbotf,low[2],title="Fractal Bottoms",color=#1b5e20,transp=0) 

var line fractal_top_line = na
var line fractal_bottom_line = na

//// Draw fractal lines if extend option is TRUE
if extend

    if filteredtopf
        fractal_top_line := line.new(x1=bar_index[2],y1=valuewhen(filteredtopf,0),x2=bar_index,y2=valuewhen(filteredtopf,color=color.red)
        line.set_extend(fractal_top_line,extend.right)
       
    if filteredbotf
        fractal_bottom_line := line.new(x1=bar_index[2],y1=valuewhen(filteredbotf,y2=valuewhen(filteredbotf,color=color.green)
        line.set_extend(fractal_bottom_line,extend.right)
 
//////////////////////////////////////////////
//// **HERE'S WHERE I RUN INTO TROUBLE** ////
////////////////////////////////////////////

//// Delete fractal lines if price crosses them
    for i=0 to bar_index
        if (barssince(high > line.get_y1(fractal_top_line[i]))) < (bar_index - line.get_x1(fractal_top_line[i]))
            line.delete(fractal_top_line[i]) 
        
        if (barssince(low < line.get_y1(fractal_bottom_line[i]))) < (bar_index - line.get_x1(fractal_bottom_line[i]))
            line.delete(fractal_bottom_line[i])
       

解决方法

这显示了从理论上讲应该可以运行的代码,但这不是因为处理过去历史记录中的图形ID的问题而引起的。计划在优先级最高的任务列表中进行修复,但尚无ETA。

Afaik,除了创建单独的变量以包含要绘制的所有线条的ID之外,目前无法可靠地实现所需的目标。

Void

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...