当价格在pine脚本中跌破时,如何删除行? [英] How to delete a line when price breaks it in pine script?
本文介绍了当价格在pine脚本中跌破时,如何删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-
我正在尝试按照以下代码删除区域(包含2行)
I'm attempting to delete a zone (which contains 2 lines) as per the below code
删除功能应是有条件的:仅在创建区域后的任何时间点价格突破区域的下限时才删除区域(两行)
delete function should be conditional:: only delete the zone (2 lines) when price breaks the lower line of the zone at any point in time after the zone has been created
//@version=4
study("zones", overlay=true)
// define a basing and explosive candles
basing_candle = ((abs(close - open)/abs(high - low)) < 0.5)
explosive_candle = (abs(close-open) / abs(high - low)) >= 0.5 and tr>tr[1]
// functions
bc_r = basing_candle and close < open
ex_g = explosive_candle and close > open
// demand zone
demand_zone = bc_r[1] and ex_g and low>=low[1] and close>open[1]
dz = if demand_zone
line.new(x1 = bar_index[1] ,y1=open[1], x2=bar_index, y2= open[1], style=line.style_solid, extend=extend.right, color=color.green, width=2)
line.new(x1 = bar_index[1] ,y1=low[1], x2=bar_index, y2= low[1], style=line.style_solid, extend=extend.right, color=color.green, width= 2)
推荐答案
I've taken the concept of How can I keep only the last x labels or lines? and applied it to your problem.
It's not the fastest code in the world, due to the for loop, but it'll work as you intened.
//@version=4
var maxBarsBack = 2000
study("zones", overlay=true, max_bars_back=maxBarsBack)
// define a basing and explosive candles
basing_candle = ((abs(close - open)/abs(high - low)) < 0.5)
explosive_candle = (abs(close-open) / abs(high - low)) >= 0.5 and tr>tr[1]
// functions
bc_r = basing_candle and close < open
ex_g = explosive_candle and close > open
// demand zone
demand_zone = bc_r[1] and ex_g and low>=low[1] and close>open[1]
line l1 = na
line l2 = na
dz = if demand_zone and barstate.isconfirmed
l1 := line.new(x1 = bar_index[1] ,y1=open[1], x2=bar_index, y2= open[1], style=line.style_solid, extend=extend.right, color=color.green, width=2)
l2 := line.new(x1 = bar_index[1] ,y1=low[1], x2=bar_index, y2= low[1], style=line.style_solid, extend=extend.right, color=color.green, width= 2)
for i = 1 to maxBarsBack
if not na(l1[i]) and close < low[i]
// We have identified a bar where a line was created.
line.delete(l1[i])
line.delete(l2[i])
这篇关于当价格在pine脚本中跌破时,如何删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文