Effective technical analysis cannot be performed without the correct trading tools. A powerful trading strategy can help avoid common mistakes, improve risk management, and enhance the ability to identify and exploit opportunities.
For many people, TradingView is a charting platform that answers all questions. This powerful HTML5 web application provides a center of technical analysis tools, helping millions of users track Forex, cryptocurrency, and traditional stock market movements.
TradingView has many powerful features: allowing users to track assets on multiple trading platforms and publish trading pairs on their social networking sites the opinion of. This article will focus on its customization capabilities. We will use TradingView's proprietary programming language Pine Script, which allows us to have more detailed control over chart layout.
Get started!
Pine Script is a scripting language that can be used to modify TradingView charts. The TradingView platform already offers many similar features, but Pine Script goes even further. Whether you want to change the color of the candlestick chart, or want to backtest a new strategy, Pine Editor allows you to customize real-time charts according to your needs.
The code itself is well documented, so be sure to check the user manual for details. This article aims to discuss some basics and introduce indicators that can come in handy in cryptocurrency trading.
Pine Script is simple and easy to use. Any code we write runs on TradingView's servers, so we can access the editor through a browser and develop our scripts with no additional downloads or configuration required.
In this tutorial we will plot the Bitcoin/Binance USD (BTCBUSD) currency pair chart. If you don’t have a Binance account yet, create a free account (a Pro account is also possible, but not necessary for this guide).
Open the link and you will see a chart similar to the following:
Your chart data may be updated.
Now, we want to get a chart with rich functions, click the button to enter. We can then see more detailed views, drawing tools, options for drawing trend lines, and other features.
Full-featured chart. You can adjust the schedule by clicking View above the highlighted tab.
We won’t We discuss how to use the various tools available, but if you really want to perform technical analysis, we strongly recommend that you become familiar with them first. In the lower left (outlined in the picture) you will see a few different tabs - click on Pine Editor.
This editor It's amazing. We'll tell it what we want to do, then click Add to Chart and we'll see the annotation we added appear in the chart. Please note that if we add several annotations at the same time, they will get mixed up, so we will delete them in the example (Right-click in the chart>Delete indicator).
As you can see, we already have a few lines of code. Let's click Add to Chart and see what happens.
Adds a second chart below the original chart. The new chart shows exactly the same data. Place the mouse on My Script and click × to delete. Now, let's explore the code.
Research ("my script")
The first line just sets up our annotation. All it takes is the name of the indicator you want to call (in this case "My Script"), but we can also add some optional parameters. One of them is Override, which instructs TradingView to put the indicator into an existing chart (instead of into a new chart). As you can see from the first example we listed, the default value is false. Although you can't see how it works yet, overlay=true will add the indicator to the existing chart.
Drawing chart (closing)
This line is the instruction to chart the closing price of Bitcoin. Chart just gives us a line chart, but we can also present candlestick charts and bar charts, as we'll see shortly.
Now, let’s try the following:
//@version=4 study("My Script", overlay=true) plot(open, color=color.purple)
After adding it, you should be able to see the second chart (it will look like the original chart has been moved to the right). What we do is to draw the opening price chart. Since the opening price of the day is the closing price of the previous day, it is reasonable for these charts to have the same trend.
Okay! Let's delete the current annotation (remember, right-click and click Delete Indicator to do this). Place the mouse on Bitcoin/BUSD and click the Hide button to delete the current chart.
Many traders prefer to use K-line charts. Compared with the simple chart we just made, K-line charts can We provide more information. Next let's add the graph we drew.
//@version=4 study("My Script", overlay=true) plotcandle(open, high, low, close)
Starts off well, but the drab colors make it look a little boring. Ideally, the K-line chart should be red when the opening price is lower than the closing price, and green if the closing price is higher than the opening price. We add a line above the plotcandle() function:
//@version=4 study("My Script", overlay=true) colors = open >= close?color.red: color.green plotcandle(open, high, low, close)
This requires looking at each K-line chart to check whether the opening price is higher than or equal to the closing price. If this is the case, it means that the price fell during this time and the candlestick chart will turn red. Otherwise it will turn green. Modify the plotcandle() function and add this color scheme:
//@version=4 study("My Script" , overlay=true) colors = open >= close?color.red: color.green plotcandle(open, high, low, close, color=colors)
Delete the existing metric if you haven't already and add this metric to the chart. Now we should have drawn a chart similar to a K-line chart.
p>
Well done!
We have completed some basic operations. Let’s take a look at our first custom indicator – the exponential moving average, or EMA. This tool is useful as it allows us to filter out any market noise and smooth out the price action.
EMA is slightly different from the simple moving average (SMA) in that it pays more attention to recent data. It tends to react more to sudden changes and is often used for short-term operations (for example, in day trading).
We can also plot the SMA so we can compare the two later. Add this line to your script.
plot(sma(close, 10))
This graph is the average of the previous ten days. Adjust the numbers in brackets to see how the curve changes as the length changes.
p>
SMA is based on the previous ten days of data.
EMA is more complicated to understand, but don’t worry. Let’s analyze this formula first:
EMA=(closing price-previous day’s EMA)*multiple-previous day One-day EMA
What does this mean? Each day, we calculate a new moving average value based on the previous day's value. The multiple is "weighted" by the number of recent days and is calculated using the following formula:
Multiple = 2/(EMA length + 1 )
Like the simple moving average, we need to assign a value to the length of the EMA. Syntactically, plotting the EMA function is similar to plotting the SMA function. Plot this alongside the SMA and you can compare the two.
//@version=4 study("My Script", overlay=true) plot(sma(close, 10)) plot(ema(close, 10))
You will see that these two types of MA are slightly different.
➟ Want to start your cryptocurrency journey? Welcome to buy Bitcoin on Binance!
So far, we have written our code manually, you will have an intuitive feeling. Now we'll introduce some features that can save time, especially if we want to write more complex scripts but don't want to start from scratch.
At the top right of the editor, click New. You'll get a drop-down menu showing a variety of different technical indicators. Click Moving Average Index to view the source code of the EMA indicator.
Click and add it to the chart.
This index is related to Our difference, you'll notice, is the input() function. These are great from a usability perspective because you can click on this box...
p>
...and click the gear icon of Settings to easily change some values in the pop-up window.
We will add a few input() functions to the next script to demonstrate this.
The Relative Strength Index (RSI) is another important indicator in technical analysis. Known as the Momentum Indicator, it measures the price at which an asset is bought and sold. On a scale of 0 to 100, the RSI score attempts to tell investors whether an asset is overbought or oversold. Typically, if an asset has a score of 30 or less, it may be considered oversold, while a score of 70 or more may be overbought.
Go to New>RSI Strategy to see it for yourself. RSI is generally measured on a period of 14 (i.e. 14 hours or 14 days), but you are free to adjust this setting to suit your strategy.
Add RSI to the chart. You should see several arrows now displayed (defined by the strategy.entry() function in this code). RsiLE represents a potential opportunity to extend an asset as it may be oversold. RsiSEhighlights points where it is possible to go short when an asset is overbought. Please note that, as with all indicators, you do not necessarily need to take these indicators as conclusive evidence that prices are going to decrease/increase.
There is a way for us to test our own custom indicators. While past performance is no guarantee of future results, backtesting our script can give us an idea of its effectiveness at catching signals.
Here we will give a simple script example. We plan a simple and clear strategy to enter a long position when the price of Bitcoin drops to $11,000 and exit the long position when the price exceeds $11,300. We can then see how profitable this strategy has 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 enter and exit as Variables – Both are inputs, meaning we can make changes to both later in the chart. We also set the Price variable to take the closing price of each period. Then, we have some logic that follows theifsentence pattern. If the part in the brackets is true, then the indented block below it will be run. Otherwise, it will be skipped.
So, if the price is less than or equal to our desired entry price, and the first expression evaluates to true, we will open a long position. Once the price equals or exceeds the required exit price, a second block will be triggered, closing all open positions.
We annotate the chart with arrows to show where we enter/exit, so we use evaluate Parameters to specify what marks these points (in this case "BuyTheDip" and "SellTheNews"). Copy the code and add it to the chart.
Now you can see these indicators in the chart. Amplification may be required.
TradingView automatically applies your rules to older data. You will also notice that TradingView switches from the Pine Editor to the Strategy Tester tab. This allows you to see an overview of potential profits, a list of trades, and the performance of each indicator.
Positions we have entered and exited.
But this does not constitute financial advice, and there is no objectively correct way to use these indicators. Like all other tools, it should be combined with other tools to develop your own investment strategy.
Now let's take a look at the new script. Remove all indicators from the chart and hide the Bitcoin/BUSD chart so that we have a clean operating background.
Let's look at the definition first. Name it whatever you want, just make sure to set overlay=true.
study(title="Binance Academy Script", overlay=true)
Remember our previous EMA formula. We need to use the EMA length to calculate the multiple. Let's turn this into aninput that requires an integer number of digits, so no decimal places. We also set 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)
Based on this new variable, we can calculate the EMA value of each K-line chart in the chart:
study(title="Binance Academy Script", overlay=true) emaLength = input(title="EMA Length", type=input.integer,defval =25, minval=0) emaVal = ema(close, emaLength)
Very good. Next let’s look at the RSI. We will assign a length value to it 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)
Now, we can calculate:
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, let us combine the logic that determines the color of the K-line chart. These The color depends on the values of EMA and RSI. Let us assume that (a) the candlestick closes above the EMA and (b) the RSI is above 50.
Why should we assume this? Because you might decide to use a combination of these indicators to know when to go long or short Bitcoin. For example, you might think that meeting these two conditions means now is a good time to go long. Or conversely, you can use it to remind yourself whennotto go short, even if other indicators give exactly the opposite reference.
So our next line of code 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.red
If we translate this sentence into plain English, we In fact, it means that if the EMA value exceeds the closing price and the RSI score exceeds 50, the K-line chart will turn green. Otherwise it will turn red.
Next, draw the EMA chart:
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")
Finally, draw the K-line chart, please be sure Contains the color parameter:
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)
Then, the script is written! Add it to the chart and see how it works.
A Bitcoin/BUSD with EMA/RSI indicator chart.
In this article, we demonstrate to you the functionality of Pine Editor on TradingView through some basic examples. You should now feel confident making simple annotations on price charts to gain more insights from your own indicators.
We have only introduced a few of these indicators in this article, but it is not difficult to create more complex indicators - choose NewBuilt-in scripts or write your own built-in scripts.
Still lacking inspiration? The following articles may provide some ideas for your next project:
A Brief Guide to the Parabolic Indicator
"Fibonacci Retracement Study Guide"
"Detailed Explanation of Leading and Lagging Indicators"
li>Detailed explanation of exponential moving average (MACD) indicator