PineScript:到目前为止,在当天最高价的特定时间购买

时间:2019-08-16 15:25:19

标签: pine-script back-testing

我正在编写一种回溯测试策略,该策略应在每天的特定时间买入当天迄今为止的最高价。

我写了一个pinescript策略。见下文。我将其限制为今年的八月。这适用于5m的图表。

getValues()

我怀疑“止损=高位”正在引起问题,因为高位并未定义为当天的最高价。

要实现此目标,我需要对脚本进行哪些更改?

1 个答案:

答案 0 :(得分: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)