首页 > 解决方案 > 解决OCHL上执行代码的问题

问题描述

如您所知,在回测期间,代码仅在蜡烛关闭时执行,这对于某些回测来说根本不好。

有没有人可以解决这个问题?

我有个主意

例如,我们想在一分钟的时间范围内测试策略但是我们在一秒的时间范围内运行代码并将一分钟的时间范围数据与一秒的时间进行比较,这样我们就非常接近了到那个目标。

类似于以下代码:

//@version=4
strategy("projheie hal moshkel bozorg", overlay=true)

function() =>
    rsiTfOt=rsi(close, 14)
    co = crossover(rsiTfOt, 30)
    cu = crossover(rsiTfOt, 70)
    [co, cu]
    
[co, cu] = security(syminfo.tickerid, "60", function())
    
if (co)
    strategy.entry("RsiLE", strategy.long, comment="RsiLE")
if (cu)
    strategy.entry("RsiSE", strategy.short, comment="RsiSE")

但是这个代码有一个逻辑错误请指导我谁找到了这个想法的解决方案

标签: pine-script

解决方案


也许这可以帮助:

//@version=4
strategy("projheie hal moshkel bozorg", overlay=true)

length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
vrsi = rsi(price, length)
co = crossover(vrsi, overSold)
cu = crossunder(vrsi, overBought)    
    
[buy, sell] = security(syminfo.tickerid, "60", [co, cu], lookahead = true)
    
if (buy)
    strategy.entry("RsiLE", strategy.long, comment="RsiLE")
if (sell)
    strategy.entry("RsiSE", strategy.short, comment="RsiSE")

推荐阅读