0

这是一个简短的版本,我的问题很容易看到。

我得到带有目标柱指数的价格,并在每次达到新高时更新它。将其绘制到图表或带有标签的最后一根可见蜡烛时,您可以看到值 x。然后我将完全相同的价格变量放入警报函数,我也应该得到值 x,但我得到值 y。是因为目标条形指数在不同的时间范围内工作吗?如果是这样,有没有办法获得特定时间范围的条形索引?还是我的想法有误?

希望我能得到任何建议。谢谢

我也发布了一张图片,您可以在其中看到具有不同值的标签和警报。

问题可见的图像

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=4
strategy("test_1", overlay = true, calc_on_every_tick = true)

// Bar index plot
plot(bar_index,  color=color.new(color.blue,100), title="Bar Index")


//      ***************************************************************************
//      **********************************  INPUT *********************************
//      ***************************************************************************

structureLookback   = input(title="Lookback", type=input.integer, defval=1, tooltip="Lookback")

var p1              = "Settings for Anchor 1"
p1TradeType         = input(title="Long/Short?", type=input.string, defval="Long", group=p1, options=["Long", "Short"], tooltip="Change if Bull or Bear market, you have the option between long and short trades")
p1TargetBarIndex    = input(title="Bar Index", type=input.integer, defval=0,  group=p1, tooltip="Insert bar index of Pivot bar")

var p1Price     = 0.0
var p1TPrice    = 0.0
  
//Update p1Price aufgrund von Price Action

if (bar_index >= p1TargetBarIndex and p1TargetBarIndex != 0 )
    p1TPrice := p1TradeType == "Long" ? highest(high, structureLookback) : lowest(low, structureLookback)

    if (p1TPrice > p1Price and p1TradeType == "Long")
        p1Price := p1TPrice

plot(p1Price!=0? p1Price : na,color=color.gray, title="second Pivot - P1")

l = label.new(bar_index, na, text=tostring(p1Price), color=color.red, style=label.style_label_down, yloc=yloc.abovebar)
label.delete(l[1])


if (barstate.isrealtime)
    alert( " Price: " + tostring(p1Price) , freq= alert.freq_once_per_bar)
  


    
4

0 回答 0