Pine 脚本代码在低时间帧上运行缓慢
Pine Script Code is Slow on low Timeframes
我的代码在低时间范围 (240,60,15) 上加载需要时间。我对数组和 For 循环了解不多,我在 Whosebug 线程(使用循环的框更新功能)的帮助下创建了这段代码,而且我想使用用户输入来限制框数,请帮助我有这个问题。
maxbox = 500
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
indicator("Liquidity Zones",overlay=true,max_boxes_count=maxbox)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VolBars = input.bool(true, title='ON/OFF ', tooltip='Colored Bars based on Average Daily Trading Volume (ADTV)', inline='2',group="Volume Bars")
VolLen = input.int(10, title='Volume Length', minval=1, inline='2',group="Volume Bars")
Volume = nz(volume)
Volume2 = Volume*(high-low)
HighVOL = ta.highest(Volume2,VolLen)
VolAvg = math.sum(Volume, VolLen) / VolLen
IncreasingVol1 = VolAvg * 1.5
IncreasingVol2 = VolAvg * 2
bool BullCandle = close > open
bool BearCandle = close < open
Color = Volume >= IncreasingVol1 or Volume2 >= HighVOL ? 1 : 0
//Box condition
ColorCode = Volume >= IncreasingVol2 or Volume2 >= HighVOL ? 2 : Color
color BullColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : color.new(#8c8c8c,0)
color BearColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : color.new(#8c8c8c,50)
color BarColor = BullCandle ? BullColor : BearColor
barcolor(VolBars ? BarColor : na,editable=true)
plotchar(Volume > VolAvg * 3.5, char='', size=size.tiny,editable=false)
color BullBoxColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : na
color BearBoxColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : na
//Box Color
BoxColor = BullCandle ? BullBoxColor : BearBoxColor
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
look_back_period = input.int(100,title="Max Bars")
switchs = input.bool(true,title="Live Update Zones")
var box[] Bull_box = array.new_box(look_back_period)
var box[] Bear_box = array.new_box(look_back_period)
int size_array0 = 0
int size_array1 = 0
size_array0 := array.size(Bull_box)
size_array1 := array.size(Bear_box)
if ColorCode and BullCandle
array.push(Bull_box,box.new(left=time, top=close, right=time, bottom=open, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BullColor,80)))
if size_array0 > 0
for i = 0 to size_array0 -1
t = box.get_top(array.get(Bull_box, i))
b = box.get_bottom(array.get(Bull_box, i))
//Delete Box
if b >= low
box.delete(array.get(Bull_box,i))
//update Box
if switchs and t >= low
box.set_top(array.get(Bull_box, i),low)
if ColorCode and BearCandle
array.push(Bear_box,box.new(left=time, top=open, right=time, bottom=close, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BearColor,80)))
if size_array1 > 0
for i = 0 to size_array1 -1
t = box.get_top(array.get(Bear_box, i))
b = box.get_bottom(array.get(Bear_box, i))
//Delete Box
if t <= high
box.delete(array.get(Bear_box,i))
//Update Box
if switchs and b <= high
box.set_bottom(array.get(Bear_box, i),high)
//END-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////```
//@version=5
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
indicator("Liquidity Zones",overlay=true,max_boxes_count=500)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VolBars = input.bool(true, title='ON/OFF ', tooltip='Colored Bars based on Average Daily Trading Volume (ADTV)', inline='2',group="Volume Bars")
VolLen = input.int(10, title='Volume Length', minval=1, inline='2',group="Volume Bars")
Volume = nz(volume)
Volume2 = Volume*(high-low)
HighVOL = ta.highest(Volume2,VolLen)
VolAvg = math.sum(Volume, VolLen) / VolLen
IncreasingVol1 = VolAvg * 1.5
IncreasingVol2 = VolAvg * 2
bool BullCandle = close > open
bool BearCandle = close < open
Color = Volume >= IncreasingVol1 or Volume2 >= HighVOL ? 1 : 0
//Box condition
ColorCode = Volume >= IncreasingVol2 or Volume2 >= HighVOL ? 2 : Color
color BullColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : color.new(#8c8c8c,0)
color BearColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : color.new(#8c8c8c,50)
color BarColor = BullCandle ? BullColor : BearColor
barcolor(VolBars ? BarColor : na,editable=true)
plotchar(Volume > VolAvg * 3.5, char='', size=size.tiny,editable=false)
color BullBoxColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : na
color BearBoxColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : na
//Box Color
BoxColor = BullCandle ? BullBoxColor : BearBoxColor
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
max_levels = input.int(100,title="Max Levels", maxval = 250)
switchs = input.bool(true,title="Live Update Zones")
var box[] Bull_box = array.new_box()
var box[] Bear_box = array.new_box()
int size_array0 = array.size(Bull_box)
int size_array1 = array.size(Bear_box)
if ColorCode and BullCandle
array.push(Bull_box,box.new(left=time, top=close, right=time, bottom=open, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BullColor,80)))
if array.size(Bull_box) > max_levels
box.delete(array.shift(Bull_box))
if size_array0 > 0
for i = 0 to size_array0 -1
if i <= array.size(Bull_box) - 1 and array.size(Bull_box) > 0
t = box.get_top(array.get(Bull_box, i))
b = box.get_bottom(array.get(Bull_box, i))
//Delete Box
if b >= low
box.delete(array.remove(Bull_box,i))
//update Box
else if switchs and t >= low
box.set_top(array.get(Bull_box, i),low)
if ColorCode and BearCandle
array.push(Bear_box,box.new(left=time, top=open, right=time, bottom=close, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BearColor,80)))
if array.size(Bear_box) > max_levels
box.delete(array.shift(Bear_box))
if size_array1 > 0
for i = 0 to size_array1 -1
if i <= array.size(Bear_box) - 1 and array.size(Bear_box) > 0
t = box.get_top(array.get(Bear_box, i))
b = box.get_bottom(array.get(Bear_box, i))
//Delete Box
if t <= high
box.delete(array.remove(Bear_box,i))
//Update Box
else if switchs and b <= high
box.set_bottom(array.get(Bear_box, i),high)
我的代码在低时间范围 (240,60,15) 上加载需要时间。我对数组和 For 循环了解不多,我在 Whosebug 线程(使用循环的框更新功能)的帮助下创建了这段代码,而且我想使用用户输入来限制框数,请帮助我有这个问题。
maxbox = 500
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
indicator("Liquidity Zones",overlay=true,max_boxes_count=maxbox)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VolBars = input.bool(true, title='ON/OFF ', tooltip='Colored Bars based on Average Daily Trading Volume (ADTV)', inline='2',group="Volume Bars")
VolLen = input.int(10, title='Volume Length', minval=1, inline='2',group="Volume Bars")
Volume = nz(volume)
Volume2 = Volume*(high-low)
HighVOL = ta.highest(Volume2,VolLen)
VolAvg = math.sum(Volume, VolLen) / VolLen
IncreasingVol1 = VolAvg * 1.5
IncreasingVol2 = VolAvg * 2
bool BullCandle = close > open
bool BearCandle = close < open
Color = Volume >= IncreasingVol1 or Volume2 >= HighVOL ? 1 : 0
//Box condition
ColorCode = Volume >= IncreasingVol2 or Volume2 >= HighVOL ? 2 : Color
color BullColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : color.new(#8c8c8c,0)
color BearColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : color.new(#8c8c8c,50)
color BarColor = BullCandle ? BullColor : BearColor
barcolor(VolBars ? BarColor : na,editable=true)
plotchar(Volume > VolAvg * 3.5, char='', size=size.tiny,editable=false)
color BullBoxColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : na
color BearBoxColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : na
//Box Color
BoxColor = BullCandle ? BullBoxColor : BearBoxColor
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
look_back_period = input.int(100,title="Max Bars")
switchs = input.bool(true,title="Live Update Zones")
var box[] Bull_box = array.new_box(look_back_period)
var box[] Bear_box = array.new_box(look_back_period)
int size_array0 = 0
int size_array1 = 0
size_array0 := array.size(Bull_box)
size_array1 := array.size(Bear_box)
if ColorCode and BullCandle
array.push(Bull_box,box.new(left=time, top=close, right=time, bottom=open, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BullColor,80)))
if size_array0 > 0
for i = 0 to size_array0 -1
t = box.get_top(array.get(Bull_box, i))
b = box.get_bottom(array.get(Bull_box, i))
//Delete Box
if b >= low
box.delete(array.get(Bull_box,i))
//update Box
if switchs and t >= low
box.set_top(array.get(Bull_box, i),low)
if ColorCode and BearCandle
array.push(Bear_box,box.new(left=time, top=open, right=time, bottom=close, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BearColor,80)))
if size_array1 > 0
for i = 0 to size_array1 -1
t = box.get_top(array.get(Bear_box, i))
b = box.get_bottom(array.get(Bear_box, i))
//Delete Box
if t <= high
box.delete(array.get(Bear_box,i))
//Update Box
if switchs and b <= high
box.set_bottom(array.get(Bear_box, i),high)
//END-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////```
//@version=5
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
indicator("Liquidity Zones",overlay=true,max_boxes_count=500)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VolBars = input.bool(true, title='ON/OFF ', tooltip='Colored Bars based on Average Daily Trading Volume (ADTV)', inline='2',group="Volume Bars")
VolLen = input.int(10, title='Volume Length', minval=1, inline='2',group="Volume Bars")
Volume = nz(volume)
Volume2 = Volume*(high-low)
HighVOL = ta.highest(Volume2,VolLen)
VolAvg = math.sum(Volume, VolLen) / VolLen
IncreasingVol1 = VolAvg * 1.5
IncreasingVol2 = VolAvg * 2
bool BullCandle = close > open
bool BearCandle = close < open
Color = Volume >= IncreasingVol1 or Volume2 >= HighVOL ? 1 : 0
//Box condition
ColorCode = Volume >= IncreasingVol2 or Volume2 >= HighVOL ? 2 : Color
color BullColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : color.new(#8c8c8c,0)
color BearColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : color.new(#8c8c8c,50)
color BarColor = BullCandle ? BullColor : BearColor
barcolor(VolBars ? BarColor : na,editable=true)
plotchar(Volume > VolAvg * 3.5, char='', size=size.tiny,editable=false)
color BullBoxColor = ColorCode == 1 ? #208000 : ColorCode == 2 ? #008000 : na
color BearBoxColor = ColorCode == 1 ? #801a00 : ColorCode == 2 ? #e60000 : na
//Box Color
BoxColor = BullCandle ? BullBoxColor : BearBoxColor
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
max_levels = input.int(100,title="Max Levels", maxval = 250)
switchs = input.bool(true,title="Live Update Zones")
var box[] Bull_box = array.new_box()
var box[] Bear_box = array.new_box()
int size_array0 = array.size(Bull_box)
int size_array1 = array.size(Bear_box)
if ColorCode and BullCandle
array.push(Bull_box,box.new(left=time, top=close, right=time, bottom=open, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BullColor,80)))
if array.size(Bull_box) > max_levels
box.delete(array.shift(Bull_box))
if size_array0 > 0
for i = 0 to size_array0 -1
if i <= array.size(Bull_box) - 1 and array.size(Bull_box) > 0
t = box.get_top(array.get(Bull_box, i))
b = box.get_bottom(array.get(Bull_box, i))
//Delete Box
if b >= low
box.delete(array.remove(Bull_box,i))
//update Box
else if switchs and t >= low
box.set_top(array.get(Bull_box, i),low)
if ColorCode and BearCandle
array.push(Bear_box,box.new(left=time, top=open, right=time, bottom=close, extend=extend.right,
xloc=xloc.bar_time,border_color=na,bgcolor=color.new(BearColor,80)))
if array.size(Bear_box) > max_levels
box.delete(array.shift(Bear_box))
if size_array1 > 0
for i = 0 to size_array1 -1
if i <= array.size(Bear_box) - 1 and array.size(Bear_box) > 0
t = box.get_top(array.get(Bear_box, i))
b = box.get_bottom(array.get(Bear_box, i))
//Delete Box
if t <= high
box.delete(array.remove(Bear_box,i))
//Update Box
else if switchs and b <= high
box.set_bottom(array.get(Bear_box, i),high)