【问题标题】:Get indicators on 1 hour daily time frame in correlation to daily timeframe获取与每日时间范围相关的 1 小时每日时间范围内的指标
【发布时间】:2022-12-03 09:48:05
【问题描述】:

在一小时的时间范围内,我试图研究四天的每日蜡烛图,以了解趋势,以便在我应该卖出或买入股票时在 1 小时图表上创建一个指标。

我如何获取从一维分辨率的安全函数获取的系列的历史数据,以了解所有四个值的收盘价、开盘价、最高价和最低价。

但是对于从安全功能获得的系列中的所有索引,我得到了相同的值。

下面是代码:

//@version=5
indicator("My Script", overlay=true)
indexHighTf = barstate.isrealtime ? 1:0
indexCurrTf = barstate.isrealtime ? 0:1

d_timeframe_Close = request.security(syminfo.tickerid, "D", close[indexHighTf])[indexCurrTf]
d_timeframe_Open = request.security(syminfo.tickerid, "D", open[indexHighTf])[indexCurrTf]
d_timeframe_High = request.security(syminfo.tickerid, "D", high[indexHighTf])[indexCurrTf]
d_timeframe_Low = request.security(syminfo.tickerid, "D", low[indexHighTf])[indexCurrTf]

down_lowest = 0.00
down_id_lowest = 0.00
up_list = array.new_int(0)
up_highest = 0.00
up_id_highest = 0
up_low_of_heighest = 0.00
candle_start = 4
candle_end = 0
sell_alert = 0

if (d_timeframe_Open[candle_start]<d_timeframe_Close[candle_end])
    count = 0
    for i = candle_end to candle_start
        if (d_timeframe_Open[i]<d_timeframe_Close[i])
            if (count == 0)
                count := count+1
                up_highest := d_timeframe_High[i]
            if (up_highest <= d_timeframe_High[i])
                array.push(up_list, i)
                up_highest := d_timeframe_High[i]
                up_id_highest := i
    up_low_of_heighest := d_timeframe_Low[up_id_highest]
    if (open[0] > up_low_of_heighest and close[0] < up_low_of_heighest)
        sell_alert := 1
plotshape(sell_alert, style=shape.triangledown, location=location.belowbar, text="Sell")

【问题讨论】:

    标签: pine-script pinescript-v5


    【解决方案1】:

    我不确定您的目标是什么,但这可能会有所帮助:

    // © BlueJayBird
    
    //@version=5
    indicator("My script", overlay = true)
    
    fNoRepaint(timeframe, expression) =>
        request.security(symbol = syminfo.tickerid, timeframe = timeframe, expression = expression[1], lookahead = barmerge.lookahead_on)
    
    requestOpen = fNoRepaint('D', open)
    plot(requestOpen, 'Open Requested', color.orange, linewidth = 2, show_last = 24 * 4)
    
    requestHigh = fNoRepaint('D', high)
    plot(requestHigh, 'High Requested', color.red, linewidth = 2, show_last = 24 * 4)
    
    requestLow = fNoRepaint('D', low)
    plot(requestLow, 'Low Requested', color.green, linewidth = 2, show_last = 24 * 4)
    

    呈现为:

    记住:

    • 该线随着最后一个小时蜡烛移动,所以它会用最新的蜡烛推进整个 4 * 24,以某种方式修剪线。
    • 我正在使用 fNoRepaint 函数来避免请求中的重绘。

    和:

    • 您收到的是一系列数字,而不仅仅是一个值。代码中的 for 循环可能不是必需的。只需比较您可能需要的条件并绘制您想要的形状。
    • closeclose[0] 返回相同的值。

    如果您提供您想要验证的书面解释,我也许可以为您提供一些帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-09
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2021-12-27
      相关资源
      最近更新 更多