在松脚本中的所需固定时间执行代码
Executing a code at a desired fixed time in pine script
我一直在用 pine 开发一个信号发生器来处理索引。我被困在一个部分,我希望在每天下午 3 点/1500 小时 5 分钟蜡烛结束时执行退出代码。但是我无法读取当前时间并执行代码。
这是我试过的
计时 = 小时 ==1500
请就此问题请求支持。
https://www.pinecoders.com/faq_and_code/#time-dates-and-sessions 上的 PineCoders 常见问题解答的 时间、日期和会话 部分帮助我做了类似的事情。
如果您使用此内容在 PineScript 中创建一个新的指示器,它可能会给您一些有用的开始:
//@version=4
study("Time Example", overlay=false)
// You can plot your value only at a certain time.
// Here we plot 9 if it is the right time, and 0 if not.
// Replace 9 with a call to whatever function you want.
plot(not na(time("5", "1500-1504")) ? 9 : 0, color=color.blue)
// Or, you can set a value to na at first:
var int red_val = na
// And then change it only when the right time comes,
// when you are finally able to calculate it.
// Here we check if this bar's start time, if converted
// to 5-minute resolution, would start at 1500.
// Note: this uses the time zone of the exchange that
// the current symbol is traded on, not your local time.
if not na(time("5", "1500-1504"))
// You would put own your calculation here.
// This dayofmonth() call is just an example.
red_val := dayofmonth(timenow)
// Then, for example, you can plot the final result
// of your calculation later on in your code:
plot(red_val, color=color.red)
在任一示例中,not na(time("5", "1500-1504"))
对您的情况来说都是重要的一点。如果您查看上面链接的常见问题解答,还有其他(可能更好)的方法可以做到这一点。
https://www.tradingview.com/pine-script-reference/v4/#var_time 上的 PineScript 参考资料也很有用,但对我帮助最大的确实是常见问题解答中的示例。
我一直在用 pine 开发一个信号发生器来处理索引。我被困在一个部分,我希望在每天下午 3 点/1500 小时 5 分钟蜡烛结束时执行退出代码。但是我无法读取当前时间并执行代码。 这是我试过的 计时 = 小时 ==1500 请就此问题请求支持。
https://www.pinecoders.com/faq_and_code/#time-dates-and-sessions 上的 PineCoders 常见问题解答的 时间、日期和会话 部分帮助我做了类似的事情。
如果您使用此内容在 PineScript 中创建一个新的指示器,它可能会给您一些有用的开始:
//@version=4
study("Time Example", overlay=false)
// You can plot your value only at a certain time.
// Here we plot 9 if it is the right time, and 0 if not.
// Replace 9 with a call to whatever function you want.
plot(not na(time("5", "1500-1504")) ? 9 : 0, color=color.blue)
// Or, you can set a value to na at first:
var int red_val = na
// And then change it only when the right time comes,
// when you are finally able to calculate it.
// Here we check if this bar's start time, if converted
// to 5-minute resolution, would start at 1500.
// Note: this uses the time zone of the exchange that
// the current symbol is traded on, not your local time.
if not na(time("5", "1500-1504"))
// You would put own your calculation here.
// This dayofmonth() call is just an example.
red_val := dayofmonth(timenow)
// Then, for example, you can plot the final result
// of your calculation later on in your code:
plot(red_val, color=color.red)
在任一示例中,not na(time("5", "1500-1504"))
对您的情况来说都是重要的一点。如果您查看上面链接的常见问题解答,还有其他(可能更好)的方法可以做到这一点。
https://www.tradingview.com/pine-script-reference/v4/#var_time 上的 PineScript 参考资料也很有用,但对我帮助最大的确实是常见问题解答中的示例。