Pine Script - 变量存储和更改

发布于 2025-01-17 15:47:58 字数 343 浏览 0 评论 0原文

很难将定义的信号转换为变量,我可以从中计算出多少条条件,因为上次符合条件使信号成真。

例如,如果我有: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千鲤 2025-01-24 15:47:58

您可以使用 ta.barssince() 函数来计算自上次条件成立以来的柱数。

since_longsignal = ta.barssince(longsignal)

您还可以使用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.

since_longsignal = ta.barssince(longsignal)

You can also use ta.crossover(close, sma50). It will only be true if the price comes below sma50 and closes over sma50.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文