“时间"在变量声明中不是有效的类型关键字 [英] 'time' is not a valid type keyword in variable declaration

查看:60
本文介绍了“时间"在变量声明中不是有效的类型关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循 PineCoders for Pine 的最佳实践,我意识到没有 time 这样的类型.在以下情况下我应该怎么做?

I'm following the best practices by PineCoders for Pine and I realized that there is no such type as time. What should I do in the following scenario?

'time' 不是变量声明中的有效类型关键字

'time' is not a valid type keyword in variable declaration

请注意,我可以轻松地从 i_startDateTimei_endDateTime 中删除 time 前缀并解决问题,但我希望它使用最好的做法.就像 LucF goy https://www.tradingview 一样.com/script/Xh8tLDTe-Delta-Volume-Realtime-Action-LucF/.

Note that I could easily remove the time prefix from i_startDateTime and i_endDateTime and solve the issue but I want it to be using the best practices. Just like LucF goy did https://www.tradingview.com/script/Xh8tLDTe-Delta-Volume-Realtime-Action-LucF/.

var string START_TIME = "2018-01-01T00:00"
var string END_TIME = "2030-01-01T00:00"

var string GP12 = "Date range filtering"
bool    i_dateFilter = input(false, "Date Range Filtering", group = GP12)
time    i_startDateTime = input(timestamp(START_TIME), "Start Date/Time", type = input.time, group = GP12)
time    i_endDateTime = input(timestamp(END_TIME), "End Date/Time", type = input.time, group = GP12)

f_tradeDateIsAllowed() => i_dateFilter ? (time >= i_startDateTime and time <= i_endDateTime) : true

推荐答案

timestamp() 函数返回一个 int,因此您的变量必须声明为 int 也可以,或者在定义变量时省略 int.

The timestamp() function returns an int, so your variable must be declared as an int too, or just omit int when defining the variable.

//@version=4
study("Time", "T", overlay=true)

var string START_TIME = "2018-01-01T00:00"
var string END_TIME   = "2030-01-01T00:00"

var string  GP12            = "Date range filtering"
var bool    i_dateFilter    = input(false, "Date Range Filtering", group = GP12)
var int     i_fromDate      = input(timestamp(START_TIME), "Start Date/Time", type = input.time, group = GP12)
var int     i_toDate        = input(timestamp(END_TIME),   "End Date/Time",   type = input.time, group = GP12)

plot(na)

这篇关于“时间"在变量声明中不是有效的类型关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆