Main clusters and core pages.
To automate a TradingView indicator, you usually need to turn its signal logic into a Pine Script strategy or build indicator alerts that send valid JSON to AlgoWay. A normal indicator can show buy and sell marks on the chart, but a strategy can simulate entries and exits, run inside TradingView Strategy Tester, and generate structured webhook messages for automated execution.
This guide is written for traders searching for turn TradingView indicator into strategy, convert indicator to strategy Pine Script, TradingView strategy webhook, Pine Script strategy.entry, TradingView alert() JSON, Any alert() function call, TradingView indicator automation, and AlgoWay webhook automation.
The practical route is:
TradingView indicator logic → Pine Script strategy → backtest → alert() JSON → AlgoWay webhook → broker or exchange execution
This page focuses on safe conversion, not magic profitability. A converted strategy still needs testing, realistic costs, clean exits, symbol mapping, risk limits and small-size forward testing before live automation.
Last updated: 2026-05-12 • Author: AlgoWay
Many TradingView users start with an indicator because it is easier to read visually: arrows, labels, colored trend lines, buy signals, sell signals, support zones or oscillator crosses. That is useful for manual trading, but it is not enough for reliable webhook automation. A webhook trading bot needs a precise event: when to enter, when to close, when to reverse, what size to use, what symbol to send, and what JSON should be delivered to the automation platform.
That is why the phrase convert TradingView indicator to strategy is one of the most important steps in Pine Script automation. The conversion turns visual chart logic into testable trading rules. Once the logic becomes a strategy, you can use TradingView Strategy Tester, inspect historical entries and exits, compare long and short behavior, and then connect the final alert flow to AlgoWay for webhook execution.
In practice, this conversion is useful for traders who already have an indicator that marks entries but need a complete route for TradingView webhook automation, TradingView to MT5 execution, TradingView to TradeLocker automation, TradingView to DxTrade routing, crypto exchange webhook alerts, or a broader webhook autotrade bot workflow.
Before rewriting code, choose the correct automation path. Not every indicator must become a full strategy. The right method depends on whether you have access to the source code, whether you need backtesting, and whether the indicator already exposes alert conditions.
| Automation path | Best use case | AlgoWay result |
|---|---|---|
| Use indicator alerts directly | The indicator already has clean Long, Short and Exit alert conditions. | Each TradingView alert sends a fixed JSON command to the AlgoWay webhook URL. |
| Convert indicator into strategy | You have source code and want backtesting, entries, exits and Strategy Tester metrics. | The Pine Script strategy sends buy, sell and flat JSON through alert(). |
| Use an adapter script | The indicator is invite-only or closed-source, but it exposes plotted values or source outputs. | An adapter reads the output and turns it into structured AlgoWay alert messages. |
For open-source Pine Script indicators, conversion gives the most control. For invite-only indicators, a direct rewrite may be impossible. In that case, the practical SEO and automation answer is to use indicator alerts or an adapter that can read exposed outputs and produce a clean JSON message.
To turn a TradingView indicator into a strategy:
indicator() with strategy().strategy.entry() for long and short entries.strategy.exit() or strategy.close() for exits.alert() calls that build AlgoWay JSON.Basic idea:
// Indicator signal:
buySignal = close > open
// Strategy action:
if buySignal
strategy.entry("Long", strategy.long)
Indicators and strategies can use similar Pine Script logic, but they have different purposes.
| Script type | Main purpose | Automation use |
|---|---|---|
| Indicator | Analyzes data, plots signals, levels, shapes or alerts. | Can send indicator alerts, but does not create Strategy Tester trades. |
| Strategy | Simulates entries, exits and order behavior on historical and realtime bars. | Can backtest logic and send structured alert messages for automation. |
If you only need a simple alert when a plotted condition appears, an indicator alert may be enough. If you need backtesting, position state, strategy orders, entries, exits and performance metrics, convert the logic into a strategy.
A clean conversion is not just replacing one function name. Use this structure:
indicator() with strategy().strategy.entry().alert() or strategy alert messages.The conversion quality depends on how accurately you identify the real signal logic. A common mistake is to copy the visible shape but miss the condition behind it. The signal is not the triangle, label or colored candle. The signal is the boolean rule that caused that visual object to appear.
When reading the indicator code, look for these parts:
This is where many converted TradingView strategies fail. The user sees a clean historical chart, but the Pine Script logic may have used realtime values, future-looking references or intrabar behavior that does not survive live automation. For AlgoWay webhook automation, the best setup is usually a bar-close signal with clear state control, because it reduces duplicate alerts and makes TradingView logs easier to compare with AlgoWay Webhook Logs.
If the indicator source code is open, conversion is straightforward: copy the logic, replace indicator() with strategy(), map signals to orders, add exits, and build AlgoWay JSON. If the indicator is protected or invite-only, you cannot simply read the internal rules. That does not mean automation is impossible, but it changes the method.
For closed-source indicators, the realistic options are:
This distinction is important for search users who type convert invite-only TradingView indicator to strategy. If the source code is locked, an exact conversion is not possible from the hidden code alone. What you can automate is the alert output or exposed signal state. AlgoWay can still receive the final TradingView alert, but the technical setup must be honest about what is being converted.
Start with the indicator code and find the conditions that create visual buy and sell signals. These are often variables such as buySignal, sellSignal, longCondition or shortCondition.
//@version=6
indicator("Example Indicator", overlay = true)
buySignal = close > open
sellSignal = close < open
plotshape(buySignal, title = "Buy", style = shape.triangleup, color = color.green)
plotshape(sellSignal, title = "Sell", style = shape.triangledown, color = color.red)
In this example:
buySignal is the long entry condition;sellSignal is the short entry or exit condition;plotshape() only draws signals and does not trade.Now replace the indicator declaration with strategy() and add strategy entries.
//@version=6
strategy("Example Strategy", overlay = true)
buySignal = close > open
sellSignal = close < open
if buySignal
strategy.entry("Long", strategy.long)
if sellSignal
strategy.entry("Short", strategy.short)
This creates a basic strategy. It can now appear in TradingView Strategy Tester, but it is still too simple for real automation. It needs exits, costs, sizing and alert messages.
Do not rely on entries alone. A strategy needs a clear exit rule. You can close on the opposite signal, use strategy.exit() for stop loss and take profit, or combine both.
//@version=6
strategy("Example Strategy with Close Logic", overlay = true)
buySignal = close > open
sellSignal = close < open
if buySignal
strategy.close("Short")
strategy.entry("Long", strategy.long)
if sellSignal
strategy.close("Long")
strategy.entry("Short", strategy.short)
//@version=6
strategy("Example Strategy with Stop and Target", overlay = true)
buySignal = close > open
sellSignal = close < open
longStop = close - 100 * syminfo.mintick
longLimit = close + 200 * syminfo.mintick
shortStop = close + 100 * syminfo.mintick
shortLimit = close - 200 * syminfo.mintick
if buySignal
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", from_entry = "Long", stop = longStop, limit = longLimit)
if sellSignal
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", from_entry = "Short", stop = shortStop, limit = shortLimit)
stop/limit parameters with protective Stop Loss and Take Profit. For protective exits, use strategy.exit() with stop, limit, loss or profit.
After conversion, run the strategy in TradingView Strategy Tester.
Check:
Backtesting is only the first filter. After that, use forward testing and compare real webhook behavior with AlgoWay logs and broker execution.
Full guide: How to backtest TradingView strategies and track live results with AlgoWay.
A backtest is not the same as live webhook trading. TradingView Strategy Tester calculates simulated results on chart data. Live execution through a webhook adds alert timing, internet delivery, AlgoWay validation, platform routing, broker rules, exchange rules, spread, slippage, rejected orders and account permissions.
For that reason, a converted indicator should pass three stages before normal live size:
This workflow helps separate Pine Script problems from webhook problems. If TradingView does not fire the alert, the problem is inside the alert condition or script. If AlgoWay receives invalid JSON, the problem is the message builder. If AlgoWay receives valid JSON but the destination rejects the order, the issue is usually symbol mapping, size, margin, order type, market session or platform permissions.
When converting indicators into strategies, bar timing matters. A signal that looks perfect on historical bars may behave differently in realtime if it updates before the candle closes. For webhook automation, this can create duplicate alerts, early entries, late exits or signals that disappear from the chart after the trade has already been sent.
Use once per bar close style logic when the strategy does not require intrabar execution. In Pine Script, combine confirmed-bar logic, position checks and alert frequency so that one trading event creates one webhook message. This is especially important when the AlgoWay route sends orders to MT5, TradeLocker, DxTrade, cTrader, Binance, Bybit, OKX or another destination where duplicate signals can create real exposure.
To automate execution, the strategy must send valid JSON to AlgoWay. You can build JSON directly in Pine Script and send it with alert().
The JSON message is the bridge between Pine Script and execution. A converted TradingView strategy should not send vague text such as “buy now” or “sell signal”. It should send a structured webhook command that AlgoWay can validate and route.
The core fields usually are:
platform_name — the destination route type, such as metatrader5, tradelocker, dxtrade, ctrader, binance, bybit or okx.ticker — the TradingView symbol or a mapped symbol accepted by the broker or exchange.order_action — the intended action: buy, sell or flat.order_contracts — the order size or quantity.order_id — optional identifier used to separate strategy legs or different entries on the same symbol.price — optional chart price for logging and comparison.stop_loss, take_profit, sl_price, tp_price or trailing_pips — risk-management fields when the destination route supports them.This structure lets AlgoWay act as more than a raw text receiver. The platform can treat the TradingView strategy alert as a proper automation command and route it through the configured connector.
//@version=6
strategy("Example Strategy with AlgoWay Alerts", overlay = true)
platform = input.string("metatrader5", "AlgoWay Platform")
qty = input.string("0.01", "Order Size")
buySignal = close > open
sellSignal = close < open
makeEntryJson(action) =>
'{' +
'"platform_name":"' + platform + '",' +
'"ticker":"' + syminfo.ticker + '",' +
'"order_contracts":"' + qty + '",' +
'"order_action":"' + action + '",' +
'"price":"' + str.tostring(close) + '"' +
'}'
makeFlatJson() =>
'{' +
'"platform_name":"' + platform + '",' +
'"ticker":"' + syminfo.ticker + '",' +
'"order_action":"flat",' +
'"order_contracts":"' + qty + '"' +
'}'
if buySignal
strategy.close("Short")
strategy.entry("Long", strategy.long)
alert(makeEntryJson("buy"), freq = alert.freq_once_per_bar_close)
if sellSignal
strategy.close("Long")
strategy.entry("Short", strategy.short)
alert(makeEntryJson("sell"), freq = alert.freq_once_per_bar_close)
When using alert(), create the TradingView alert with:
Condition: Any alert() function call
The alert message field can stay empty because the Pine Script code generates the JSON.
This template keeps the routing logic separate from the strategy logic. Replace the demo EMA signals with your own indicator conditions after conversion.
alert();platform_name;buy, sell and flat actions;//@version=6
strategy("AlgoWay Universal Connector Template", overlay = true, pyramiding = 0)
// Automation settings
provider = input.string("AlgoWay", "Automation Provider", options = ["Off", "AlgoWay"])
enabled = provider == "AlgoWay"
platform = input.string("metatrader5", "AlgoWay Platform",
options = ["metatrader5", "tradelocker", "matchtrader", "dxtrade", "ctrader", "capitalcom", "bybit", "binance", "okx", "bitmex", "coinbase", "projectx", "tradovate", "alpaca"])
qty = input.string("1", "Order Size")
// Optional SL/TP fields for routes that support them
useStops = input.bool(false, "Send SL/TP Fields")
slValue = input.string("100", "Stop Loss")
tpValue = input.string("200", "Take Profit")
// Replace this demo logic with your converted indicator logic
fastEma = ta.ema(close, 9)
slowEma = ta.ema(close, 21)
longCond = ta.crossover(fastEma, slowEma)
shortCond = ta.crossunder(fastEma, slowEma)
// JSON builders
entryJson(id, action) =>
base = '{' +
'"platform_name":"' + platform + '",' +
'"ticker":"' + syminfo.ticker + '",' +
'"order_id":"' + id + '",' +
'"order_action":"' + action + '",' +
'"order_contracts":"' + qty + '",' +
'"price":"' + str.tostring(close) + '"'
useStops ? base + ',"stop_loss":"' + slValue + '","take_profit":"' + tpValue + '"}' : base + '}'
flatJson(id) =>
'{' +
'"platform_name":"' + platform + '",' +
'"ticker":"' + syminfo.ticker + '",' +
'"order_id":"' + id + '",' +
'"order_action":"flat",' +
'"order_contracts":"' + qty + '"' +
'}'
// Entry and exit logic
if longCond
strategy.close("Short")
if enabled
alert(flatJson("Short"), freq = alert.freq_once_per_bar_close)
strategy.entry("Long", strategy.long)
if enabled
alert(entryJson("Long", "buy"), freq = alert.freq_once_per_bar_close)
if shortCond
strategy.close("Long")
if enabled
alert(flatJson("Long"), freq = alert.freq_once_per_bar_close)
strategy.entry("Short", strategy.short)
if enabled
alert(entryJson("Short", "sell"), freq = alert.freq_once_per_bar_close)
alert(), or manually paste JSON into the TradingView alert message field. Do not mix both methods in the same alert.
After adding the strategy to the chart:
alert() JSON.AlgoWay webhook URL format:
https://algoway.co/your-webhook-uuid
General setup guide: How to create a TradingView webhook alert.
There are two common ways to send automation messages from TradingView:
| Method | How it works | When to use |
|---|---|---|
| Manual alert message | You paste JSON into the TradingView alert message field. | Simple strategy alerts or fixed payloads. |
alert() function |
Pine Script builds and sends the JSON message itself. | Dynamic platform, size, SL/TP, action and order_id logic. |
For converted indicators, alert() is often cleaner because the script can send different JSON on long, short and flat conditions.
The same converted strategy can be reused across several AlgoWay destinations if the JSON fields and platform settings are correct. The Pine Script does not need to know the full API details of every broker or exchange. It only needs to send a clear AlgoWay command.
Common routing examples include:
This is the main SEO and product reason to use AlgoWay after converting an indicator into a strategy: the Pine Script strategy creates the signal, while AlgoWay handles the routing layer between TradingView and the final execution platform.
Conversion is not always the best answer. If the indicator already provides stable alert conditions and you do not need Strategy Tester metrics, fixed TradingView alert messages may be simpler. If the indicator is closed-source, exact conversion is usually not possible. If the signal repaints heavily, converting it into a strategy may only expose the weakness of the signal.
Do not convert only because the chart looks good. Convert when you can define objective long, short and exit rules. A proper TradingView strategy for webhook automation needs clear conditions, controlled frequency, valid JSON, and a testable connection from TradingView to AlgoWay logs and from AlgoWay to the broker or exchange.
plotshape(), plot() and labels are visual. They do not create trades. You must map the signal condition to strategy.entry() or alert().
Check whether buy and sell conditions can both trigger too frequently. Add filters, bar-close logic or position checks.
TradingView backtests are simulations. Live webhook routing adds alert timing, spread, slippage, broker rules and platform rejection risks.
Use double quotes in JSON. Do not build broken strings in Pine. If AlgoWay rejects the payload, check commas, braces, quotes and field names. Read: How to fix AlgoWay webhook Error 415.
syminfo.ticker or {{ticker}} may not match the broker or exchange symbol. Check symbol mapping.
If the original indicator repaints, the converted strategy can give misleading backtests and unstable live alerts. Test on closed bars and avoid future-looking logic.
If you choose Any alert() function call, your Pine script must call alert(). Otherwise TradingView has nothing to send.
Use one approach. If the script sends JSON with alert(), do not also paste another unrelated JSON message into the alert box.
Before live trading:
alert();Yes, if the indicator has usable alert conditions. You can create TradingView alerts from those conditions and send AlgoWay JSON directly. Conversion is needed when you want Strategy Tester results, strategy entries, exits, position state or dynamic Pine Script JSON.
No. Conversion only creates a testable strategy. Before live automation, you still need realistic backtesting, forward testing, valid webhook JSON, symbol mapping, order size checks, risk fields, AlgoWay logs and destination platform confirmation.
If your Pine Script sends JSON through alert(), use Any alert() function call. If you use strategy order messages with alert_message, create an order-fill alert and use the correct TradingView placeholder.
Yes, if the script calculates those values and the selected AlgoWay route supports them. The JSON can include distance-style fields such as stop_loss and take_profit, or exact price fields such as sl_price and tp_price.
The usual causes are intrabar recalculation, duplicated alert methods, missing position checks, repainting logic, or an alert frequency that does not match the strategy design. Start with bar-close logic and one alert method.
Yes. MetaTrader 5 is a common destination, but AlgoWay can also route compatible webhook commands to platforms such as TradeLocker, DxTrade, cTrader, Tradovate, ProjectX, Binance, Bybit, OKX and other supported destinations.
Turning a TradingView indicator into a strategy means converting visual signal logic into executable strategy rules. First identify the indicator's long and short conditions. Then add strategy.entry(), exits, risk assumptions, backtesting and alert JSON.
For AlgoWay automation, the cleanest advanced workflow is to build JSON inside Pine Script with alert(), create a TradingView alert using Any alert() function call, paste the AlgoWay webhook URL, and verify the payload in AlgoWay Webhook Logs before live trading.