Mirror a TradingView strategy with setposition

Copy a TradingView strategy you can't edit to MT5 or cTrader. Send its position size with setposition so each fill keeps your broker account in sync.

Last updated: 2026-10-08

Many TradingView strategies are invite-only or protected. You can add one to a chart and create alerts from it, but you can't change its code or the messages it sends. setposition lets you automate these strategies anyway. Your alert reports the size of the strategy's whole position after every fill, and PineHook adjusts your broker account to match it.

If you can edit the strategy's code, Pine Script strategy alerts shows how to build each message yourself, which gives you more control.

When to use it#

TradingView's default order-fill alert tells you what the strategy just did, such as "sell 2 contracts". It doesn't tell you where that leaves the position, and turning those messages into separate buy and sell commands breaks down quickly:

  • A reversal arrives as one order for the combined size. When a 1-lot long flips to a 1-lot short, the strategy reports "sell 2", and a plain sell on a hedging account would open a 2-lot short beside the long instead of closing it.
  • Partial exits and added entries each need a different command, and the alert doesn't say which one applies.
  • If one alert goes missing, every later buy and sell starts from the wrong position. Your account then stays out of step with the strategy until you fix it by hand.

With setposition, every alert carries the strategy's full position, such as "short 1". PineHook compares that with what your account holds and trades only the difference. A missed alert corrects itself at the next fill, and a repeated alert does nothing once your position already matches.

Before you start#

  • A working PineHook license. Follow Set up webhook alerts first and confirm that a test alert reaches your account.
  • Your account type. Check with your broker whether your account uses hedging or netting. It changes how you write the alert below.
  • Lot conversion. TradingView reports a strategy's size in contracts or units, and your broker trades in lots. A forex strategy that shows 100000 for one standard lot needs a conversion factor of 0.00001. Set this up in lot size conversion before you go live.

Write the alert message#

Use this message on a netting or exchange account:

YOUR_LICENSE_KEY,setposition,{{ticker}},target={{strategy.position_size}}

TradingView replaces {{strategy.position_size}} with the strategy's position after each fill. The value is positive when the strategy is long, negative when it is short, and zero when it is flat. {{ticker}} becomes the chart's symbol. If your broker names the symbol differently, add a rule in broker symbol mapping.

On a hedging account, add a ticket so the target only manages this strategy's positions, even if you trade the same symbol in other ways:

YOUR_LICENSE_KEY,setposition,{{ticker}},target={{strategy.position_size}},ticket=my-strategy

The ticket stays with the strategy's positions after they go flat or reverse, so every alert from this strategy can reuse it. Give each strategy its own ticket. Netting and exchange accounts reject tickets, so leave it out there.

You can also add one stop loss and one take profit, such as sl_pips=50 or tp_pips=100. They apply to the whole position after each fill. This alert is the one case where you should leave out id=. Without one, PineHook never drops a target alert as a duplicate, and sending the same target twice does no harm. For every other kind of alert, we recommend adding a fresh id= each time it fires.

Create the alert#

  1. Add the strategy to your chart with the symbol, timeframe and inputs you want to trade.
  2. Select Create alert and choose the strategy as the condition.
  3. Choose Order fills only.
  4. Under Notifications, enable Webhook URL and enter https://relay.pinehook.io/webhook.
  5. Replace the default message with your setposition command, name the alert, and select Create.

TradingView only sends strategy alerts for fills on live bars, never for historical ones. If the strategy already holds a position when you create the alert, your account stays as it is until the strategy's next fill, which then brings it in line.

Recreate the alert after changing the strategy

TradingView saves a copy of the strategy and its inputs when you create the alert. If you change the inputs, symbol or timeframe, delete the alert and create a new one, or the old settings keep running.

What to expect#

Each fill sends one target. In Signal Logs, the row shows whether it finished as Complete, Partial, Blocked or Uncertain, together with the target and the size your account confirmed afterward.

A target is reached once and is not watched afterward. If your broker's stop loss closes the position while the strategy still holds it, PineHook leaves your account flat until the strategy's next fill sends a new target.

When the strategy reverses, PineHook closes the old direction first and then opens the new one. A check such as Active Hours or Allow Hedging can block the new side, which leaves you flat with a Partial result. Your position limits never shrink a target either. An opening that would go past them is refused instead.

If you copy the strategy to other accounts with a Trade Copier, each account scales the target by its own multiplier.

Test it on a demo account#

Run the alert on a demo account for a few fills. Compare the strategy's trade list in TradingView's Strategy Tester with the targets in Signal Logs and the positions at your broker. TradingView simulates its fills, so prices and timing at your broker can differ slightly, but the position size and direction should match after every fill.