pinescript中指定时间的触发策略
trigger strategy at specified time in pinescript
我计划在 tradingview 中测试一个非常简单的策略,该策略需要根据前一根蜡烛的时间和颜色执行。下面是我的代码。我正在尝试 运行 它在 15 分钟蜡烛上,如果 9:15 到 9:30 蜡烛是绿色的然后买其他卖。
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 31
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Buy", strategy.long,1, when = shortCondition)
当我 运行 我在 tradingview 策略测试器中收到“无数据”错误。
如果我遗漏了什么,有人可以帮忙吗?
您有两个问题:
- 你的第二个
strategy.entry()
调用应该是 short
类型。
- 如果您想在 15 分钟图表上使用它,那么您的时间条件必须可以用 15 分钟柱表示。在 15 分钟图表上 09:31 处不会有任何柱线。因此,将其更改为 09:30.
这应该有效:
//@version=5
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 30
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Sell", strategy.short,1, when = shortCondition)
我计划在 tradingview 中测试一个非常简单的策略,该策略需要根据前一根蜡烛的时间和颜色执行。下面是我的代码。我正在尝试 运行 它在 15 分钟蜡烛上,如果 9:15 到 9:30 蜡烛是绿色的然后买其他卖。
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 31
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Buy", strategy.long,1, when = shortCondition)
当我 运行 我在 tradingview 策略测试器中收到“无数据”错误。
如果我遗漏了什么,有人可以帮忙吗?
您有两个问题:
- 你的第二个
strategy.entry()
调用应该是short
类型。 - 如果您想在 15 分钟图表上使用它,那么您的时间条件必须可以用 15 分钟柱表示。在 15 分钟图表上 09:31 处不会有任何柱线。因此,将其更改为 09:30.
这应该有效:
//@version=5
strategy("Time_Strategy", overlay=true, margin_long=100, margin_short=100)
if hour(time) == 09 and minute(time) == 30
longCondition = open[1] < close[1]
strategy.entry("Buy", strategy.long,1, when = longCondition)
shortCondition = open[1] > close[1]
strategy.entry("Sell", strategy.short,1, when = shortCondition)