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

Viewed 253

In a strategy template I found and established my understanding on, both strategy.exit() and strategy.close() are included after strategy.entry() but in the manual, there's only one of them, see below:

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)

How to decide which should be used in a certain case? Should they both be used? Which one is for what?

I can see that strategy.exit() has more arguments to be specified.

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

I may prefer strategy.exit() if I'm not wrong…?

1 Answers

Use strategy.exit() when you want to exit when the price reaches to a calculated value (TP/SL). In fact, you must have at least one of the following parameters: profit, limit, loss, stop or else it will throw an error.

To close the position at market price, use strategy.close().

Related