ta.value当仅计算一次条件为true时(pinescript/tradingview)
我正在尝试根据最低的脚步编写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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是第一次触发脚本,请使用 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