Pine Script - 变量存储和更改
很难将定义的信号转换为变量,我可以从中计算出多少条条件,因为上次符合条件使信号成真。
例如,如果我有: longSignal = Close> ta.sma(50,关闭)
,假设我退出了交易,但想等到关闭后,才落在SMA50以下,然后再次进入。因此,我需要存储上次登录时,当Close最近距离SMA50以下时,我可以为“ longsignal”添加其他条件,以说也必须说,确定为'Close&lt的交叉; SMA50'比最近的“ longsignal”更发生了。此外,我需要一个开始论点来使事情运转,因为第一个交易将没有“长信号”来参考
我尝试为每个交易创建var,但我的所有论点似乎都无法完成
Having trouble converting a defined signal into variable from which i can use to count how many bars since the last time conditions were meet making the signal true.
For instance if i have:longsignal = close > ta.sma(50, close)
and assume i got out of the trade but want to wait until close falls below the SMA50 before going in again. So i need to store when longsignal was last met and also when close most recently went below SMA50 so I can add an additional condition to 'longsignal' to say that it must also be true that a crossover defined as 'close < SMA50' occurred in time more recently than the most recent 'longsignal'. Additionally i need a starting argument to get things going since the first trade will have no 'long signal' to reference
i tried creating var for each but all my arguments seem to fail to be complete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
ta.barssince()
函数来计算自上次条件成立以来的柱数。您还可以使用
ta.crossover(close, sma50)
。仅当价格低于 50 移动平均线且收盘高于 50 移动移动平均线时,该情况才会成立。You can use
ta.barssince()
function to count the number of bars since the last time the condition was true.You can also use
ta.crossover(close, sma50)
. It will only be true if the price comes below sma50 and closes over sma50.