ta.value当仅计算一次条件为true时(pinescript/tradingview)

发布于 2025-01-30 01:29:50 字数 526 浏览 3 评论 0原文

我正在尝试根据最低的脚步编写Stoploss和TakeProfit脚本。当条件“买入”为真时,脚本应将以前的最低点作为止动。问题在于脚本在整个“ buy = true”期间重新计算了最低和近距离的价格。我需要脚本在条件为真时计算此值,但仅在第一个栏中。

rr = input(1.5, title="RISK & REWARD")

buy = rsi > rsiMA and (Greenbar1 and Greenbar2 == 1) and (vfi > vfima and vfima > 0)
loweststop = ta.lowest(close, 10)
longstopl = ta.valuewhen(buy, loweststop, 1)
longprice = ta.valuewhen(buy, close, 1)
longtakep = ((longprice - longstopl) * rr) + longprice
longclose = high >= longtakep or low <= longstopl

I'm trying to write a StopLoss and TakeProfit script based on the lowest. When the condition "buy" is true the script should take the previous lowest as a StopLoss. The problem is that the script recalculate the lowest and the close price for the entire duration of "buy = true". I need the script calculate this value when condition is true, but only in the first bar.

rr = input(1.5, title="RISK & REWARD")

buy = rsi > rsiMA and (Greenbar1 and Greenbar2 == 1) and (vfi > vfima and vfima > 0)
loweststop = ta.lowest(close, 10)
longstopl = ta.valuewhen(buy, loweststop, 1)
longprice = ta.valuewhen(buy, close, 1)
longtakep = ((longprice - longstopl) * rr) + longprice
longclose = high >= longtakep or low <= longstopl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眉黛浅 2025-02-06 01:29:50

如果您只是第一次触发脚本,请使用 var boolean buy
如果您仅是在酒吧中的第一个刻度,请使用 varip boolean buy

If you mean only the first time the script is triggered, then use var boolean buy.
If you mean only for the first tick in a bar, then use varip boolean buy

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