Introduction
Without the right trading tools, it is not possible to perform effective technical analysis. A solid trading strategy will help you avoid common mistakes, improve your risk management, and enhance your ability to identify and take advantage of opportunities.
For many, TradingView is the best charting platform. The powerful HTML5 web application offers many technical analysis tools and is used by millions of users to track movements in the stock, Forex, and cryptocurrency markets.
TradingView has many powerful features: it allows us to track assets across multiple trading platforms and share trading ideas on social media. In this article, we will talk about your customization options. We will use PineScript, TradingView's own programming language, which gives us control over our chart layouts.
Let's start!
What is Pine Script?
Pine Script is a scripting language used to customize TradingView charts. The platform already provides many features for this, but Pine Script offers some additional options. Whether you want to change the colors of candlesticks or backtest a new strategy, the Pine Editor allows you to customize your charts in real-time the way you prefer.
The code has very solid documentation, so be sure to consult the user manual for more information. Our goal in this tutorial is to discuss some of the basics and present indicators that are useful for cryptocurrency trading.
Setting
It's very simple to start using Pine Script. All code runs on TradingView's servers, so we can access the editor and develop our scripts from a browser – no additional downloads or configuration required.
In this tutorial, we will use the Bitcoin/Binance USD (BTCBUSD) currency pair. If you don't have an account yet, create one for free (there is also a Pro subscription option, but it is not necessary for this tutorial).
Go to this link and you will see a graph like this:

Yours will probably be more up to date.
Here we will use the full-featured chart mode – click the button to access it. In this mode, we have a more detailed view, drawing tools and options for plotting trend lines, among other functions.

The complete graph. You can adjust the time period by clicking the options above the tabs highlighted in the image.
We won't discuss how to use the various tools available, but if you use technical analysis, we recommend that you familiarize yourself with them. In the bottom left corner (shown in the image), you will see a few different tabs – click on Pine Editor.
Pine Editor

This editor is where the magic happens. Let's enter the instructions. Click Add to Chart to display the above annotations. Note that things can get complicated if we include multiple annotations at once, so we'll remove them for the next examples (right-click on the chart > Remove Indicators).
As we can see, we already have a few lines of code. Let's click Add To Chart and see what happens.

A second graphic will be added below the original. The new chart now displays the same data. Hover over My Script and click the cross to remove it. Now, let's dive deeper into the code.
study("My Script")This first line is just setting up our annotations. We only need to define a name for the indicator ("My Script" in this case), but there are also some optional parameters we can add. One of them is the overlay, which instructs TradingView to insert the indicator into the existing chart (instead of using a new segment). As we can see in the first example, the default is false. The overlay = true parameter adds the indicator to the existing chart, but we will not use it now.
plot(close)This line is an instruction for plotting the closing price of Bitcoin. The plot parameter simply gives us a line graph, but it is also possible to display candles and bars, as we will see shortly.
Now, let's try the following:
//@version=4 study("My Script", overlay=true) plot(open, color=color.purple)After adding this parameter, we will see a second graph (which looks like the original, but shifted to the right). All we did was plot the open price. Since the current day's open is the previous day's close, it makes sense that they have an identical format.
OK! Let's get rid of the current notes (remember, we do this by right-clicking and selecting Remove Indicators). Hover over Bitcoin/BUSD and click Hide to clear the current chart as well.
Many traders prefer candlestick charts because they give us more information than a simple chart like the one we just made. We'll add them next.
//@version=4 study("My Script", overlay=true) plotcandle(open, high, low, close)It's a good start, it's a good idea to add some colors. Generally, we use red candles when the opening price is higher than the closing price for the given period, and green candles if the closing price is higher than the opening price. Let's add a line below the plotcandle() function:
//@version=4 study("My Script", overlay=true) colors = open >= close ? color.red : color.green plotcandle(open, high, low, close)This function analyzes each candle and checks whether the opening value is greater than or equal to the closing value. If it is, it means prices have fallen over the period, so the candle will turn red. Otherwise, it will be green. Modify the plotcandle() function to set this color scheme to:
//@version=4 study("My Script", overlay=true) colors = open >= close ? color.red : color.green plotcandle(open, high, low, close, color=colors)Remove the current indicators if you haven't already and add this one to the chart. Now we should have something similar to a regular candlestick chart.

Great!
Plotting Moving Averages (MM)
We go through some of the basics. Let’s plot our first custom indicator – the exponential moving average or EMA. This is a valuable tool as it allows us to filter out any market noise and smooth out price action.
The EMA differs slightly from the simple moving average (SMA) in that it places more emphasis on the most recent data. It tends to be more reactive to sudden movements and is often used for short-term strategies (like day trading, for example).
Simple Moving Average (SMA)
Let's also plot the simple moving average (SMA), so we can compare the two later. Add this line to your script:
plot(sma(close, 10))This value represents the average of the last ten days. Adjust the number in parentheses to see how the curve changes when considering different periods.

MMS, based on the last ten days.
Exponential Moving Average (EMA)
The EMA is a little more complicated, but don't worry. Let's look at the formula first:
EMA = (Closing - Previous Day's EMA) * Multiplied - Previous Day's EMAWhat does that mean? For each day, we calculate a new moving average based on the previous day's average. The multiplier considers the “weight” of the most recent period and calculates it using the formula:
Multiplier = 2 / (EMA Period + 1)As with simple moving averages, we need to specify the duration of the EMA. Syntactically, the function to plot the EMA is similar to the MMS. Plot it next to the MMS so you can compare the two:
//@version=4 study("My Script", overlay=true) plot(sma(close, 10)) plot(ema(close,10))
We can notice a slight difference between the two types of moving averages.
➠ Thinking about investing in cryptocurrencies? Buy Bitcoin on Binance!
Built-in scripts
So far, we've written our code manually so you can get an idea. But let's use something that can save us time, especially if we are writing more complex scripts and don't want to do them from scratch.
At the top right of your editor, click New. You will see a drop-down menu with all types of technical indicators. Click Moving Average Exponential to view the source code of an EMA indicator.

Add this to the chart.
This one is different from ours – here we see input() functions. They are good in terms of usability, because we can click this box…

...and easily change some of the values in a new window by clicking Settings.

We will add some input() functions in our next script to demonstrate this.
Plotting the Relative Strength Index (RSI) indicator
The Relative Strength Index (RSI) is another essential technical analysis indicator. It is known as a momentum indicator, that is, it measures the buying and selling rate of assets. The RSI score is presented on a scale of 0 to 100 and attempts to inform investors whether assets are overbought or oversold. Typically, an asset is considered oversold if it has a score less than or equal to 30 and overbought with a score greater than or equal to 70.
You can go to New > RSI Strategy and see for yourself. Generally, RSI is measured in 14-hour or 14-day periods, but you can adjust this setting to suit your own strategy.
Add this to the chart. Now, you will see some arrows (defined by the strategy.entry() function in the code). RsiLE indicates a potential long position opportunity for the asset, which may be oversold. RsiSE highlights the possible points for short positions in the asset, when it is overbought. Please note that, as with all indicators, you should not necessarily rely on them as infallible evidence that prices will fall/rise.
Backtesting
There is a way to test custom indicators. While an asset's history is no guarantee of future results, backtesting our scripts can give us an idea of its effectiveness in capturing signals.
Next, we will use a simple script example. Let's create a strategy that enters a long position when the price of BTC drops below $11,000 and exits the position when the price exceeds $11,300. We can then see how profitable this strategy would have been historically.
//@version=4 strategy("ToDaMoon", overlay=true) enter = input(11000) exit = input(11300) price = close if (price <= enter) strategy.entry("BuyTheDip", strategy.long, comment="BuyTheDip") if (price >= exit) strategy.close_all(comment="SellTheNews")Here, we define entry and exit as variables – both are inputs, which means you can change them in the chart later. We also configure the price variable, price, which considers the closing of each period. Then we have the use of logic in the form of if functions. If the part in square brackets is true, the block below it will be executed. Otherwise, the block will be ignored.
Therefore, if the price is less than or equal to the desired entry, the first expression will evaluate to true and we will open a long position. As soon as the price is equal to or greater than the desired exit, the second block will be triggered, closing all open positions.
We will use the graph with arrows that show where we enter/exit; Therefore, we specify how to label these points with the comment parameter, comment (in this example, “BuyTheDip” and “SellTheNews”). Copy the code and add it to the chart.

Now we can see the indicators on the chart. You may need to zoom out.
TradingView automatically applies its rules to older data. You will also notice that it switches from the Pine Editor to the Strategy Tester tab. This allows you to have an overview of your possible profits, a list of trades and each of their individual performances.

Entry and exit positions.
Associating the information
It's time to write our own script using some of the concepts we've seen so far. Let's combine EMA and RSI and use their values to color the candlestick charts, generating information that we can easily visualize.
This should not be interpreted as investment encouragement or financial advice – there is no objectively correct way to use this indicator. Like all others, it should be used with other tools to develop your own strategy.
Now let's work on our new script. Remove all your indicators from the chart and hide the Bitcoin/BUSD chart so we can work in a clean canvas.
Let's start by defining our study. Feel free to name it whatever you want, but remember to set the overlay=true parameter.
study(title="Binance Academy Script", overlay=true)Remember our EMA formula from before. We must provide the multiplier with the period of the EMA. Let's use an input that requires an integer (so no decimal places). We will also define a minimum value (minval) and a default value (defval).
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0)Using this new variable, we can calculate the EMA value for each candle on our chart:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength)Excellent. Now the RSI. We will define a period in a similar way:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength) rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0)And then, we can calculate it:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength) rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0) rsiVal = rsi(close, rsiLength)At this stage, we will put together the logic that colors candlestick charts according to EMA and RSI values. Let's consider a situation where (a) the candle's closing price exceeds the EMA and (b) the RSI is greater than 50.
Why? Well, you can decide to use these indicators together to get long or short signals for Bitcoin trading. For example, you might think that satisfying both conditions means it's a good time to enter a long position. Or, on the other hand, you can use it to inform yourself about when the position should not be short, even if other indicators signal otherwise.
So our next line will look like this:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength) rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0) rsiVal = rsi(close, rsiLength) colors = close > emaVal and rsiVal > 50 ? color.green : color.redUsing simple language, the code simply says that if the EMA value exceeds the closing price and the RSI score is greater than 50, the candle color will be green. Otherwise, it will be red.
Next, let's plot the EMA:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength) rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0) rsiVal = rsi(close, rsiLength) colors = close > emaVal and rsiVal > 50 ? color.green : color.red plot(emaVal, "EMA")Lastly, plot the candles, making sure to include the color parameter, color:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer, defval=25, minval=0) emaVal = ema(close, emaLength) rsiLength = input(title="RSI Length", type=input.integer, defval=25, minval=0) rsiVal = rsi(close, rsiLength) colors = close > emaVal and rsiVal > 50 ? color.green : color.red plot(emaVal, "EMA") plotcandle(open, high, low, close, color=colors)And that's the script! Add it to the chart to see it working.

BTC/BUSD chart with the EMA/RSI indicator.
Final considerations
In this article, we look at some basic examples of what you can do with TradingView's Pine Editor. Now, you should be able to customize price charts to gain additional insights using your own indicators.
We've only covered a few indicators here, but the idea is the same for more complex ones – you can select scripts built into New or write them yourself.
Uninspired? The following articles may provide some ideas for your next project:
A brief guide on the Parabolic SAR Indicator
Fibonacci Retracement Guide
Leading and Lagging Indicators
How the MACD Indicator Works

