Skip to content

Guide / Checked Nov 2026

How do I close or reverse a position with a TradingView alert?

To close, send CLOSE with the direction you hold, such as {"ticker": "SPY", "action": "CLOSE", "direction": "LONG"}. Nyria closes all of it. An exit that finds nothing open is logged Skipped and sends nothing. To reverse, set both sides to Enter position and send one alert that reports the flip. A TradingView Order fills only alert with prevMarketPosition long and marketPosition short closes the long, then opens the short.

Official documentation

Close and flip by alert

  1. 1

    Turn exits on

    On the strategy, set Close on exit alerts on for the side you hold. With it off, exit alerts for that side are ignored.

  2. 2

    Send CLOSE with the direction

    From your own code, POST action CLOSE and direction LONG or SHORT. If the entry is still working at the broker, the exit cancels it instead.

  3. 3

    Let a strategy() fill send it

    On a TradingView strategy() script, strategy.close or strategy.exit fires one Order fills only alert. Nyria reads it as an exit.

  4. 4

    Set both sides to Enter position

    To reverse, set Long behavior and Short behavior to Enter position. An alert that reports the flip closes the old side, then opens the new one.

  5. 5

    Keep the position fields

    The Order fills only message carries prevMarketPosition and marketPosition. Nyria reads long to short as a reversal. A plain SPY short entry reports no position.

  6. 6

    Space your alerts

    Alerts sent close together can race, and a sell can arrive before its buy. Flip with one reversing alert, or leave 30 to 60 seconds between them.

Messages to copy

Full close

{
  "ticker": "AAPL",
  "action": "CLOSE",
  "direction": "LONG"
}

Reversal, from a strategy() script

{
  "ticker": "{{ticker}}",
  "action": "{{strategy.order.action}}",
  "marketPosition": "{{strategy.market_position}}",
  "prevMarketPosition": "{{strategy.prev_market_position}}"
}

Exit, as plain text

Close SPY long

What an exit does

  • CLOSE closes the whole position. There is no partial-close field.
  • An exit that names only the ticker closes the most recent position on it, with every entry stacked onto it.
  • An exit with no tracked position is logged Skipped, not Failed, and sends nothing.
  • Nyria tracks the orders it placed. A position opened by hand at the broker isn't closed by an alert.
  • Nyria attaches no stop or target to an entry. Exits come from exit alerts.
  • On a strategy you own, Close positions in its menu closes each one as an exit alert would.

What a reversal does

  • A resting entry on the old side is canceled. A filled one is closed, sized from its fill.
  • If any bot still holds the old side after the close, no bot gets the new one.
  • A long-only strategy with Short set to Do nothing won't close a long on a short alert.
  • Market exits are the safer default for a fast flip. A limit exit can sit unfilled while price moves.

Questions

How do I close a position from a TradingView alert?
Send CLOSE with the direction you hold, or let strategy.close in your Pine script fire the Order fills only alert. Close on exit alerts must be on for that side.
How do I reverse a position with a TradingView webhook?
Set both sides to Enter position and send one Order fills only alert. prevMarketPosition long and marketPosition short tells Nyria to close the long and open the short.
Why was my exit skipped?
Nyria tracked no open position for that bot or strategy. Usually an earlier exit already closed it, or the entry never filled. Check the strategy's Logs tab for the matching entry.
Can an alert attach a stop loss to the entry?
No. Nyria places no bracket, OCO, OTO or trailing-stop order. Put the exit rule in your script and let its fill send the exit alert.
What does it cost?
Paper is free. Live trading from $15 a month.

Next

Try a paper bot first

No card required. Paper is free. Live trading from $15 a month.