【发布时间】:2020-11-05 02:22:24
【问题描述】:
更新 1:
让我尝试修改我的问题,因为我认为我想要实现的目标不是很清楚,我也尝试了另一种解决方案 所以我的目标是在特定区域找到最高点蜡烛(绿色圆圈蜡烛),这是我下面屏幕截图中的绿色区域。
现在我做的是一个循环,当 d1 50 然后我逐条循环以找到最高条的索引 然后当我找到它时,我会做一个 barsince(d1 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 之间(在我的图表上以绿色突出显示)但我不知道如何实现它。我试图做一个组合 barsince , high 和 bar_index 但未能实现它
我想要的输出是在蜡烛上贴一个标签,形成绿色区域的最高点
现在我尝试做的是查看那个特定区域以找到最高点的 N 根蜡烛
为了能够做到这一点,我在蜡烛中做了一个循环,以找到最高点并存储最高点的蜡烛。 然后我会做一个酒吧
我的编码尝试
//@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)
或者也许我需要找到摆动高点来跟踪它,我现在不确定。接下来的问题是如何检查两个不同绿色区域之间的最高点,但我想我首先需要弄清楚这个问题可以使用什么逻辑
谢谢
【问题讨论】:
标签: pine-script