0

我正在编写一个回测策略,以在每天高于当天最高点的特定时间买入。

我写了一个 pinescript 策略。见下文。我把它限制在今年八月。这适用于 5m 海图。

//@version=4
strategy("bnf2")

entryTime = year == 2019 and month == 8 and hour == 14 and minute == 0
exitTime = year == 2019 and month == 8 and hour == 15 and minute == 15

strategy.entry("bnf-long", strategy.long, 20, stop= high, when=entryTime)
strategy.close("bnf-long", when = exitTime)
plot(strategy.equity)

我怀疑“stop = high”会导致问题,因为到目前为止高点还没有被定义为当天的高点。

我需要对脚本进行哪些更改才能实现此目的?

4

1 回答 1

0

这将在 14h00 之后买入,但仅在收盘价突破当天高点时才会买入。绘制的标记可帮助您查看何时发生条件。

//@version=4
strategy("bnf2", overlay=true)

// Keep track of current day's high.
var dayHigh = 0.0
dayHigh := change(dayofweek) ? high : max(high, dayHigh)

entryTime = year == 2019 and month == 8 and hour == 14 and close > dayHigh[1]
exitTime = year == 2019 and month == 8 and hour == 15 and minute == 15
strategy.entry("bnf-long", strategy.long, 20, when = entryTime)
strategy.close("bnf-long", when = exitTime)
plot(dayHigh)
plotshape(entryTime, style = shape.triangleup, color = color.lime, location = location.belowbar, size = size.normal)
plotshape(exitTime, style = shape.triangledown, color = color.red, location = location.abovebar, size = size.normal)
// plot(strategy.equity)
于 2019-08-19T03:54:26.660 回答