策略:理解 strategy.exit() 和 strategy.close()。如何决定应该使用哪一个?

Strategy: Understanding strategy.exit() and strategy.close(). How to decide which one should be used?

在我找到并建立了我的理解的策略模板中,strategy.exit()strategy.close()都包含在strategy.entry()之后但是在手册中,只有一个,见下文:

Strategy.Exit

//@version=5
strategy(title = "simple strategy exit example")
strategy.entry("long", strategy.long, 1, when = open > high[1]) // enter long by market if current open great then previous high
strategy.exit("exit", "long", profit = 10, loss = 5) // generate full exit bracket (profit 10 points, loss 5 points per contract) from entry with name "long"

Strategy.Close

//@version=5
strategy("closeEntry Demo", overlay=false)
strategy.entry("buy", strategy.long, when = open > close)
strategy.close("buy", when = open < close, qty_percent = 50, comment = "close buy entry for 50%")
plot(strategy.position_size)

如何决定在特定情况下应该使用哪个?他们都应该使用吗?哪一个有什么用?

我可以看到 strategy.exit() 有更多参数需要指定。

strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, when, alert_message) → void

strategy.close(id, when, comment, qty, qty_percent, alert_message) → void

如果我没记错的话我可能更喜欢strategy.exit()…?

如果您想在价格达到计算值 (TP/SL) 时退出,请使用 strategy.exit()。实际上,您必须至少具有以下参数之一:profitlimitlossstop,否则会抛出错误。

要以市价平仓,请使用strategy.close()