【问题标题】:PineScript Highest Bar between two zones两个区域之间的 PineScript 最高条
【发布时间】: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


    【解决方案1】:

    当我们处于适当的区域时,我们在这里监控 hi/lo,并在找到新的 hi/lo 时重新定位标签。因为我们使用标签,这是在 Pine 中实现您需要的唯一方法,所以您只会看到最后约 50 个标签。

    虽然打印标签不需要它们,但 hilo 变量会跟踪这些值,以便您可以在需要时重复使用它们:

    //@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)
    

    【讨论】:

    • 有没有办法得到50多个标签!!
    • 目前没有。我们已向 Pine 团队提出了更多要求,但在增加限制之前,还需要对脚本使用的内存进行管理。几个月后我们应该可以使用更多标签。
    • 是否有任何其他解决方法可以获得超过 50 个标签的标签?例如将 bar_index 存储在变量中并使用 barsince 来绘制标签?
    猜你喜欢
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 2023-03-22
    • 1970-01-01
    • 2017-11-09
    • 2020-06-16
    相关资源
    最近更新 更多