pine-script - 如何计算 pinescript 中特定日期范围的枢轴级别?
问题描述
我正在尝试获取特定日期范围的每周枢轴计算的高/低/收盘系列数据..
示例代码:
//
study(title="Pivot Points", shorttitle="Weekly-Levels", overlay=true)
// defaultTimeFrame = ((isintraday) ? "D" : ((isdaily) ? "W" : ((isweekly) ? "M" : "3M")))
// inputTimeFrame = input(title="Time Frame", type=string, defval="Default")
// chosenTimeFrame = (inputTimeFrame == "Default") ? defaultTimeFrame : inputTimeFrame
startDate = input(title="Start Date", type=integer, defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=integer, defval=2, minval=1, maxval=12)
startYear = input(title="Start Year", type=integer, defval=2020, minval=2020, maxval=2100)
endDate = input(title="End Date", type=integer, defval=30, minval=1, maxval=31)
endMonth = input(title="End Month", type=integer, defval=6, minval=1, maxval=12)
endYear = input(title="End Year", type=integer, defval=2020, minval=1800, maxval=2100)
weekly_cpr = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
getSeries(e) => security(tickerid, weekly_cpr, e, lookahead=barmerge.lookahead_on)
H = getSeries(high[1])
L = getSeries(low[1])
C = getSeries(close[1])
// Main Pivot
P = (H + L + C) / 3
我得到以下错误。
Processing script...
line 40: Cannot call `security` with arguments (string, series[bool], series, literal bool, literal bool, literal string); available overloads: security(string, string, series[integer], const bool, const bool, string) => series[integer]; security(string, string, series, const bool, const bool, string) => series; security(string, string, series[bool], const bool, const bool, string) => series[bool]; security(string, string, series[color], const bool, const bool, string) => series[color];
让我知道我应该如何处理这个?
解决方案
这是实现您的目的的更简单方法。我们在图表的上下文中定义我们的计算和条件,然后将它们发送到security()
其 HTF 上下文中进行评估。Calcs 不会重绘:
//@version=4
study(title="Pivot Points", shorttitle="Weekly-Levels", overlay=true)
startDate = input(title="Start Date", defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", defval=2, minval=1, maxval=12)
startYear = input(title="Start Year", defval=2020, minval=2020, maxval=2100)
endDate = input(title="End Date", defval=30, minval=1, maxval=31)
endMonth = input(title="End Month", defval=6, minval=1, maxval=12)
endYear = input(title="End Year", defval=2020, minval=1800, maxval=2100)
weekly_cpr = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
H = high
L = low
C = close
P = (H + L + C) / 3
// We send both the date constraint and the request for the complete, calculated data through `security()`,
// so that all that is evaluated in the context of `security()`'s context.
pHtf = security(syminfo.tickerid, "W", weekly_cpr ? P[1] : na, lookahead = barmerge.lookahead_on)
plot(pHtf, "pHtf", color.blue, 1, plot.style_circles)
推荐阅读
- vuejs3 - Apexcharts:水平为真时的条形图错误
- flutter - Flutter 和 getx:update() 不通知 GetBuilder
- javascript - Hightchart 问题,当页面上使用多个绘图时
- html - CSS Flexbox 如何用分隔符均匀分隔两个元素
- python - Got ValueError:使用 tf.Keras 重新训练(拟合)加载的子类模型时没有为任何变量提供梯度
- javascript - 有人可以帮我理解这段代码吗?
- python - 将 XLSM 转换为 CSV 限制列数(范围)
- next.js - Tailwind grid-cols 无法与 Next 在生产环境中一起使用
- javascript - 从对象中获取相似的键
- flutter - Riverpod 提供程序调用一次 - 为什么对提供程序的后续调用会“缓存”?