首页 > 解决方案 > 如何根据之字形外观在 pine 脚本中创建警报?

问题描述

我正在尝试包含我在 Tradingview 中找到的该指标的警报。当锯齿线出现在蜡烛上方时,我需要一个卖出警报,当它出现在蜡烛下方时,我需要一个买入警报。

以下是该指标的完整 pinescript:

showPatterns = input(true, title='Show Patterns')
showFib0000 = input(title='Display Fibonacci 0.000:', type=bool, defval=true)
showFib0236 = input(title='Display Fibonacci 0.236:', type=bool, defval=true)
showFib0382 = input(title='Display Fibonacci 0.382:', type=bool, defval=true)
showFib0500 = input(title='Display Fibonacci 0.500:', type=bool, defval=true)
showFib0618 = input(title='Display Fibonacci 0.618:', type=bool, defval=true)
showFib0764 = input(title='Display Fibonacci 0.764:', type=bool, defval=true)
showFib1000 = input(title='Display Fibonacci 1.000:', type=bool, defval=true)
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)
z = valuewhen(sz, sz, 6) 
y = valuewhen(sz, sz, 5) 
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)
zyx = (abs(x-y)/abs(z-y))
zyb = (abs(b-y)/abs(z-y))
zyd = (abs(d-y)/abs(z-y))
zab = (abs(b-a)/abs(z-a))
zad = (abs(d-a)/abs(z-a))
zcd = (abs(d-c)/abs(z-c))
yxa = (abs(a-x)/abs(y-x))
yxc = (abs(c-x)/abs(y-x))
ybc = (abs(a-c)/abs(y-c))
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))
isABCD(_mode)=>
    _abc = abc >= 0.382 and abc <= 0.886
    _bcd = bcd >= 1.13 and bcd <= 2.618
    _abc and _bcd and (_mode == 1 ? d < c : d > c)
isBat(_mode)=>
    _xab = xab >= 0.382 and xab <= 0.5
    _abc = abc >= 0.382 and abc <= 0.886
    _bcd = bcd >= 1.618 and bcd <= 2.618
    _xad = xad <= 0.618 and xad <= 1.000    // 0.886
    _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)
is3Drive(_mode)=>
    _zyx = zyx >= 0.236 and zyx < 1.000
    _yxa = yxa >= 1.000 and yxa < 9.999
    _xab = xab >= 0.236 and xab < 1.000
    _abc = abc >= 1.000 and abc < 9.999
    _bcd = bcd >= 0.236 and bcd < 1.000
    _zyx and _yxa and _xab and _abc and _bcd and (_mode == 1 ? d < c : d > c)
plotshape(not showPatterns ? na : change(isABCD(-1)) > 0, text="\nAB=CD", title='Bear ABCD', style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0)
plotshape(not showPatterns ? na : change(isBat(-1)) > 0, text="Bat", title='Bear Bat', style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0)
plotshape(not showPatterns ? na : change(is3Drive(-1)) > 0, text="3Driver", title='Bear 3 Driver', style=shape.labeldown, color=maroon, textcolor=white, location=location.top, transp=0)
plotshape(not showPatterns ? na : change(isABCD(1)) > 0, text="AB=CD\n", title='Bull ABCD', style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(not showPatterns ? na : change(isBat(1)) > 0, text="Bat", title='Bull Bat', style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)
plotshape(not showPatterns ? na : change(is3Drive(1)) > 0, text="3Driver", title='Bull 3 Driver', style=shape.labelup, color=green, textcolor=white, location=location.bottom, transp=0)

谢谢你的帮助

标签: pine-scripttradingtradingview-api

解决方案


推荐阅读