时光倒流的第一个绿色酒吧

问题描述

我正在处理一些代码(这是Pine的新手),在其中我连续寻找3个绿色蜡烛,并向第一个蜡烛添加标签。使用bar_index-2可以轻松完成该部分。 但是,假设连续有5支绿色蜡烛。我有多个标签,但我只希望标签位于连续5个蜡烛的第一个绿色蜡烛上。我如何获得该信息? 谢谢你的帮助! 罗布

解决方法

这需要一个向下条以重置条件:

//@version=4
study("","",true)

// Define our boolean condition for an up bar.
upBar = close > open

// Here we do many things in one line:
// 1. Using `sum()`,we will add a value for the last 3 bars.
//    That's the `sum(...,3)` part.
// 2. The value we add for each bar is the evaluation of an expression.
//    That expression is a ternary: `upBar ? 1 : 0`.
//    It evaluates to `1` if the current bar is an upBar,//    and to zero when it is not.
// 3. We use the `==` boolean operator to compare the result of `sum()` to `3`.
//    When it is equal to `3`,`true` will be assigned to `upBars3`.
//    This will occur when `upBar` was true on each of the last 3 bars.
upBars3 = sum(upBar ? 1 : 0,3) == 3

// Here we generate a signal when our `upBars3` boolean variable is `true`,// and it was not `true` on the previous bar,which is the `not upBars3[1]` part.
signal = upBars3 and not upBars3[1]

// Here we plot an arrow 2 bars back when our signal triggers.
// Note that if you publish a script plotting in the past like this,// it is expected that you will explain this in your script's description
// so you do not mislead traders into thinking your script is prescient.
plotchar(signal,"signal","▲",location.top,size = size.tiny,offset = - 2)

enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...