HI-USD
How To Create TA Indicators on TradingView
स्रोत:LBank
समय:2020-08-28
स्तर:Research
टैग:Tech/Trading

TradingView: A Powerful Tool for Technical Analysis and Custom Indicators

In the realm of financial investing, possessing precise and efficient trading tools forms the bedrock of effective technical analysis. TradingView, a widely embraced HTML5 web charting platform, offers a comprehensive, user-friendly one-stop solution for millions of global traders to monitor real-time fluctuations in forex, cryptocurrencies, and traditional stock markets.


Beyond aggregating multi-asset tracking capabilities, enabling users to oversee asset performance across multiple platforms within a single interface, TradingView fosters an active social trading community where traders exchange insights and strategies. However, this article zeroes in on a distinctive strength of TradingView—users' ability to customize technical analysis indicators.


This feature is underpinned by TradingView's proprietary programming language, Pine Script. By mastering and applying Pine Script, traders can intricately tailor charts to their liking, encompassing but not limited to designing unique trendlines, plotting specific statistical graphs, and crafting bespoke technical indicators tailored to their individual trading styles. Hence, this article aims to guide readers through understanding and personally implementing how to construct custom technical analysis indicators on TradingView using Pine Script, thereby enhancing the accuracy and efficiency of their trading decisions. Now, let's embark together on this exploratory journey!

Pine Script: The Customization Wizard for TradingView Charts

Pine Script, a cornerstone technology within the TradingView platform, is a potent scripting language tailor-made for traders. It grants users unparalleled autonomy, enabling them to modify and customize an extensive array of charts and indicators on TradingView at will, transcending mere tweaking of pre-existing functionalities.


While TradingView boasts a rich collection of chart types and analytical tools, Pine Script offers a more robust and adaptable solution catering to the unique needs of seasoned traders. Whether you wish to revamp the color scheme of your candlestick charts according to personal preference or devise and backtest a groundbreaking trading strategy from scratch, Pine Script effortlessly facilitates these endeavors through its integrated Pine Editor.


It's worth noting that the syntax structure and function library of Pine Script are comprehensively documented in the official user manual; beginners are strongly advised to consult these resources for comprehensive guidance. This article delves into the fundamentals of Pine Script, intertwining theoretical knowledge with practical examples, focusing on how to harness this powerful tool to construct and apply technically insightful analysis indicators in the realm of cryptocurrency trading.

Practical Pine Script: Starting to Write Technical Analysis Indicators on TradingView

Pine Script, characterized by its simplicity and ease of use, offers traders a means of developing and executing code online without necessitating any additional downloads or environment configurations. By simply accessing the TradingView platform through your browser, you are granted direct entry into the Pine Script editor for script creation.


In this tutorial segment, we will use the BTC/USDT currency pair as an example to guide you through creating custom charts on TradingView. First, ensure that you have an LBank account—either a free version or a paid professional membership account will suffice, though it does not impact the workflow in this tutorial.


Next, log in to TradingView and navigate to the chart page for the BTC/USDT currency pair. You will be presented with a feature-rich chart interface. Within this interface, click the appropriate buttons to delve into chart view, which offers a variety of drawing tools, trendline options, and other technical analysis functionalities to support trading.


While we do not delve into the intricacies of utilizing these existing tools here, we strongly recommend familiarizing yourself with their basic usage methods beforehand. At this point, focus on the series of tabs located at the bottom left of the chart. Locate and click on the "Pine Editor" tab, marking the starting point of our journey into programming technical analysis indicators. Inside the Pine Editor, you will be able to write code to implement calculations such as moving averages, relative strength indices, and more, continually refining and enhancing your trading strategies through practical application.

Exploring Pine Editor: From Crafting Simple Indicators to Plotting Candlestick Charts

In TradingView's Pine Script editor, writing code is akin to issuing commands to a smart assistant, instructing it to display technical analysis indicators on charts according to our specifications. To begin with, we can quickly compose a few lines of script and click "Add to Chart" to instantly annotate or overlay an indicator onto the chart. However, to maintain clarity in the face of multiple overlapping indicators, we can easily right-click any indicator on the chart and select "Remove Indicator" for effective management.


Each line of code in Pine Script serves a distinct purpose. For instance, the first line typically sets the indicator name and optional parameters like "overlay." This parameter allows us to superimpose the new indicator over the existing chart (overlay=true), rather than generating a separate new chart.


Next, let's demonstrate how to plot a chart of Bitcoin's closing prices. While we use a line chart as an example here, similar methods can be employed to create candlestick and bar charts. In fact, when plotting the opening price on a second chart, it's unsurprising that both charts show identical trends since the opening price usually equals the previous day's closing price.


To cater to traders' appetite for more comprehensive market information, we delve further into using Pine Script to create a candlestick chart. Initially, the candlesticks are monochromatic; to enhance their expressive power, we need to adjust the color scheme based on price fluctuations. To achieve this, we introduce a conditional statement above the `plotcandle()` function to check the relationship between the opening and closing prices. If the opening price is higher than or equal to the closing price, it indicates a price decline during that period, warranting a red-colored candlestick. Conversely, a green candlestick signifies a price increase.


After making these modifications, ensure you clear any existing indicators and add the new candlestick chart indicator to your chart. With this, we have successfully leveraged the Pine Script editor within TradingView to customize a candlestick chart that vividly portrays market volatility, thereby enhancing trading decision-making. As we progress through the tutorial, we will continue learning how to plot moving averages (MA), Relative Strength Index (RSI), and other valuable technical analysis indicators, as well as conducting backtesting and their synergistic application.

Utilizing Pine Script to Plot Moving Averages (MAs) and Understanding Their Fundamentals

In the process of creating technical analysis indicators on TradingView, moving averages are an indispensable tool. This section will focus on how to employ Pine Script to draw both Exponential Moving Averages (EMAs) and Simple Moving Averages (SMAs), delving into their calculation methods and practical applications.


Firstly, let us zero in on exponential moving averages. Compared to simple moving averages, EMAs place greater emphasis on recent data, rendering them more sensitive to price fluctuations, hence often utilized by short-term traders for identifying market trends over a brief horizon. When scripting, simply invoking the plot() function with specified EMA parameters suffices to generate the EMA curve for the desired time frame. For instance, we can compute the EMA value for the past 10 trading days, observing variations in EMA line patterns as the number within parentheses is adjusted to represent different periods.


Grasping the mathematical formula behind EMA is paramount. It employs a weighted average approach where each day's EMA value is dynamically updated based on the previous day's figure combined with that day's price data, with the weight factor dictating the extent to which new data influences the outcome. This process can be concisely represented by a recursive formula, blending historical data and current prices in a predetermined ratio to form a novel moving average line.


To facilitate user customization of indicator parameters, the TradingView Pine Script Editor offers a convenient feature: the input() function. By clicking 'New' in the top right corner and selecting 'Moving Average Index' from the dropdown menu, one can view the source code of the EMA. Here, the presence of the input() function becomes apparent, enabling users to effortlessly adjust indicator parameters, such as the EMA's period length, directly within the chart interface via clicking the settings gear icon.


Subsequently, upcoming script examples will demonstrate how to incorporate the input() function to introduce user-configurable parameters, further enhancing the flexibility and practicality of custom indicators. Through juxtaposing plotted SMA and EMA graphs, readers will gain a visceral understanding of the subtle differences between the two in revealing market trends, thereby empowering them to choose the appropriate moving average type in accordance with their individual trading strategy preferences.

Exploring RSI Drawing and Application on TradingView

In the toolbox of technical analysis on TradingView, the Relative Strength Index (RSI) plays a pivotal role. Serving as a momentum indicator, RSI gauges whether the market is overbought or oversold by calculating the magnitude of asset price fluctuations. When the RSI value dips below 30, it is commonly regarded as an oversold region, whereas exceeding 70 may indicate entry into an overbought zone, offering investors valuable guidance for buy-sell decisions.


Crafting an RSI indicator within the Pine Script editor is highly convenient. Users can click on 'New' and select the RSI strategy template; the default period parameter is set to 14 (hours or days), but this can be freely adjusted according to individual trading strategies and time frame requirements.


Upon adding RSI to your chart, you'll notice arrow cues defined by the strategy.entry() function in the code. For instance, RsiLE might appear when the RSI falls below a specific threshold, signaling a potential buying opportunity since the market may have become oversold; conversely, RsiSE will display when the RSI rises above another threshold, warning of a possible sell signal, indicating that the market could be overbought.


However, it's crucial to remember that like all other technical indicators, RSI is an auxiliary analytical tool rather than an absolute predictive one. Even if RSI indicates overbuying or overselling, it does not guarantee an imminent price reversal. Hence, in practical application, RSI should be combined with other indicators, trendlines, and fundamental market information for comprehensive assessment, thereby enhancing the accuracy and robustness of trading decisions.

Practical Implementation and Application of Backtesting on TradingView

Backtesting is a crucial step in the process of creating technical analysis indicators on TradingView. Through this feature, we can validate custom trading strategies or indicators against historical data, recognizing that past performance does not guarantee future results but can help assess the effectiveness of a strategy in capturing market signals.


Let's illustrate how backtesting is performed on TradingView using a simple Bitcoin trading strategy as an example. The strategy stipulates buying (going long) when the Bitcoin price falls to $11,000 and selling (closing positions) when it rises above $11,300. First, define the entry and exit trigger conditions as input variables in Pine Script, allowing users to adjust these parameters directly within the chart interface. Simultaneously, retrieve the closing prices for each period as the basis for decision-making.


Next, utilize if-else logic such that when the market price satisfies the buy condition, the script executes the action of establishing a long position; conversely, when the preset sell condition is met, it executes the operation to close all open positions. To facilitate visualizing trade decision points on the chart, employ the plotshape() function to add arrow annotations marking the "BuyTheDip" and "SellTheNews" locations.


Copy and paste the prepared code into TradingView's Pine Editor, then apply the strategy. TradingView will automatically run these rules against past data in a simulated environment. At this point, the page will switch from the editor to the Strategy Tester tab, presenting an overview of potential profits, detailed trade records, and performance metrics for various indicators. Through backtesting, traders gain直观 insights into their strategy's overall profit and loss, trading frequency, win rate, and other key information over a past time frame, providing strong support for optimizing and refining their trading strategy.

Combining EMA and RSI to Build a Trading Decision Indicator

In the process of creating technical analysis indicators on TradingView, we have already learned how to plot Moving Averages (MAs) and Relative Strength Index (RSI) separately. Now, we will integrate these two tools to design a script that visually reflects market conditions through color changes in candlestick charts, providing auxiliary information for trading decisions.


Firstly, before writing a new script, ensure all existing indicators are cleared from the chart and the underlying Bitcoin/USDT chart is hidden, allowing focus on the new custom indicator. In Pine Script, we need to define an EMA indicator with its `overlay` parameter set to `true`, enabling the EMA to overlay on the candlestick chart. Also, set the length of the EMA as an input integer variable, assigning it a minimum value (e.g., 1) and a default value (such as 14), using user input to calculate the EMA value.


Next, adopt the same approach to define and compute the RSI indicator, also setting a user-adjustable period length. Once the RSI calculation is complete, we will combine these two indicators to determine the color of the candlestick chart. Suppose we establish the following conditions: (a) the closing price of the candlestick is above the current EMA value; (b) the RSI is greater than 50. When both conditions are satisfied, it may indicate that the market is in a strong phase, suitable for longing Bitcoin.


To achieve this, write a logical statement such that if both conditions hold true, the candlestick chart is colored green; otherwise, it is colored red. Next, plot the EMA curve followed by the candlestick chart, ensuring the `color` parameter is included within the `plotcandle()` function, which determines the candle color based on the previously set conditions.


Upon completing these steps, our custom indicator script is ready. Adding it to a TradingView chart will reveal differently colored candlestick charts, clearly reflecting market conditions as determined by the combined judgment of EMA and RSI. However, it is crucial to note that while this combined usage holds some reference value, investment decisions should be made considering multiple tools and technical indicators, along with market fundamentals and individual risk preferences. Moreover, no indicator can guarantee future price movements, hence investors must maintain a cautious attitude.

Conclusion

Summarizing the entirety of this discourse, TradingView stands as a trusted real-time charting platform for global traders, where its custom technical analysis indicators are actualized through Pine Script, affording users an unprecedentedly personalized trading experience. This article delves deeply into how to construct and employ bespoke technical analysis tools using Pine Script, ranging from fundamental moving averages and relative strength indices to sophisticated candlestick pattern rendering and backtesting. It comprehensively illustrates the potential for strategy refinement and decision support within the TradingView ecosystem. Looking ahead, with blockchain technology and financial markets continually evolving, TradingView and its Pine Script will incessantly update and enhance, empowering an ever-growing number of investors to grasp market trends and elevate their trading efficiency.