英文:
How to find the number of bars of the previous intersection by the condition [3]?
问题
我不知道如何找到前一个交叉的长度。看看上面的图片,你会立刻明白一切。是否可以通过函数 ta.barssince 找到条数?
indicator(title="OHLC", shorttitle="Close", overlay=true, max_bars_back=100)
a = 44967
plot(a, '1', color.white, 3)
var int r = 0
var x = 0
var int t = 0
var int p = 0
var int p1 = 0
var int p2 = 0
var float f = 0
var l = 0
var l1 = 0
var l2 = 0
isCond11 = ta.crossover(close, a)
isCond21 = ta.crossunder(close, a)
isCond1 = ta.cross(a, close)
x := isCond11 ? 1 : isCond21[1] ? 0 : nz(x[1])
r := isCond21 ? 1 : 0
l := ta.barssince(isCond11) + 1
l1 := ta.barssince(isCond21) + 1
p := int(math.max(1, l))
p1 := int(math.max(1, l1))
//highp = ta.highest(close, int(math.max(1, nz(p))))
p2 := l1[1] - l[1]
if isCond21
label.new(bar_index, close, str.tostring(l[1]), color = color.green)
label.new(bar_index, close-7000, str.tostring(p2), color = color.yellow)
英文:
The problem in the picture is indicated in red
I don't know how to find the length of the previous intersection. Look at the picture above and you will immediately understand everything. Is it possible to find the number of bars through the function ta.barssince?
//@version=5
indicator(title="OHLC", shorttitle="Close",overlay = true, max_bars_back = 100)
a = 44967
plot(a, '1', color.white, 3)
var int r = 0
var x = 0
var int t = 0
var int p = 0
var int p1 = 0
var int p2 = 0
var float f = 0
var l = 0
var l1 = 0
var l2 = 0
isCond11 = ta.crossover(close, a)
isCond21 = ta.crossunder(close, a)
isCond1 = ta.cross(a, close)
x := isCond11 ? 1 : isCond21[1] ? 0 : nz(x[1])
r := isCond21 ? 1 : 0
l := ta.barssince(isCond11) + 1
l1 := ta.barssince(isCond21) + 1
p := int(math.max(1, l))
p1 := int(math.max(1, l1))
//highp = ta.highest(close, int(math.max(1, nz(p))))
p2 := l1[1] - l[1]
if isCond21
label.new(bar_index, close, str.tostring(l[1]), color = color.green)
label.new(bar_index, close-7000, str.tostring(p2), color = color.yellow)
答案1
得分: 0
//@version=5
indicator("我的脚本")
ema = ta.ema(close, 50)
cond = ta.crossover(close, ema)
var int bars = 0
plot(ema)
plot(close)
bgcolor(cond ? color.green : na)
if cond
bars := ta.valuewhen(cond, bar_index, 0) - ta.valuewhen(cond, bar_index, 1)
label.new(bar_index, high, str.tostring(bars))
英文:
Example:
//@version=5
indicator("My script")
ema = ta.ema(close, 50)
cond = ta.crossover(close,ema)
var int bars = 0
plot(ema)
plot(close)
bgcolor(cond? color.green:na)
if cond
bars := ta.valuewhen(cond, bar_index,0) - ta.valuewhen(cond, bar_index,1)
label.new(bar_index, high, str.tostring(bars))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论