Rocky
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: August 19th, 2023

Question: syntax for shorting

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?

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Question: syntax for shorting

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)

Return to “Pine Script Q&A”