【问题标题】:Why does this Pinescript alert repaint, despite having refactored the security function?尽管重构了安全功能,为什么这个 Pinescript 警报会重新绘制?
【发布时间】:2021-03-18 18:48:42
【问题描述】:

我无法解决您发布的任何功能的问题。我正在尝试消除对应用于图表的指标的重新绘制,该图表的时间框架为 15m,需要将其带到 1h:

//@version=4
    res5 = input("60", type=input.resolution)

// Funzione di security incapsulata
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src, barmerge.gaps_off, barmerge.lookahead_on)[1]

// Funzioni di security
o = f_secureSecurity(syminfo.tickerid, res5, open)
c = f_secureSecurity(syminfo.tickerid, res5, close)
hz = f_secureSecurity(syminfo.tickerid, res5, high)
l = f_secureSecurity(syminfo.tickerid, res5, low)

////////////////////////////////////////////////////////////////////////////////
// INPUT SUPERTREND
st_mult   = input(0.1,   title = 'SuperTrend Multiplier', minval = 0, maxval = 100, step = 0.01)
st_period = input(50, title = 'SuperTrend Period',     minval = 1)

// CALCULATIONS //
up_lev =l - (st_mult * atr(st_period))
dn_lev = hz + (st_mult * atr(st_period))

up_trend   = 0.0
up_trend   := c[1] > up_trend[1]   ? max(up_lev, up_trend[1])   : up_lev

down_trend = 0.0
down_trend := c[1] < down_trend[1] ? min(dn_lev, down_trend[1]) : dn_lev

// Calculate trend var
trend = 0
trend := c > down_trend[1] ? 1: c < up_trend[1] ? -1 : nz(trend[1], 1)

// Calculate SuperTrend Line
st_line = trend ==1 ? up_trend : down_trend

////////////////////////////////////////////////////////////////////////////////
// CONDIZIONI DI INGRESSO A MERCATO
OpenLong = crossover(c, st_line)
OpenShort = crossunder(c, st_line)
CloseLong = OpenShort
CloseShort = OpenLong

////////////////////////////////////////////////////////////////////////////////
// SEGNALI DI DEBUG
OpenLongFlag = if OpenLong == true
    1
else
    0

OpenShortFlag = if OpenShort == true
    1
else
    0

CloseLongFlag = if CloseLong == true
    1
else
    0

CloseShortFlag = if CloseShort == true
    1
else
    0

plot(OpenLongFlag, color = color.black)
plot(OpenShortFlag, color = color.yellow)
plot(CloseLongFlag, color = color.blue)
plot(CloseShortFlag, color = color.red)

////////////////////////////////////////////////////////////////////////////////
// ALLERT
alertcondition(OpenLong,title="Open Long")
alertcondition(CloseLong,title="Close Long")
alertcondition(OpenShort,title="Open Short")
alertcondition(CloseShort,title="Close Short")code here

警报的生成时间与我在 Tradingview 图表中输入的调试信号不同,然后它们被重新绘制。

您之前发布的封装函数 (f_secureSecurity) 是否可能在如此短的时间范围内不起作用?

【问题讨论】:

    标签: pine-script repaint


    【解决方案1】:

    试试这个:

    ...
    f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], barmerge.gaps_off, barmerge.lookahead_on)
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-20
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 2015-01-25
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多