【问题标题】:PineScript: Buy at certain time above day's high so farPineScript:在高于当天最高点的特定时间买入
【发布时间】:2019-08-16 15:25:19
【问题描述】:

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

我写了一个 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”导致了一个问题,因为到目前为止高点还没有被定义为当天的高点。

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

【问题讨论】:

    标签: pine-script back-testing


    【解决方案1】:

    这将在 14:00 之后买入,但仅在收盘价突破当天高点时才会买入。绘制的标记可帮助您了解情况何时发生。

    //@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)
    

    【讨论】:

    • 谢谢。这似乎把我带到了正确的方向。但它似乎仍然没有做我想做的事。它确实在下午2点进入。但无论亏损/盈利如何,并不总是在 15:15 关闭订单。好像把位置带到了第二天。由于是日内交易,我还需要做些什么吗?
    • 您可以尝试改用exitTime = year == 2019 and month == 8 and hour == 15 and minute >= 15,但如果没有退出未正确触发的具体示例,则很难诊断。链接到图表会有所帮助。
    猜你喜欢
    • 2020-09-11
    • 1970-01-01
    • 2022-12-10
    • 2022-07-26
    • 1970-01-01
    • 2020-11-05
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多