两个区域之间的 PineScript 最高栏
PineScript Highest Bar between two zones
更新 1:
让我尝试修改我的问题,因为我认为我想实现的目标不是很清楚,我也尝试了另一种解决方案
所以我的目标是在特定区域找到最高的蜡烛(绿色圆圈蜡烛),这是我下面屏幕截图中的绿色区域。
现在我所做的是当 d1 < 50 和 d > 50 时循环,然后我逐条循环以找到最高柱的索引
然后当我找到它时,我做了一个 barssince(d1 < 50 and d > 50) 来发现我在绿色区域有多少根蜡烛
最后我将用最高点的柱索引减去 barsince 数,瞧
如此清晰的例子
让我们说我的绿色区域,当我循环时我发现第 4 根柱子是我做一个柱子后最高的柱子,因为它告诉我我有
绿色区域总共有 7 个柱状图,所以要知道哪个是那个区域内最高的柱状图,我会做 7-4 = 3
所以如果我做 -3 的偏移量,我应该找到最高的蜡烛,但它不起作用。
正如您在屏幕截图中看到的那样,如果我发现应该以紫色突出显示的蜡烛应该从橙色突出显示区域开始偏移 -3 但它确实是 - 5 所以我不确定发生了什么
这是我的编码尝试
//@version=4
study(title="trytofindhighesthigh", shorttitle="trytofindhighesthigh", max_bars_back=5000)
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
// plotchar(crossabove,char='o')
var counter = 0.0
var keephigh = 0.0
var keepbarindex = 0.0
var h_indx = 0
if d > 50 and counter == 0
counter := counter + 1
keephigh := high
keepbarindex := bar_index
h_indx := 0
else if d > 50 and counter > 0
counter := counter + 1
if high >= keephigh
keephigh := high
keepbarindex := bar_index
h_indx := h_indx + 1
if d < 50
counter := 0
mycolor4 = if d[1] > 50 and d < 50
color.orange
//color the chart depending on the stochastic
bgcolor(color=mycolor4, transp=85)
mycolor5 = if d[1] > 50 and d < 50
color.purple
bgcolor(color=mycolor5, transp=85,offset=-1 * ( barssince(d[1] < 50 and d >50 ) - h_indx) )
plot(-1 * (barssince(d[1] < 50 and d >50 ) - h_indx) )
-- 更新 1 结束
我想找到两个区域之间的最高点,但我很难理解如何实现它
我的区域在 1 和 2 之间划定(在我的图表上以绿色突出显示),但我不确定如何实现它。我尝试组合 barssince 、 highest 和 bar_index 但未能实现
我想要的输出是在形成绿色区域最高点的蜡烛上贴上标签
现在我尝试做的是查看那个特定区域以找到达到最高点的 N 根蜡烛
为了能够做到这一点,我对蜡烛进行了循环以找到最高价并存储具有最高价的蜡烛。
然后我会做一个 barsince
我的编码尝试
//@version=4
study(title="whatever", shorttitle="Colored SMA", max_bars_back=5000,overlay=true)
// SMA
smaplot = input (false, title="Show MA on chart")
len2 = input(50, minval=1, title="ma Length")
src2 = close
out2 = sma(src2, len2)
colorsma = if out2 > out2[1]
color.green
else if out2 < out2[1]
color.red
else
color.blue
plot(out2, color=colorsma )
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
// color when the candle cross the 50
//crossabove
// colors1 = if d[1] < 50 and d > 50
// color.yellow
// bgcolor(color=colors1, transp=85)
// //crossbelow
// colors2 = if d[1] > 50 and d < 50
// color.blue
// bgcolor(color=colors2, transp=85)
// var test = 0
// test := if d[1] > 50 and d < 50
// 1
// plot(barssince(d[1] < 50 and d > 50 and d[1] > 50 and d < 50),color=color.orange)
crossabove = if d[1] < 50 and d > 50
1
else
0
crossbelow = if d[1] > 50 and d < 50
2
else
0
plotchar(crossabove==1 ,title = "Crossabove" , char="1",color=color.green,location=location.belowbar,transp=0)
plotchar(crossbelow==2 ,title = "Crossbelow" , char="2",color=color.green,location=location.belowbar,transp=0)
temp_BarSincecrossabove = barssince(crossabove==1) + 3
temp_BarSincecrossabove_2 = temp_BarSincecrossabove <= 0 ? 1 : temp_BarSincecrossabove
temp_BarSincecrossabove_3 = na(temp_BarSincecrossabove_2) ? 1 : temp_BarSincecrossabove_2
highestpointBarSincecrossabove = highest(high,temp_BarSincecrossabove_3)
highestBarSincecrossabove = highestbars(high,temp_BarSincecrossabove_3)
plot(highestpointBarSincecrossabove)
// plotchar(bar_index[-highestBarSincecrossabove] ,title = "Highest High", text= '[HH]',color=color.green,location=location.abovebar,transp=0)
或者我可能需要找到高点并跟踪它,我现在不确定。接下来的问题是如何检查两个不同绿色区域之间的最高点,但我想我首先需要弄清楚这个问题可以使用什么逻辑
谢谢
在这里,我们在适当的区域中监视 hi/lo,并在找到新的 hi/lo 时重新定位标签。因为我们正在使用标签,这是 Pine 中实现您需要的唯一方法,所以您只会看到最后 ~50 个标签。
虽然打印标签不需要它们,但 hi
和 lo
变量会跟踪这些值,因此您可以在需要时重复使用它们:
//@version=4
study(title="whatever", shorttitle="Colored SMA", max_bars_back=5000,overlay=true)
// SMA
smaplot = input (false, title="Show MA on chart")
len2 = input(50, minval=1, title="ma Length")
src2 = close
out2 = sma(src2, len2)
colorsma = if out2 > out2[1]
color.green
else if out2 < out2[1]
color.red
else
color.blue
plot(out2, color=colorsma )
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
var float hi = na
var float lo = na
var label labelHi = na
var label labelLo = na
// Detect crosses.
xUp = crossover( d, 50)
xDn = crossunder(d, 50)
// When entering new zone, reset hi/lo and create a new label.
if xUp
hi := high
labelHi := label.new(bar_index, na, "▼", yloc = yloc.abovebar, color = #000000, textcolor = color.lime, style = label.style_none)
else if xDn
lo := low
labelLo := label.new(bar_index, na, "▲", yloc = yloc.belowbar, color = #000000, textcolor = color.red, style = label.style_none)
// When in a zone, continuously monitor for newer hi/lo and if one is found, move label.
if up3 and high > hi
hi := high
label.set_xy(labelHi, bar_index, na)
else if down3 and low < lo
lo := low
label.set_xy(labelLo, bar_index, na)
plotchar(xUp, title = "Crossabove" , char="1",color=color.green,location=location.belowbar,transp=0)
plotchar(xDn, title = "Crossbelow" , char="2",color=color.green,location=location.belowbar,transp=0)
更新 1:
让我尝试修改我的问题,因为我认为我想实现的目标不是很清楚,我也尝试了另一种解决方案 所以我的目标是在特定区域找到最高的蜡烛(绿色圆圈蜡烛),这是我下面屏幕截图中的绿色区域。
现在我所做的是当 d1 < 50 和 d > 50 时循环,然后我逐条循环以找到最高柱的索引 然后当我找到它时,我做了一个 barssince(d1 < 50 and d > 50) 来发现我在绿色区域有多少根蜡烛 最后我将用最高点的柱索引减去 barsince 数,瞧 如此清晰的例子 让我们说我的绿色区域,当我循环时我发现第 4 根柱子是我做一个柱子后最高的柱子,因为它告诉我我有 绿色区域总共有 7 个柱状图,所以要知道哪个是那个区域内最高的柱状图,我会做 7-4 = 3 所以如果我做 -3 的偏移量,我应该找到最高的蜡烛,但它不起作用。 正如您在屏幕截图中看到的那样,如果我发现应该以紫色突出显示的蜡烛应该从橙色突出显示区域开始偏移 -3 但它确实是 - 5 所以我不确定发生了什么
这是我的编码尝试
//@version=4
study(title="trytofindhighesthigh", shorttitle="trytofindhighesthigh", max_bars_back=5000)
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
// plotchar(crossabove,char='o')
var counter = 0.0
var keephigh = 0.0
var keepbarindex = 0.0
var h_indx = 0
if d > 50 and counter == 0
counter := counter + 1
keephigh := high
keepbarindex := bar_index
h_indx := 0
else if d > 50 and counter > 0
counter := counter + 1
if high >= keephigh
keephigh := high
keepbarindex := bar_index
h_indx := h_indx + 1
if d < 50
counter := 0
mycolor4 = if d[1] > 50 and d < 50
color.orange
//color the chart depending on the stochastic
bgcolor(color=mycolor4, transp=85)
mycolor5 = if d[1] > 50 and d < 50
color.purple
bgcolor(color=mycolor5, transp=85,offset=-1 * ( barssince(d[1] < 50 and d >50 ) - h_indx) )
plot(-1 * (barssince(d[1] < 50 and d >50 ) - h_indx) )
-- 更新 1 结束
我想找到两个区域之间的最高点,但我很难理解如何实现它
我的区域在 1 和 2 之间划定(在我的图表上以绿色突出显示),但我不确定如何实现它。我尝试组合 barssince 、 highest 和 bar_index 但未能实现
我想要的输出是在形成绿色区域最高点的蜡烛上贴上标签
现在我尝试做的是查看那个特定区域以找到达到最高点的 N 根蜡烛
为了能够做到这一点,我对蜡烛进行了循环以找到最高价并存储具有最高价的蜡烛。 然后我会做一个 barsince
我的编码尝试
//@version=4
study(title="whatever", shorttitle="Colored SMA", max_bars_back=5000,overlay=true)
// SMA
smaplot = input (false, title="Show MA on chart")
len2 = input(50, minval=1, title="ma Length")
src2 = close
out2 = sma(src2, len2)
colorsma = if out2 > out2[1]
color.green
else if out2 < out2[1]
color.red
else
color.blue
plot(out2, color=colorsma )
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
// color when the candle cross the 50
//crossabove
// colors1 = if d[1] < 50 and d > 50
// color.yellow
// bgcolor(color=colors1, transp=85)
// //crossbelow
// colors2 = if d[1] > 50 and d < 50
// color.blue
// bgcolor(color=colors2, transp=85)
// var test = 0
// test := if d[1] > 50 and d < 50
// 1
// plot(barssince(d[1] < 50 and d > 50 and d[1] > 50 and d < 50),color=color.orange)
crossabove = if d[1] < 50 and d > 50
1
else
0
crossbelow = if d[1] > 50 and d < 50
2
else
0
plotchar(crossabove==1 ,title = "Crossabove" , char="1",color=color.green,location=location.belowbar,transp=0)
plotchar(crossbelow==2 ,title = "Crossbelow" , char="2",color=color.green,location=location.belowbar,transp=0)
temp_BarSincecrossabove = barssince(crossabove==1) + 3
temp_BarSincecrossabove_2 = temp_BarSincecrossabove <= 0 ? 1 : temp_BarSincecrossabove
temp_BarSincecrossabove_3 = na(temp_BarSincecrossabove_2) ? 1 : temp_BarSincecrossabove_2
highestpointBarSincecrossabove = highest(high,temp_BarSincecrossabove_3)
highestBarSincecrossabove = highestbars(high,temp_BarSincecrossabove_3)
plot(highestpointBarSincecrossabove)
// plotchar(bar_index[-highestBarSincecrossabove] ,title = "Highest High", text= '[HH]',color=color.green,location=location.abovebar,transp=0)
或者我可能需要找到高点并跟踪它,我现在不确定。接下来的问题是如何检查两个不同绿色区域之间的最高点,但我想我首先需要弄清楚这个问题可以使用什么逻辑
谢谢
在这里,我们在适当的区域中监视 hi/lo,并在找到新的 hi/lo 时重新定位标签。因为我们正在使用标签,这是 Pine 中实现您需要的唯一方法,所以您只会看到最后 ~50 个标签。
虽然打印标签不需要它们,但 hi
和 lo
变量会跟踪这些值,因此您可以在需要时重复使用它们:
//@version=4
study(title="whatever", shorttitle="Colored SMA", max_bars_back=5000,overlay=true)
// SMA
smaplot = input (false, title="Show MA on chart")
len2 = input(50, minval=1, title="ma Length")
src2 = close
out2 = sma(src2, len2)
colorsma = if out2 > out2[1]
color.green
else if out2 < out2[1]
color.red
else
color.blue
plot(out2, color=colorsma )
//Stochastic
smooth = input(2, minval=1), K = input(3, minval=1), D=input(5,minval=1)
hhs=highest(high,K)
ll=lowest(low,K)
k = sma((close-ll)/(hhs-ll)*100, smooth)
d = sma(k, D)
up3 = d > 50
down3 = d < 50
mycolor3 = up3 ? color.green : down3 ? color.red : color.blue
backgroundColour = mycolor3
//color the chart depending on the stochastic
bgcolor(color=backgroundColour, transp=85)
var float hi = na
var float lo = na
var label labelHi = na
var label labelLo = na
// Detect crosses.
xUp = crossover( d, 50)
xDn = crossunder(d, 50)
// When entering new zone, reset hi/lo and create a new label.
if xUp
hi := high
labelHi := label.new(bar_index, na, "▼", yloc = yloc.abovebar, color = #000000, textcolor = color.lime, style = label.style_none)
else if xDn
lo := low
labelLo := label.new(bar_index, na, "▲", yloc = yloc.belowbar, color = #000000, textcolor = color.red, style = label.style_none)
// When in a zone, continuously monitor for newer hi/lo and if one is found, move label.
if up3 and high > hi
hi := high
label.set_xy(labelHi, bar_index, na)
else if down3 and low < lo
lo := low
label.set_xy(labelLo, bar_index, na)
plotchar(xUp, title = "Crossabove" , char="1",color=color.green,location=location.belowbar,transp=0)
plotchar(xDn, title = "Crossbelow" , char="2",color=color.green,location=location.belowbar,transp=0)