PINE SCRIPT · UPDATED OCTOBER 2026

Pine Script tutorial: from your first script to MT5 orders.

Pine Script is TradingView’s language for indicators and strategies. This tutorial walks the whole path: your first indicator, converting it into a strategy, testing it honestly, firing alerts — and then copying those alerts into MetaTrader 5 so the strategy trades without you at the keyboard.

BBenjamin SF · Founder Published Oct 26, 2026 Read 9 min

What Pine Script is.

TRADINGVIEW’S LANGUAGE, IN THE CLOUD

Pine Script runs on TradingView’s servers: you write it in the Pine Editor, press compile, and the script draws on the chart or simulates trades. Two script types matter for automation. An indicator only draws or calculates. A strategy declares entries and exits, so TradingView can backtest them bar by bar and fire alerts when the conditions trigger live.

For automation, the strategy is the one you want: its alerts are the bridge between what you designed and what your broker executes.

Step 1: your first indicator.

TEN LINES, ONE LINE ON THE CHART

Open the Pine Editor at the bottom of any chart, paste this and press compile:

//@version=6
indicator("SMA 50", overlay=true)
plot(ta.sma(close, 50))

Three lines: declare the script, give it a name, draw the 50-period simple moving average over the price. From here, everything you will ever build is this same shape: inputs, a calculation, and something to show or to trade.

Step 2: from indicator to strategy.

DECLARING ENTRIES SO TRADINGVIEW CAN TEST THEM

Change the declaration to strategy() and add a rule that opens a position. A minimal crossover example:

//@version=6
strategy("SMA cross", overlay=true)
fast = ta.sma(close, 50)
slow = ta.sma(close, 200)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.close("Long")

Now the Strategy Tester tab fills with trades: every crossover bought, every crossunder closed. That tester is where you add costs and find out the strategy is not as good as it looked on the chart — which is the point.

Step 3: test it honestly.

COSTS, DEPTH AND THE REPAINTING TRAP

Three things turn a pretty backtest into an honest one. Commission and slippage in the strategy properties — without them every result is fiction. Enough history — a few months proves nothing. And the repainting trap: a script repaints when its past values change after the fact because it used information that did not exist at that bar’s close. A repainting strategy looks brilliant in the tester and dies live. Test the same logic with bar replay, and verify the signals on a demo before real money.

Step 4: fire alerts.

THE STRATEGY SPEAKS JSON

Once the strategy behaves, add alert messages: TradingView can send the order as JSON every time an entry or exit triggers. A webhook alert with a body like this is all a bridge needs:

{
  "symbol": "{{ticker}}",
  "action": "{{strategy.order.action}}",
  "lot": 0.1
}

The placeholders fill in the symbol and the direction automatically. One alert now covers every chart the strategy runs on.

Step 5: the alerts become MT5 orders.

THE BRIDGE CLOSES THE LOOP

Pine cannot reach your broker: it lives inside TradingView. The last hop is a bridge — a webhook receiver plus an EA inside your MetaTrader 5 that executes each alert on your account. With SignalForge the setup is four steps (register the account, install the EA, paste the webhook URL, test on demo) and the median time from alert to confirmed order in our 19-23 September 2026 measurements was about 0.5 s. The full walkthrough: how to copy TradingView signals into MT5.

If writing the strategy itself is the part you would rather skip, the Script Builder turns plain-language rules into Pine and our AI Pine script generator guide covers that route in depth; converting an existing script into a tradeable one is covered in Pine Script to EA.

FAQ

Quick questions.

Email support@signalforge-ai.com if yours isn’t here.

Is Pine Script hard to learn?

+
For a trader who already understands indicators and entries, the basics take an afternoon: an indicator is a few lines, and a strategy adds entry and exit calls. The hard part is not the language, it is building a rule that survives costs and drawdown.

What version of Pine Script should I use?

+
Write new scripts in the current version (v6) and let TradingView convert old v4/v5 scripts. Each major version changes parts of the built-in function names, so mixing versions in one script fails to compile.

Can Pine Script place orders in my broker?

+
Not directly. Pine runs inside TradingView: what it can do is fire alerts. To turn those alerts into orders you need execution on the broker side, for example a bridge that copies each alert into your MT5 account as an order.

What is repainting in Pine Script?

+
A script repaints when its past values change after the fact, because it used data that was not available at that bar's close. A repainting strategy looks brilliant in the Strategy Tester and fails live. Test with bar replay and verify the signals on a demo before risking money.

Do I need to learn Pine to automate a TradingView strategy?

+
No. If your logic is already an indicator, a no-code route exists: an AI Pine generator or a script builder turns plain-language rules into a strategy, and an alert bridge executes it in MT5. Learning Pine still helps you read and fix what the generator produces.
B
Benjamin SF · Founder of SignalForge
TRADER · ALICANTE

Benjamin SF is the founder of SignalForge and an expert in trading algorithm automation. He builds and operates the SignalForge bridge and the SFCloud hosted-MT5 fleet for prop-firm traders.

From Pine alerts to MT5 orders

SignalForge executes your TradingView strategy on MetaTrader 5 in milliseconds. 14-day free trial, no card required.

SignalForge AI is an order-execution tool. We do not provide investment advice. Trading involves risk of loss.

Your Pine strategy, trading on MT5 automatically — from $4.99/moStart free →