Skip to main content

Connecting Your TradingView Strategy

You can automate a TradingView Strategy script with AlgoTest Signals. Entry and exit signals come from TradingView, and AlgoTest executes the matching strategy with your broker.

What is a TradingView Strategy?​

In PineScript, a script is either an indicator or a strategy, set by its first line:

IndicatorStrategy
Declared withindicator(...)strategy(...)
What it doesPlots values on the chartPlaces simulated buy and sell orders
Order functionsNonestrategy.entry(), strategy.exit(), strategy.close()
Appears inThe chart onlyThe Strategy Tester tab, with backtest results

If your script declares strategy(...) and shows up under Strategy Tester, this is the page for you. If it declares indicator(...), use Connecting Your TradingView Indicator instead.

Why connect a Strategy rather than an Indicator​

One alert instead of six. An Indicator needs a separate alert for each event - long entry, long target, long stop loss, short entry, and so on. A Strategy needs one alert for everything, because the routing lives inside the script.

Entries and exits in one place. A Strategy script already defines when to get out, so you don't build exit conditions separately.

A backtest before you connect. Strategy scripts run in TradingView's Strategy Tester, so you can review historical results first.

Before you start​

  • A TradingView Essential plan or higher - webhook alerts aren't available on the free tier. See Why You Need a TradingView Essential Plan.
  • A Strategy script on a chart, showing results in the Strategy Tester.
  • An active Signal Plan on AlgoTest.

Two limits worth knowing before you build:

  • One signal can drive up to four AlgoTest strategies.
  • All of them must be on the same index. You can't combine a NIFTY strategy and a BANKNIFTY strategy under one signal.

Step 1) Put your strategy on a TradingView chart​

Open the chart and timeframe you want to trade.

Open the Pine Editor, choose Open → New strategy, clear the template, and paste in your script. Click Save, then Add to chart.

Confirm it appears under the Strategy Tester tab at the bottom of the chart.

Step 2) Backtest it on TradingView​

Hover the strategy name on the chart and click the Settings gear to see its inputs. Change them and the Strategy Tester results update immediately. The Properties tab shows the period being tested.

Step 3) Create the signal on AlgoTest​

Go to Signals → Create Signal. Choose TradingView Strategy as the source (not TradingView Indicator), and pick your execution type:

  • Forward Test - simulated, no real money.
  • Live Deployment - real orders through your broker.

Step 4) Create the strategy for long signals​

This is the trade AlgoTest executes when your script opens a long.

Create a new strategy. To trade futures, open Advanced strategy creation, then set the index, entry and exit times, and the underlying. In the Leg Builder, add your leg - for example 1 lot, Futures, Buy.

Save it with a name that identifies the direction, such as volume future buy.

Step 5) Create the strategy for short signals​

Repeat Step 4 with the opposite leg - for example 1 lot, Futures, Sell - on the same index.

Save it as something like volume future sell.

Step 6) Paste the snippets into your PineScript​

You'll now see Add AlgoTest Strategies to PineScript (Pine Editor), with one tab per strategy you created. Each tab holds two snippets that look like this:

,comment='entry', alert_message='682da1ea0d5cef30a7b4d583'
,comment='exit', alert_message='682da1ea0d5cef30a7b4d583'

For each tab:

  1. Click Copy next to the entry snippet, then paste it inside that strategy's matching strategy.entry() call in the Pine Editor.
  2. Click Copy next to the exit snippet, then paste it inside the matching strategy.exit() or strategy.close() call.

Once you click Copy, an I have pasted button appears - click it to confirm and move on.

Switch to the next tab and repeat, so long orders carry the long strategy's snippets and short orders carry the short strategy's.

Click Save in the Pine Editor when all snippets are in.

Your script's layout will differ

In your own script the entry and exit calls may sit in different places. If you're unsure which call is which, ask in the TradingView Signals Telegram group.

Step 7) Name the alert and copy the JSON​

Back on AlgoTest, give the alert a name and Save. AlgoTest generates a JSON block that looks like this:

{
"access_token": "YOUR_ACCESS_TOKEN",
"alert_type": "{{strategy.order.comment}}",
"alert_name": "YOUR_ALERT_NAME",
"strategy_id": "{{strategy.order.alert_message}}"
}

Copy it exactly as AlgoTest generates it.

Keep your access token private

The access_token in your JSON is tied to your account. Don't share it or post it in screenshots or support messages.

Step 8) Create one alert on TradingView​

On your chart, click Add alert, then:

  1. Condition - select your strategy by name.

  2. Alert name - anything you like.

  3. Message - delete what's there and paste the JSON from Step 7.

  4. Notifications → Webhook URL - paste:

    https://api.algotest.in/webhook/tradingview/execution/strategy

    This URL is the same for everyone; your access_token in the JSON identifies your account.

Click Save. That's the only alert you need.

Step 9) Start listening​

Back on AlgoTest, click Start Listening. Your strategies show as listening, and AlgoTest executes them as signals arrive from TradingView.

How the routing works​

Two values in the snippets you pasted do all the work:

ValueWhat it is
commentEither entry or exit - tells AlgoTest whether to open or close
alert_messageThe strategy ID of the AlgoTest strategy to execute

Your alert's JSON reads both from whichever order fired, using TradingView's {{strategy.order.comment}} and {{strategy.order.alert_message}} placeholders. Nothing in the alert is fixed to a single strategy, which is why one alert can serve all of them.

Each AlgoTest strategy has its own strategy ID, so a script trading both directions ends up with four snippets in total:

Paste intocommentalert_message
strategy.entry() in your long conditionentryLong strategy ID
strategy.close() / strategy.exit() for your long exitexitLong strategy ID
strategy.entry() in your short conditionentryShort strategy ID
strategy.close() / strategy.exit() for your short exitexitShort strategy ID

When your script fires a long entry, TradingView sends comment=entry with the long strategy's ID, and AlgoTest enters that strategy. The same alert carries a short exit when the short side closes.

FAQ​

Do I need a different TradingView plan for Strategy alerts?​

No - the TradingView Essential plan requirement is the same as for Indicators. See Why You Need a TradingView Essential Plan.

Why do I need two strategies for a long/short script?​

Long and short use different legs - one buys, one sells. Each is a separate AlgoTest strategy with its own strategy ID, and the ID you paste into each order call decides which one fires.

Can I connect strategies on different indexes to one signal?​

No. Only strategies on the same index can be selected together.

How many strategies can one signal drive?​

Up to four.

Can I trade options instead of futures?​

Yes. The signal flow is identical - build the AlgoTest strategy with option legs instead of a futures leg.

For more insights, visit AlgoTest Signals.