Tradingview pinescript- 3M 时间框架支撑和阻力图

问题描述 投票:0回答:1

使用tradingview Pinescript,我想在“3M”时间范围内指定数量的柱线的高/低点上绘制水平线,以便在任何时间范围内查看。该代码在“3M”时间范围内查看时有效。然而,当时间范围缩短时,就会出现问题。一些支撑/阻力线没有显示。

//@version=5
indicator("3M-HLINE", overlay=true)

// Define the timeframe
timeframe1 =input.timeframe('3M', "Timeframe")

// Calculate the number of bars to look back
numBarsBack1 =input.int(16,"BARS BACK")

// Arrays to store open and close values
var float[] openArr1 = array.new_float(numBarsBack1)
var float[] closeArr1 = array.new_float(numBarsBack1)

array.clear(openArr1)
array.clear(closeArr1)

baropen1 = request.security(syminfo.tickerid, timeframe1, high)
barclose1 = request.security(syminfo.tickerid, timeframe1, low)

// Accumulate 3M open/close values in arrays
for i = 1 to numBarsBack1
    array.unshift(openArr1, baropen1[i])
    array.unshift(closeArr1, barclose1[i])

// Plot the 3M open/close values as lines
for i = 0 to numBarsBack1 -1
    line.new(x1=bar_index - 1, y1=array.get(openArr1, i), x2=bar_index + 1, y2=array.get(openArr1, i), color=color.new(color.rgb(135, 206, 250), 0), width=2, extend=extend.both)
    line.new(x1=bar_index - 1, y1=array.get(closeArr1, i), x2=bar_index + 1, y2=array.get(closeArr1, i), color=color.new(color.rgb(135, 206, 250), 0), width=2, extend=extend.both)`

  1. 我尝试将“request.security”放入for循环中。脚本不允许这样做。
  2. 我尝试使用 hline 来绘图。不能与浮点数组一起使用。
pine-script pine-script-v5 trading tradingview-api
1个回答
0
投票

尝试

//@version=5
indicator("3M-HLINE", overlay=true)

// Define the timeframe
timeframe1 =input.timeframe('3M', "Timeframe")

// Calculate the number of bars to look back
numBarsBack1 =input.int(16,"BARS BACK")

myFun()=>
    // Arrays to store open and close values
    var float[] openArr1 = array.new_float(numBarsBack1)
    var float[] closeArr1 = array.new_float(numBarsBack1)

    array.clear(openArr1)
    array.clear(closeArr1)
    // Accumulate 3M open/close values in arrays
    for i = 1 to numBarsBack1
        array.unshift(openArr1, high[i])
        array.unshift(closeArr1, low[i])
    [openArr1, closeArr1]

[closeArr1, openArr1] = request.security(syminfo.tickerid, timeframe1, myFun())



if not na(openArr1) and not na(closeArr1)
    for i = 0 to numBarsBack1 -1
        line.new(x1=bar_index - 1, y1=array.get(openArr1, i), x2=bar_index + 1, y2=array.get(openArr1, i), color=color.new(color.rgb(135, 206, 250), 0), width=2, extend=extend.both)
        line.new(x1=bar_index - 1, y1=array.get(closeArr1, i), x2=bar_index + 1, y2=array.get(closeArr1, i), color=color.new(color.rgb(135, 206, 250), 0), width=2, extend=extend.both)

© www.soinside.com 2019 - 2024. All rights reserved.