TradingView PineScript for CFD Traders
Build your own indicators, alerts, and backtestable strategies — Pine v5 from zero to a complete trend-following system.
About this course
TradingView ships hundreds of indicators, but the ones that fit your strategy usually do not exist yet. PineScript is TradingView's purpose-built scripting language, and it is the fastest way to turn a trading idea into something you can see on the chart and test against history. This course takes you from opening the Pine Editor for the first time to writing a complete, alertable, multi-timeframe trend-following system tuned for CFD execution realities — leverage, swaps, and contract sizing included.
What you'll be able to do
- Write and debug PineScript v5 indicators and strategies from scratch
- Read a Pine backtest report and know which numbers actually matter
- Encode position sizing and risk rules directly in your strategy
- Build a multi-timeframe system with proper alert wiring
Prerequisites
- A free TradingView account (paid tier unlocks more alerts but is not required)
- Familiarity with basic chart reading — candles, support/resistance, indicators
- No prior coding experience needed for Part 1
Learning path
4 parts · 17 lessons · every lesson ships with a complete TradingView program you can paste in and run.
Part 1PineScript Foundations
Open the Pine Editor, learn the data model, and plot your first indicator.
5 done
PineScript Foundations
Open the Pine Editor, learn the data model, and plot your first indicator.
- 01Beginner5 min
What is PineScript? The Pine Editor explained
PineScript is TradingView's purpose-built language for custom indicators and strategies. Here is what it is, what it isn't, and how to open the editor.
- 02Beginner6 min
Series, types, and the basic data flow
Every Pine variable is implicitly a time series. Understanding this is what makes Pine feel strange to anyone coming from general-purpose languages.
- 03Beginner5 min
Variables, operators, and comments
Variables, arithmetic, comparisons, logical operators, and how to leave notes for your future self.
- 04Beginner8 min
Your first indicator: plotting a moving average
A complete walkthrough: write, save, add to chart, and tune a simple moving average from scratch.
- 05Beginner7 min
Inputs and parameters: making indicators reusable
Inputs let you expose tunables to whoever uses your script. Pick the right input type and Pine will give you a useful settings UI.
Part 2Logic and Reuse
Conditionals, loops, functions, and arrays — the structures that let you write logic, not just plot lines.
4 done
Logic and Reuse
Conditionals, loops, functions, and arrays — the structures that let you write logic, not just plot lines.
- 01Intermediate7 min
Conditional logic: if/else for trade signals
if/else blocks, switch expressions, and how to use them to encode trade rules without spaghetti.
- 02Intermediate8 min
Loops: for and while
Pine's loops are different from what you may know — bounded for, single-pass semantics, and the cap on iterations.
- 03Intermediate9 min
Functions: writing reusable blocks
Functions in Pine take series and return series. They are how you stop copy-pasting the same code into every script.
- 04Intermediate10 min
Arrays and matrices: working with multiple series
Pine arrays are fixed at runtime. Matrices are 2D. Both are how you do work Pine's vector model can't express directly.
Part 3Strategy Development
From study to strategy: entries, exits, position sizing, and how to read the backtest report.
4 done
Strategy Development
From study to strategy: entries, exits, position sizing, and how to read the backtest report.
- 01Intermediate8 min
From study to strategy: declaring a strategy
A strategy is just an indicator that can also place orders. The declaration and the constraints you need to know.
- 02Intermediate10 min
Entries and exits: strategy.entry, strategy.exit
The order primitives: how to open a position, set a stop, take a profit, and reverse on signal.
- 03Intermediate9 min
Reading backtest results: what the numbers actually mean
Net profit is the worst metric. The numbers that matter are drawdown, profit factor, and exposure-adjusted return.
- 04Advanced11 min
Position sizing and risk in code
CFD leverage makes position sizing the highest-leverage decision in your strategy. Encoded correctly, it is also the easiest to test.
Part 4Advanced Patterns for CFD
Multi-timeframe analysis, drawing on charts, alerts and automation, and a complete trend-following build.
4 done
Advanced Patterns for CFD
Multi-timeframe analysis, drawing on charts, alerts and automation, and a complete trend-following build.
- 01Advanced12 min
Multi-timeframe analysis with request.security
Higher-timeframe context in your strategy — but only if you avoid the two look-ahead bugs Pine warns about.
- 02Advanced8 min
Drawing on charts: labels, lines, and boxes
Annotations that make a chart readable: trade markers, stop lines, target zones, and trade-management dashboards.
- 03Advanced10 min
Alerts and automation: from signal to notification
Alerts in Pine fire on conditions. Routing them to email, webhook, or your broker's automation API is what closes the loop.
- 04Advanced15 min
Building a complete trend-following system
Putting every lesson together: a multi-timeframe, ATR-sized, alert-wired trend system you can run on any CFD instrument.
Ready to run your first TradingView program?
Jump into lesson 1 — setting up the TradingView editor and writing your first program. No prior coding required.
Continue with another course
MetaTrader 5 MQL5 for CFD Traders
From your first indicator to a complete risk-managed Expert Advisor — 17 lessons, 4 parts.
17 lessonsMacroeconomic Data Analysis for CFD Traders
From reading the calendar to a complete weekly macro workflow — 17 lessons, 4 parts.
17 lessonsGold Analysis for CFD Traders
From the four drivers to a complete weekly gold workflow — 17 lessons, 4 parts.
17 lessonsTechnical Indicators for Beginners
From 'what is an indicator' to a two-indicator setup you can actually defend — 12 lessons, 3 parts.
12 lessonsCandlestick Charting for Beginners
From 'what is a candle' to reading patterns in context — 12 lessons, 3 parts, with a diagram in every one.
12 lessonsPattern Trading for Beginners
From support and resistance to a complete pattern trade plan — 14 lessons, 4 parts, 20 diagrams.
14 lessonsPair this with execution
Compare brokers
Execution engine matters as much as the script. Look at latency, API stability, and product structure side by side.
OpenTradingView strategies
See how other traders translate ideas into Pine. Useful as reference implementations while you build your own.
OpenKnowledge base
Broader CFD curriculum — leverage, edge-building, and systematisation — separate from this course.
Open