pine-script - Pinescript - 全局变量的历史参考在函数中返回意外结果
问题描述
当涉及到未在每个柱上执行的函数内部的历史引用时,用户定义的全局变量是否与内置变量的处理方式不同?以下两个示例产生不同的结果,其中第一个示例在标签中打印“NaN”,而第二个示例(使用内置关闭变量的示例)打印前一个柱的收盘值(正确的行为):
//@version=4
study("My Script", overlay=true)
_close = close
f()=>
label l1= label.new(bar_index, high, text=tostring(_close[1]), style=label.style_circle)
if(barstate.islast)
f()
//@version=4
study("My Script", overlay=true)
f()=>
label l1= label.new(bar_index, high, text=tostring(close[1]), style=label.style_circle)
if(barstate.islast)
f()
这让我非常困惑,因为它暗示内置变量的处理方式与全局用户定义的变量不同?
需要明确的是,我确实理解为什么以下示例不起作用,但我认为上述情况的行为应该有所不同:
//@version=4
study("My Script", overlay=true)
f(_close)=>
label l1= label.new(bar_index, high, text=tostring(_close[1]), style=label.style_circle)
if(barstate.islast)
f(close)
谁能解释这里发生了什么?谢谢!
解决方案
推荐阅读
- python - Python:如何有效地组合 collection.counter 对象的 DataFrame 列?
- html - 我可以在 React JS 中返回自定义 HTML div 吗?
- arrays - 使用随机数组字符串键入对象键/属性 - TypeScript
- mysql - \n 不能发布到 MYSQL 服务器
- c++ - dijkstra 算法打印路径会跳过一些数字并且不适用于某些数字
- javascript - 元素的 css 样式完成转换后是否有回调?
- r - 如何使用多种模式在 R 中执行 filter_all
- javascript - 如何在反应离子中将道具从一个组件传递到另一个组件
- command-line - 使用命令行开关启动 Chromium 无效
- javascript - 在 IE11 的子窗口中打开新组件不起作用