TradingView is programmable through a language called Pine Script. This document is a beginner’s guide to learning how to write, execute, and backtest a simple trading strategy.
Where to start
How to create a new strategy
The backtest
A little improvement
Conclusions
Where to start?
At this link, you can find the online manual of the language: Pine Script User Manual 4 documentation,
and here is the Reference guide.
If you want to learn to code indicators and automated trading systems, this book (“Learn to program automated trading systems for TradingView from scratch”) can help you to start.
We begin to become familiar with the development environment, namely the Pine Editor.
In the lower part of the window with the graph, choose the Pine Editor tab.
Pine Editor tab in TradingView - Screenshot by Author.
Now we should see the indicator drawn in the graph window.
The indicator named “My script” is plotted on the chart of TradingView - Screenshot by Author.
How to create a new strategy
We want to write a trading system, not an indicator (many are already on the platform)!
Let's close it by pressing the button with the "X" at the top right.
Into the “Open” menu choose “CREATE NEW / Strategy”.
We start to create a new strategy - Screenshot by Author.
A complete strategy already appears: it is a crossing of moving averages.
This is the code that appears when I choose to create a new strategy in TradingView - Screenshot by Author.
The backtest
Click on "Add to Chart" also for this strategy and the backtest will appear.Please, watch the content of all four tabs (Overview, Performance Summary, List of Trades, Properties).
A little improvement
I have added some inputs to “My strategy” - Screenshot by Author.
This is the window with the inputs that you can change, now.
Strategy inputs - Screenshot by Author.
If you change a value, the platform immediately recalculates all the backtest.
Conclusions
- Pine Script is a powerful language that you can easily learn.
- Learning this language, you can backtest your strategies and understand if they have worked or not in the past, so you can decide if it’s a good idea to try to use them in the future.
Written by F. GRAMOLA (*).
(*) Member of S.I.A.T., the Italian Society of Technical Analysis (member society of I.F.T.A. – International Federation of Technical Analysts).
Warning
We merely cite our personal opinions for educational purposes only.
All trademarks are the property of their respective owners.
Investing and trading are risky. Don't invest or trade money that you cannot afford to lose.
The above trading system is intended for education and research only.
Initial Photo by Luke Chesser on Unsplash.
Post a Comment