Pine script 要将三元运算符转换为循环吗

Pine script 要将三元运算符转换为循环吗,pine-script,Pine Script,我正在制作一个指示器,如果在该指示器之后的值小于高[100],我只想保存高[100]的值 我想保留该值,直到得到另一个类似的条件,最后一个high[100]是否高于或低于新的high[100]条件并不重要 我试着在循环中做,但因为我对循环非常陌生,所以我还没有成功 //@version=3 strategy("trend hybrid",overlay=true) long_2 = highest(high,100) high_long = high[100] long_test = hig

我正在制作一个指示器,如果在该指示器之后的值小于
高[100]
,我只想保存
高[100]
的值

我想保留该值,直到得到另一个类似的条件,最后一个
high[100]
是否高于或低于新的
high[100]
条件并不重要

我试着在循环中做,但因为我对循环非常陌生,所以我还没有成功

 //@version=3
strategy("trend hybrid",overlay=true)

long_2 = highest(high,100)
high_long = high[100]
long_test = highest(high,99)

long = na
long := long_test <= high_long ? high_long : long[1]

plot(long) 


//@version=3
study("For Loop tutorial - Example 6")
l = high[100]
y = high
for i = 99 to 1
    if high[i] <= high[l]
        break    
    y := l

plot(y, style=line, color=green, linewidth=3)
/@version=3
策略(“趋势混合”,叠加=真)
长2=最高(高,100)
高长=高[100]
长_测试=最高(高,99)
长=不适用

long:=long_test这可能就是你要找的。请记住,检测您的病情需要100个条,因此蓝色标签和线条在过去打印时的偏移量为
长度-1
。只有检测到新高点时出现的紫红色圆圈才会绘制在发生检测的蜡烛上。您可以更改输入中的长度


我将带您了解两种方法,使用循环,因为这是您想要的,并使用推荐的方法

使用循环

//@version=4
//@author=lucemanb
study("Highest", overlay=true)

// your bars limit
limit = input(100)

// we start comparing from 100th bar to the next 100 candles
highest = high[limit]

// if we find a candle greater than that, we set the high to the new value
//for i=limit to limit+limit // refer bottom 11
for i=0 to limit
    if high[i] > highest
        highest := high[i]

// we check - if our 100th high is equal to the highest value that we were searching for, it means its the highest.
newValue = high[limit] == highest

// we draw a background color on the place that we find
// note that, since we are checking the level 100 candles behind, we need to set the offset so
// that we can see where the level is
bgcolor(newValue?color.red:na, offset=-limit)

// 11 Your after is ambiguous, if you mean the candles older than 100th candle, remove the first '//' on line 12 and put it on lime 13
推荐方式

//@version=4
//@author=lucemanb
study("Highest", overlay=true)

// your bars limit
limit = input(100)

// we simply check if our 100th high is equal to the highest high 
// from the 100th candle to the other 99 candles after it.
newValue = high[limit] == highest(limit) //[limit] // refer bottom 11

// we draw a background color on the place that we find
// note that, since we are checking the level 100 candles behind, we need to set the offset so
// that we can see where the level is
bgcolor(newValue?color.red:na, offset=-limit)

// 11 Your after is ambiguos, if you mean the candles older than 100th candle, remove the first '//' on the line 10
请仔细阅读评论



我希望这有帮助

嗨,你的问题不清楚,你可能会被否决。为了澄清,您需要的条件是,如果最后101-200支蜡烛小于
high[100]
,您需要将
high[100]
设置为某个变量,这就是您的意思吗?您的richt oke我已经更新了代码,我想在循环中转换该代码。所以我想得到同样的结果,但是以循环的形式,那么你的问题在哪里呢?你的代码中没有尝试你所描述的内容(没有循环或其他)。第二个脚本是我尝试过的,但是我对循环非常陌生,我不知道我在做什么。嘿,Luc,你的代码扫描100中的高条,如果它是最后一个,它会显示出来。这不是他想要的。Y,很可能不是。我不太确定我的代码是否是他想要的,所以我想我会展示一些东西,然后会有评论或其他答案。也许你是对的。@lucaalbers这有帮助吗?是的,我还有一个问题。如果你能帮我的话,我会很感激的。这是书名。如果你看我的acc,你会发现它。尝试停止和限制策略。退出
//@version=4
//@author=lucemanb
study("Highest", overlay=true)

// your bars limit
limit = input(100)

// we simply check if our 100th high is equal to the highest high 
// from the 100th candle to the other 99 candles after it.
newValue = high[limit] == highest(limit) //[limit] // refer bottom 11

// we draw a background color on the place that we find
// note that, since we are checking the level 100 candles behind, we need to set the offset so
// that we can see where the level is
bgcolor(newValue?color.red:na, offset=-limit)

// 11 Your after is ambiguos, if you mean the candles older than 100th candle, remove the first '//' on the line 10