pine-script - 如何根据之字形外观在 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)
谢谢你的帮助
解决方案
推荐阅读
- python - python中的主成分分析降维
- machine-learning - 为不平衡二元分类对数据进行过采样的过程
- powershell - PowerShell中的多个排除规则
- qt - QEventDispatcherWin32::processEvents 逻辑问题
- android - 如何验证选中了哪个复选框?
- javascript - jasmine:单元测试一个独立的 Promise 函数
- r - 如何在2个数据框之间进行查找
- swift - 斯威夫特:解压缩文件
- arrays - 将数组导入对象 - Angular 2+
- asp.net - 如何阻止某些 HTTP 方法访问特定 URL?