更新条件变量

发布于 2025-01-10 18:14:35 字数 1128 浏览 1 评论 0原文

我想在每次验证条件时更新一个变量(在下面的示例中为 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")

不幸的是,我得到了这种行为:

closeEntry(old) new_profit(new) new_profitNotes
782.7783.5783.5783.5Enter
784.0783.5784.5new_profitchanged
784.6783.5784.5new_profit 不改变:为什么?
781.4783.5783.5
776.9783.5783.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:

closeentry(old) new_profit(new) new_profitnotes
782.7783.5783.5783.5enter
784.0783.5784.5new_profit changed
784.6783.5784.5new_profit not changed: why?
781.4783.5783.5
776.9783.5783.5exit

What's wrong?

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

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

发布评论

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

评论(1

请恋爱 2025-01-17 18:14:35

最后,我想出了这个解决方案:

entry = strategy.opentrades.entry_price(strategy.opentrades - 1)
profit = entry + tp
loss = entry - sl
extra = tp * .5

var float new_profit = na
var float old_profit = na

if not new_profit
    new_profit := profit

if close > profit
    if close > new_profit
        old_profit := new_profit
        new_profit := new_profit + extra
    else if close < old_profit
        strategy.close("long")
        new_profit := na
        old_profit := na
else if close < loss
    strategy.close("long")
    new_profit := na
    old_profit := na

Finally, I came up with this solution:

entry = strategy.opentrades.entry_price(strategy.opentrades - 1)
profit = entry + tp
loss = entry - sl
extra = tp * .5

var float new_profit = na
var float old_profit = na

if not new_profit
    new_profit := profit

if close > profit
    if close > new_profit
        old_profit := new_profit
        new_profit := new_profit + extra
    else if close < old_profit
        strategy.close("long")
        new_profit := na
        old_profit := na
else if close < loss
    strategy.close("long")
    new_profit := na
    old_profit := na
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文