pine-script - Tradingview pinescipt heiken ashi color change
问题描述
I'm trying to write a code that sends alert when heiken ashi bars change colour but it keeps sending the alert every time the condition is true but I only want the alert to be triggered once the condition is met
study("Heikin Ashi Candle Colour Change Alerts", overlay=true)
val = (open + high + low + close) / 4
up = val > val[1]
down = val <= val[1]
alertcondition(condition = up, title = 'Up Candle', message = ' - UP CANDLE')
alertcondition(condition = down, title = 'Down Candle', message = ' - DOWN CANDLE')
plotshape(up, title = 'Up Candle', style = shape.square, color = lime, location = location.bottom)
plotshape(down, title = 'Down Candle', style = shape.square, color = red, location = location.bottom)
解决方案
使用一个简单的计数器:
CountUP = 0
CountUP := nz(CountUP[1])
CountDOWN = 0
CountDOWN := nz(CountDOWN[1])
if up
CountUP += 1
CountDOWN := 0
CountDOWN
if down
CountUP := 0
CountDOWN += 1
CountUP
推荐阅读
- ios - swift:仅在超过 1 个部分时显示部分标题
- c# - 如何在一个选项卡中打开多个链接
- c# - System.ArgumentNullException:值不能为空。参数名称:unitOfWork
- javascript - 使用多个可选参数重构 JS 方法
- apache-spark - 在 Apache Spark 的 `bucketBy` 中,如何为每个存储桶生成 1 个文件,而不是每个分区每个存储桶生成 1 个文件?
- marketo - 我可以仅在 Marketo 中使用 API 创建营销活动吗?
- java - 如何设置 Twilio To phoneNumber 获取此号码作为 Spring Boot 中的用户输入
- swift - UITableView 和自定义单元格之间的覆盖边距
- spring - Bean not found 错误:通过字段表示的不满足的依赖关系
- javascript - Zingchar - 使用散点图规则