Automating your trading process is a crucial step for traders looking to shift from manual chart analysis to fully operational trading algorithms. This guide explains how to convert an indicator into a strategy, backtest it, and prepare it for automation through AlgoWay webhooks.
Pine Script is the programming language used for creating indicators and strategies in TradingView.
Key components:
Indicators analyze markets, while strategies execute trades based on rules.
Open the indicator and identify the key signals. Determine which conditions imply buy and sell actions.
//@version=5
indicator("Example Indicator", overlay=true)
buySignal = close > open
sellSignal = close < open
plotshape(buySignal, style=shape.triangleup, color=color.green)
plotshape(sellSignal, style=shape.triangledown, color=color.red)
Replace indicator with strategy and add entry logic.
//@version=5
strategy("Example Strategy", overlay=true)
buySignal = close > open
sellSignal = close < open
if buySignal
strategy.entry("Buy", strategy.long)
if sellSignal
strategy.entry("Sell", strategy.short)
Include basic risk controls through stop and limit parameters or through your connector’s SL/TP fields.
//@version=5
strategy("Strategy with Risk", overlay=true)
buySignal = close > open
sellSignal = close < open
if buySignal
strategy.entry("Buy", strategy.long, stop=low - 10, limit=high + 20)
if sellSignal
strategy.entry("Sell", strategy.short, stop=high + 10, limit=low - 20)
Run backtests, evaluate the core metrics, and optimize your inputs to improve performance consistency.
Add alertcondition or alert() logic to enable notifications and automation triggers.
//@version=5
strategy("Strategy with Alerts", overlay=true)
buySignal = close > open
sellSignal = close < open
alertcondition(buySignal, title="Buy Alert", message="Buy Now!")
alertcondition(sellSignal, title="Sell Alert", message="Sell Now!")
if buySignal
strategy.entry("Buy", strategy.long)
if sellSignal
strategy.entry("Sell", strategy.short)
One strategy → many connectors and platforms. No manual JSON typing. Uses “Any alert() function call”.
alert().stop_loss and take_profit; other platforms use simplified JSON.buy/sell; exits send flat.metatrader5 tradelocker matchtrader dxtrade ctrader capitalcom bybit binance okx bitmex
SL/TP supported only for: metatrader5, tradelocker.
order_action: "flat" on exit conditions.//@version=6
strategy("Universal Connector", overlay = true)
// PROVIDER
provider = input.string("AlgoWay Connector", "Automation Provider", options = ["Off", "AlgoWay Connector", "SomeOther Connector"])
aw_enabled = provider == "AlgoWay Connector"
// PLATFORM
platform = input.string("metatrader5", "Trading Platform",
options = ["metatrader5","tradelocker","matchtrader","dxtrade","ctrader","capitalcom","bybit","binance","okx","bitmex"])
// JSON BUILDERS
algoway_entry_full(id, action, qty, sl, tp) =>
'{ "platform_name":"' + platform + '","ticker":"' + syminfo.ticker + '","order_id":"' + id + '","order_action":"' + action + '","order_contracts":"' + qty + '","stop_loss":"' + sl + '","take_profit":"' + tp + '" }'
algoway_exit_full(id, qty) =>
'{ "platform_name":"' + platform + '","ticker":"' + syminfo.ticker + '","order_id":"' + id + '","order_action":"flat","order_contracts":"' + qty + '" }'
algoway_entry_basic(id, action, qty, price) =>
'{ "platform_name":"' + platform + '","ticker":"' + syminfo.ticker + '","order_contracts":"' + qty + '","order_action":"' + action + '","price":"' + price + '" }'
algoway_exit_basic(id, qty) =>
'{ "platform_name":"' + platform + '","ticker":"' + syminfo.ticker + '","order_action":"flat","order_contracts":"' + qty + '" }'
// SL/TP supported only for MT5 and TradeLocker
supports_sl_tp = platform == "metatrader5" or platform == "tradelocker"
// DEMO STRATEGY (replace with your own logic)
longCond = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
shortCond = ta.crossunder(ta.ema(close, 9), ta.ema(close, 21))
// ENTRY
if longCond
strategy.entry("Long", strategy.long)
if aw_enabled
if supports_sl_tp
alert(algoway_entry_full("Long", "buy", "1", "50", "100"), freq = alert.freq_once_per_bar_close)
else
alert(algoway_entry_basic("Long", "buy", "1", str.tostring(close)), freq = alert.freq_once_per_bar_close)
if shortCond
strategy.entry("Short", strategy.short)
if aw_enabled
if supports_sl_tp
alert(algoway_entry_full("Short", "sell", "1", "50", "100"), freq = alert.freq_once_per_bar_close)
else
alert(algoway_entry_basic("Short", "sell", "1", str.tostring(close)), freq = alert.freq_once_per_bar_close)
// EXIT
if strategy.position_size > 0 and shortCond
strategy.close("Long")
if aw_enabled
if supports_sl_tp
alert(algoway_exit_full("Long", "1"), freq = alert.freq_once_per_bar_close)
else
alert(algoway_exit_basic("Long", "1"), freq = alert.freq_once_per_bar_close)
if strategy.position_size < 0 and longCond
strategy.close("Short")
if aw_enabled
if supports_sl_tp
alert(algoway_exit_full("Short", "1"), freq = alert.freq_once_per_bar_close)
else
alert(algoway_exit_basic("Short", "1"), freq = alert.freq_once_per_bar_close)
Once your indicator becomes a strategy, you can backtest it, add alerts, and connect it to automation through webhooks. The universal template above keeps routing to connectors and platforms simple and consistent.