更新条件变量
我想在每次验证条件时更新一个变量(在下面的示例中为 new_profit_long
)。
以下是我想要实现的目标的简化示例:
entry = nz(strategy.opentrades.entry_price(strategy.opentrades - 1))
profit = entry + tp
loss = entry - sl
extra = tp * .5
new_profit = profit
if close > profit
if close > new_profit
new_profit := new_profit + extra
else
strategy.close("long")
else if close < loss
strategy.close("long")
不幸的是,我得到了这种行为:
close | Entry | (old) new_profit | (new) new_profit | Notes |
---|---|---|---|---|
782.7 | 783.5 | 783.5 | 783.5 | Enter |
784.0 | 783.5 | 784.5 | new_profit changed | |
784.6 | 783.5 | 784.5 | new_profit 不改变:为什么? | |
781.4 | 783.5 | 783.5 | ||
776.9 | 783.5 | 783.5 | 退出 |
怎么了?
I would like to update a variable (in the below example is new_profit_long
) every time a condition is verified.
The following is a simplified example of what I want to achieve:
entry = nz(strategy.opentrades.entry_price(strategy.opentrades - 1))
profit = entry + tp
loss = entry - sl
extra = tp * .5
new_profit = profit
if close > profit
if close > new_profit
new_profit := new_profit + extra
else
strategy.close("long")
else if close < loss
strategy.close("long")
Unfortunately, I get this behaviour:
close | entry | (old) new_profit | (new) new_profit | notes |
---|---|---|---|---|
782.7 | 783.5 | 783.5 | 783.5 | enter |
784.0 | 783.5 | 784.5 | new_profit changed | |
784.6 | 783.5 | 784.5 | new_profit not changed: why? | |
781.4 | 783.5 | 783.5 | ||
776.9 | 783.5 | 783.5 | exit |
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我想出了这个解决方案:
Finally, I came up with this solution: