TradingView programming articles
This page lists all TradingView programming articles, starting with a basic understanding of TradingView Pine and ending with more complex concepts.
Part I: The fundamentals of TradingView Pine
In this first part we look at the basic fundamentals of the TradingView Pine programming language.
Operators are used in TradingView for a wide range of operations, and perform actions like addition, comparing true/false values, and creating functions. The articles below discuss the various operators and how they work, starting with the chapter’s introduction and ending with a summary of operators.
Assigning values to variables
- TradingView’s arithmetic operators (+, -, *, /)
- Combining strings with the addition operator (+) in TradingView
- Working with TradingView’s modulus operator (%)
If/else statement-like behaviour
- The conditional ternary operator (?:): a compact if/else statement
- The iff() function in TradingView: the conditional operator simplified
Operators and true/false values
- Comparing values for true or false with TradingView’s comparison operators
- TradingView’s logical operators: evaluating true/false values
Creating single-line and multi-line functions
The order of operations
Part II: Working with TradingView Pine
In this part we take a closer look at the different features in TradingView and how we can use these programmatically.
In this chapter we discuss how we can add manual input options to TradingView indicators and trading strategies. The introduction provides an overview of the chapter, while the summary recaps the most important points.
- How to add numerical inputs to a TradingView script?
- Adding a true/false checkbox option to a TradingView script
- Creating a text box input option in Pine
- How to create a session time range input in TradingView?
- Adding a symbol search box to a TradingView script
- Creating a resolution input in a TradingView script
- Adding a source input type to a TradingView Pine script
The basics of colours in TradingView
- How to manually change a TradingView script’s colours?
- Coding with TradingView’s basic colours
- Working with hexadecimal colour values in TradingView (+colour lists)
- Why does the same colour not always look the same in TradingView?
Working with colours programmatically
- How to ‘turn off’ a colour in TradingView Pine?
- Changing TradingView colours conditionally with the conditional operator
- Using the
iff()function to apply colours conditionally in TradingView
- Setting TradingView colours conditionally with if/else statements
- Colour transitions in TradingView: how to get gradient-like colours?
- How to use pseudo-random colours in TradingView?
In this chapter we discuss how to apply TradingView colours on the chart’s full background (top to bottom) or a background section that’s between two plots or two horizontal lines. See the introduction for an overview of the chapter while the summary reiterates the most important points.
Colouring the chart's full background
- Colouring the background of a TradingView chart programmatically
- Colouring a TradingView background with different colours or none
- How to shift a coloured background to the past or future?
- Colouring the background repeatedly: combining coloured backgrounds
- How to colour the background of forex market sessions?
- How to create a TradingView background that’s like a heat map?
Colouring a section of the chart's background
- Colouring a part of the chart’s background in TradingView
- Shading the background between a plot and a horizontal line
- Colouring the background of support and resistance areas in TradingView
- Filling the background between invisible TradingView plots
- Colouring the background between circles and crosses
- Colouring the background area between histograms and columns
- Filling background areas around a TradingView area plot
- Combining several coloured background sections in TradingView
- Colouring the background of price bands and price bars in TradingView
In this (currently incomplete) chapter we look at creating custom price bars and colouring the instrument’s existing price bars.
Colouring price bars
- How to change the colour of price bars in TradingView Pine?
- Offsetting coloured price bars in TradingView: how?
Part III: Indicators
In this part we take a closer look at the different features of TradingView Pine that we use when programming indicators.
In this chapter we look at the different indicator settings that we can configure programmatically in Pine. The introduction provides an overview of the chapter, while we reiterate the most important points in the summary.
- Introduction: configuring TradingView indicators programmatically
- How to set indicator properties programmatically in TradingView?
- Setting the name of a TradingView indicator programmatically
- How to overlay a TradingView indicator on the price chart?
- Specifying the precision of an indicator plot in TradingView Pine
- Setting the price scale of a TradingView indicator programmatically
- How to programmatically set the number of bars an indicator calculates on?
Oddities of indicator settings
Part IV: Trading strategies
In this part we look at how we can program trading strategies in with the TradingView Pine scripting language.
In this chapter we examine the different TradingView strategy settings, and how we can set those programmatically and by hand. Each article, besides discussing a certain feature, also contains an example strategy. An overview of the chapter is given in the introduction while we the summary reiterates the most important points.
Configuring strategies programmatically
- How to configure a trading strategy in TradingView?
- Configuring a TradingView strategy by hand and with code: an overview
- Setting the name of a TradingView strategy programmatically
Setting a strategy's visual appearance
- Plotting a TradingView strategy on the instrument’s price bars
- How to set the precision of a TradingView trading strategy?
- Why does a TradingView strategy plot with more or less decimals than configured?
- How to set the price scale of a TradingView strategy programmatically?
Specifying initial capital and currency
- How to set the initial capital of a TradingView strategy?
- Setting the currency of a TradingView strategy with code
- Initial capital and currency conversion with a TradingView strategy
- Why are TradingView’s backtest results with currency conversion slightly off?
Pyramiding in TradingView
- How to set a TradingView strategy’s pyramiding with code?
- Why TradingView doesn’t respect pyramiding settings: multiple entry orders
- Why TradingView doesn’t follow pyramiding settings: using
Order sizing in TradingView
- How to set the default order size to a fixed quantity?
- Sizing TradingView trades with a fixed amount of cash?
- Currency conversion when sizing TradingView orders with a cash amount
- Sizing TradingView orders based on a percentage of the strategy’s equity
- Currency conversion and sizing TradingView orders based on equity percentage
Historical bar settings
- How to programmatically set the number of bars a TradingView strategy calculates on?
- Configuring how strict TradingView fills limit orders during backtesting
Additional intra-bar calculations
- How to recalculate a TradingView strategy once an order fills?
- Additional calculations after an order fills: inaccurate backtest results
- Why is my strategy not affected by an additional intra-bar calculation after an order fills?
- How to calculate a TradingView strategy with every real-time tick?
- Tip: backtest results are inaccurate when calculating on every tick