【问题标题】:Stoch security request setupStoch 安全请求设置
【发布时间】:2022-11-16 19:51:13
【问题描述】:

另一个新问题。我试图从 macd 和 stoch 上的其他时间范围获取数据。多亏了这个网站上的其他人,我让 macd 正常工作(我认为)。现在我正在尝试获取 stoch 的信息,但我遇到了安全请求问题。我想知道给定时间范围内 k 和 d 的值,但不确定如何设置 ta.stoch。

stoch_length        = input.int(14, title = 'K Length', minval=1 , group = stochGroup)
smoothK             = input.int(3, 'Smooth K', group = stochGroup)
smoothD             = input.int(3, "Smooth D", group = stochGroup)
OverBought          = input.int(80, group = stochGroup)
OverSold            = input.int(20, group = stochGroup)
lengthRSI           = input.int(14, "RSI Length", minval=1)
stoch_src           = input(close, title="RSI Source")
rsi1                = ta.rsi(src, lengthRSI)
k                   = ta.sma(ta.stoch(rsi1, rsi1, rsi1, stoch_length), smoothK)
d                   = ta.sma(k, smoothD)

[k5,d5,stochlength5] = request.security(syminfo.tickerid, "5", ta.stoch(stoch_src, smoothK, smoothD,stoch_length), barmerge.gaps_off,  barmerge.lookahead_on)

我希望它指向我的变量,这样如果我在输入列表中更改它们,它会根据新数字自动计算,而无需在脚本中手动更改它们(如果可能)

这就是我设置 macd 的方式,我以为我在工作,但如果我在 5m 图表上设置警报,它会根据该图表的 macd 发送警报,而不是 60m 图表

f_get_60_macd() => [src, fastMAlen, slowMAlen, hist]

[close60,macdLine60,signalLine60,histLine60] = request.security(syminfo.tickerid, "60", f_get_60_macd(), barmerge.gaps_off,  barmerge.lookahead_on)

macd_already_up_60          = ((macdLine60 > signalLine60) and  (histLine60 > histLine60[1])) or ((macdLine60 > macdLine60[1]) and  (histLine60 > histLine60[1]))
macd_already_dn_60          = ((macdLine60 < signalLine60) and ( histLine60 < histLine60[1])) or ((macdLine60 > signalLine60) and  (histLine60 < histLine60[1]))

macd_trend_state_60         = macd_already_up_60 ? 1 : macd_already_dn_60 ? -1 : 0

if  macd_trend_state_60  == 1 
    message = "60m macd trend UP " +syminfo.ticker
    alert(message, alert.freq_once_per_bar_close)

那么我可以在以下场景中使用它

stoch_cross_Up      = ta.crossover(k,d)
stoch_cross_Dn      = ta.crossunder(k,d)

stoch_already_up            = (k > d) and  (k > k[1])
stoch_already_dn            = ((k < d) and (k < k[1])) or ((k > d) and  (k < k[1]))

stoch_trend_state           = stoch_already_up  ? 1 : stoch_already_dn ? -1 : 0
stoch_cross_state           = stoch_cross_Up ? 1 : stoch_cross_Dn ? -1 : 0

在此先感谢您的帮助

【问题讨论】:

    标签: pine-script pinescript-v5


    【解决方案1】:

    为了在时间范围内正确获得您想要的信号,整个函数应该在所需的时间范围内运行。我在这里只用您指示的信号编写 macd 函数。您需要为 stoch 设置类似的功能。

    f_get_macd() => [src, fastMAlen, slowMAlen, hist]
        [macdLine,signalLine,histLine]= ta.macd(src, fastMAlen, slowMAlen,hist)
        macd_already_up_ = ((macdLine > signalLine) and  (histLine > histLine[1])) or ((macdLine > macdLine[1]) and  (histLine > histLine[1]))
        macd_already_dn_ = ((macdLine < signalLine) and ( histLine < histLine[1])) or ((macdLine > signalLine) and  (histLine < histLine[1]))
        macd_trend_state_ = macd_already_up_ ? 1 : macd_already_dn_ ? -1 : 0
        macd_trend_state_
    
    macd_trend_state_60 = request.security(syminfo.tickerid, "60", f_get_macd(close,fastlen,slowlen,histlen), barmerge.gaps_off)
    
    if macd_trend_state_60  == 1 
        message = "60m macd trend UP " +syminfo.ticker
        alert(message, alert.freq_once_per_bar_close
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2016-01-13
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多