【问题标题】:Stochastic hline cross on different timeframe不同时间范围内的随机线交叉
【发布时间】:2021-10-28 21:07:31
【问题描述】:

我正在尝试创建一个策略,在该策略中查看信号的每小时时间范围(随机 D 线高于 60 或低于 40 线),然后在 15 分钟时间范围内执行交易 - 但我没有取得多大成功安全函数中的 hline 表达式。有人可以建议一个更好或不同的方法来做到这一点。

这是在每小时时间范围内定义随机属性的代码,而图表则专注于 15 分钟时间范围

我收到以下错误消息:Type hline cannot be used in security "expression" argument

////PINE 脚本

htf_stoch_k = security(syminfo.tickerid,"60",sma(stoch(close, high, low, 14), 1),lookahead=barmerge.lookahead_on)
htf_stoch_d = security(syminfo.tickerid,"60",sma(htf_stoch_k, 3),lookahead=barmerge.lookahead_on)
htf_stoch_h0 = security(syminfo.tickerid,"60",hline(60, "Upper Band", color=#787B86),lookahead=barmerge.lookahead_on)
htf_stoch_h1 = security(syminfo.tickerid,"60",hline(40, "Lower Band", color=#787B86),lookahead=barmerge.lookahead_on)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    给你,伙计(这没有重绘),

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © SafetyHammer
    
    //@version=4
    study("My Script")
    Length = input(14, minval=1, title="Stochastic Length")
    smoothK = input(1, title="Smoothing of Stochastic K")
    smoothD = input(3, title="Smoothing of Stochastic D")
    
    Res_stoch_k     = input(title="Stoch K Resolution", type=input.resolution, defval="60")  
    Res_stoch_d     = input(title="Stoch D Resolution", type=input.resolution, defval="60")  
    
    f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1],barmerge.gaps_on, lookahead = barmerge.lookahead_on) // orignal code line
    
    
    Sto             = stoch(close, high, low, Length)
    K               = sma(Sto, smoothK)
    D               = sma(Sto, smoothD)
    
    
    htf_stoch_k     = f_secureSecurity(syminfo.tickerid, Res_stoch_k, K)
    htf_stoch_d     = f_secureSecurity(syminfo.tickerid, Res_stoch_d, D)
    
    
    upper_bound     = input(title="Upper Bound", type=input.integer, defval=60, minval=0, maxval=100)  // User input for overbought horizontal line
    lower_bound     = input(title="Lower Bound", type=input.integer, defval=40, minval=0, maxval=100)  // User input for oversold horizontal line
    
    upper_hl        = hline(upper_bound, title="Upper bound") 
    lower_hl        = hline(lower_bound, title="Lower bound")
    
    top_hl          = hline(100, title="100 bound") 
    bottom_hl       = hline(0, title="0 bound")
    
    fill(top_hl, upper_hl, color=color.new(color.red,80))
    fill(lower_hl, bottom_hl, color=color.new(color.blue,80))
    
    plot(htf_stoch_k, title="htf_stoch K", color=color.new(color.blue,10))
    plot(htf_stoch_d, title="htf stoch D", color=color.new(color.red,10))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 2011-12-16
      • 2017-07-13
      • 2012-12-21
      • 1970-01-01
      相关资源
      最近更新 更多