如何通过序列下标访问枢轴点?附Pine Script实现代码
通过序列下标访问枢轴点
my_pivothigh(float _series = high, int _leftBars, int _rightBars) => float _pivotHigh = na int _pivotRange = ( _leftBars + _rightBars ) float _leftEdgeValue = nz(_series[_pivotRange], na) if not na(_series) and _leftBars > 0 and _rightBars > 0 and not na(_leftEdgeValue) float _possiblePivotHigh = _series[_rightBars] float[] _arrayOfSeriesValues = array.new_float(0) for _barIndex = _pivotRange to 0 array.push(_arrayOfSeriesValues, _series[_barIndex]) //end for int _pivotHighRightBars = array.size(_arrayOfSeriesValues) - array.lastindexof(_arrayOfSeriesValues, array.max(_arrayOfSeriesValues)) - 1 _pivotHigh := ( _pivotHighRightBars == _rightBars ) ? _possiblePivotHigh : na //end if _pivotHigh
通过序列下标[]访问枢轴点,能更便捷地获取其历史值并进行遍历。目前这个函数仅能返回最新的_pivotHigh值;虽然可以用数组来存储历史值,但这类数据操作的复杂度更高。
当前若要访问最新的_pivotHigh值,可参考以下示例代码:
ph = my_pivothigh(high, 10, 10) if ph label.new(bar_index[10], ph, text=str.tostring(ph))
内容的提问来源于stack exchange,提问作者x945
相关产品推荐
相关产品推荐

