Page 1 of 1

Question: syntax for shorting

Posted: Mon Sep 04, 2023 4:55 pm
by Rocky
Hello. I wonder what is the syntax to open and close a short position?
For example, on SPY if the RSI drops below 20 (open) and if the RSI crosses above 80 (close).
For some reason, I can successfully code a long position and see open and close (on the chart) but I'm unable to do that for a short position.
Can you please help out?

Re: Question: syntax for shorting

Posted: Wed Sep 20, 2023 3:24 am
by Steve Burman
The syntax is similar to entering and closing a long position.

strategy.entry(id = "Short", direction = strategy.short, qty = 1)

strategy.exit(id = "Exit", from_entry = "Short", profit = 10, loss = 5)