VN神经蛙 wrote:
单凭文字描述不太确定你的意思,方便贴一下策略吗
抱歉,几天没看,下面是trading view的一段代码,想在vnpy中实现,thx
zigzag() =>
_isUp = close >= open
_isDown = close <= open
_direction = _isUp[1] and _isDown ? -1 : _isDown[1] and _isUp ? 1 : nz(_direction[1])
_zigzag = _isUp[1] and _isDown and _direction[1] != -1 ? highest(2) : _isDown[1] and _isUp and _direction[1] != 1 ? lowest(2) : na
_ticker = useHA ? heikenashi(tickerid) : tickerid
sz = useAltTF ? (change(time(tf)) != 0 ? security(_ticker, tf, zigzag()) : na) : zigzag()
plot(sz, title='zigzag', color=black, linewidth=2)
// ||--- Pattern Recognition:
x = valuewhen(sz, sz, 4)
a = valuewhen(sz, sz, 3)
b = valuewhen(sz, sz, 2)
c = valuewhen(sz, sz, 1)
d = valuewhen(sz, sz, 0)
xab = (abs(b-a)/abs(x-a))
xad = (abs(a-d)/abs(x-a))
abc = (abs(b-c)/abs(a-b))
bcd = (abs(c-d)/abs(b-c))