LightningChart JS TraderUsing Triangular Moving Average for Stock Trading
ArticleImplement the triangular moving average technical indicator for developing stock trading strategies.
Written by a human | Updated on April 24th, 2025
Triangular Moving Average Indicator
In stock trading and technical analysis, moving averages are widely used to smooth out price data and help traders identify trends. The triangular moving average indicator (TMA) is one such tool that offers a unique approach compared to other types of moving averages. In this blog, we will delve into the triangular moving average (TMA) and explore its calculation, formula, and how to use it effectively in stock trading. We’ll also guide you through the process of creating this indicator using the LC JS Trader Interactive Examples.
What is the TMA Indicator?
The triangular moving average indicator is a type of moving average that smoothens price data by giving greater weight to the middle points of the price series. Unlike the simple moving average (SMA) or exponential moving average (EMA), which apply equal or exponentially decreasing weights to prices, the TMA emphasizes the central data points. This makes it particularly useful for traders who seek to reduce noise in volatile markets.
How This Moving Average Differs from Others
While the simple moving average (SMA) assigns equal weights to all data points, and the exponential moving average (EMA) assigns more weight to recent data, the triangular moving average (TMA) creates a double-smoothed result. It takes the average of the averages, providing an even smoother trend line than other types of moving averages. This makes it slower to react to rapid market movements but effective in identifying longer-term trends with less market noise.
Triangular Moving Average Formula
The triangular moving average formula is built on a two-step calculation process. The first step involves calculating a simple moving average (SMA) of the data series. The second step calculates the SMA of the resulting SMA values. This double smoothing effect makes the TMA particularly smooth and helps reduce the impact of short-term fluctuations.
Step 1: The formulas for the calculations are given below:
Where:
- P represents the price at each period.
- n is the number of periods considered.
Step 2: Take the average of all the SMA values to get TMA values:
Where:
- SMA1, SMA2, SMA3, etc. are the SMA values calculated in step 1
- n is the number of periods (same as in step 1)
Calculation Example:
Let’s break down the triangular moving average calculation into clear steps. Assume we have the following 9 daily closing prices for a stock:
Step 1: Calculate the First Simple Moving Average (SMA)
We start by calculating the 9-period Simple Moving Average (SMA) for these prices.
Step 2: Calculate the Next Simple Moving Average on the SMA Values
Since the TMA requires a second smoothing, let’s assume we already have several prior SMA values (calculated in previous periods). For the sake of this example, let’s assume the following earlier SMA values:
Now, to calculate the triangular moving average for the period, we apply the SMA formula again, but this time using the previous SMA values (in this case, we’ll average these 5 SMA values):
Interpretation of Results
- Smoothing of data: The TMA has provided a smoothed value of 24 that is less influenced by the individual price fluctuations seen in the original data series.
- Lagging effect: Since the TMA smooths the data more heavily, it is slower to react to rapid price changes. For instance, even though the prices rose to 28 on Day 9, the TMA remains at 24, which reflects the average trend rather than immediate price spikes.
- Trend identification: A rising TMA value indicates a bullish (upward) trend, as seen in this example where the TMA steadily rises. This suggests that the stock has been in a general upward trend for the observed period.
In summary, the TMA value of 24 indicates that the stock’s overall trend is upward, though it is slow to react to short-term price increases such as the jump to 28 in the most recent days.
TMA Usage in Technical Analysis
In technical analysis, the triangular moving average is used in much the same way as other moving averages – to identify and confirm trends. When the TMA is rising and the price is above it, the trend is considered bullish. Conversely, a falling TMA with the price below it indicates a bearish trend.
Crossovers between the price and the TMA can also be used to generate trading signals. When the price crosses above the TMA, it’s a bullish signal suggesting a potential buying opportunity. When the price crosses below the TMA, it’s a bearish signal suggesting a potential selling opportunity.
However, due to the slowness of the TMA, these crossover signals will occur much later than they would with a faster moving average like the exponential moving average (EMA). The TMA is therefore best suited for identifying long-term trends rather than short-term price movements.
How Traders and Analysts Use TMA to Identify Trends
Traders and analysts typically plot multiple TMAs of different lengths on their price charts, with the 50 and 200-period TMAs being the most common. These are often seen as key support and resistance levels. When the price is above both the 50 and 200 TMAs, it’s a strong bullish signal. When it’s below both, it’s a strong bearish signal.
Traders often combine the triangular moving average with other technical indicators like the Relative Strength Index (RSI) or Moving Average Convergence Divergence (MACD) to confirm trends. The TMA is particularly useful for identifying the beginning of long-term trends because its double smoothing reduces the chances of false signals triggered by short-term price fluctuations.
The Role of LightningChart JS Trader in Financial Analysis
Financial analysis involves examining historical data to forecast future trends, make informed decisions, and assess risk. In this domain, applications like LightningChart JS Trader serve a critical role by providing real-time, high-performance data visualization tools that help traders and analysts better interpret complex datasets. It enables traders to track market trends using built-in indicators.
The platform’s ability to handle large datasets and real-time updates makes it essential for fast decision-making in dynamic markets. Additionally, its customization options allow users to create tailored charts and apply statistical indicators, enhancing both the precision of analysis and risk management. This tool helps streamline financial analysis and supports more informed, data-driven trading strategies.
Implementation with LightningChart JS Trader
Advanced charting platforms like LightningChart JS offer traders a range of technical indicators, including the Triangular Moving Average indicator. LightningChart JS allows traders to create interactive, high-performance charts, ensuring real-time data visualization. This platform is particularly useful for traders who rely on technical indicators such as the Triangular Moving Average indicator to make quick, informed decisions.
Step 1: Get LightningChart JS Trader
To begin, you’ll need access to LightningChart JS Trader. This library provides the tools necessary to create advanced technical indicators, including the Triangular Moving Average indicator. Visit the LightningChart JS Trader page to download the required components and review the documentation.
Step 2: Review the Interactive Example
LightningChart JS Trader includes interactive examples that demonstrate how to create custom technical indicators. Start by reviewing the documentation, focusing on how to integrate the Triangular Moving Average indicator into your chart setup. The interactive examples will guide you through the process of setting up the Triangular Moving Average indicator, from importing the necessary modules to modify the chart settings.
Step 3: Code Explanation
In this step, we will break down the code that creates the chart with the Triangular Moving Average indicator, as shown in the image, using LightningChart JS Trader. The code demonstrates how to initialize a trading chart, apply the Triangular Moving Average indicator, and customize its appearance.
Here’s a detailed breakdown of each section:
A. Importing the Required Libraries:
const lcjsTrader = require('@arction/lcjs-trader')
const lcjs = require('@arction/lcjs')
const { Themes } = lcjs
- lcjsTrader: This library provides access to the LightningChart JS Trader functionalities, allowing you to create advanced financial charts.
- lcjs: The main LightningChart JS library is used for general charting functionality.
- Themes: A property within lcjs that provides access to pre-built themes. In this case, we are using the
darkGoldtheme to style the chart.
B. Initializing the Trading Chart:
lcjsTrader.trader(TRADER_LICENSE).then(async (trader) => {
// Create a trading chart.
const tradingChart = trader.tradingChart({ loadFromStorage: false, colorTheme: Themes.darkGold })
- trader(TRADER_LICENSE): Initializes the LightningChart JS Trader with the provided license key (TRADER_LICENSE). This is required to access the charting functionalities for financial data.
Note you can request a LightningChart JS Trader trial license, which is free.
tradingChart(): This function creates a trading chart with certain options. In this example:
loadFromStorage: false: This disables the loading of previously stored chart data from local storage, ensuring a fresh chart setup.colorTheme: Themes.darkGold: This applies the darkGold theme to the chart which influences the background color, grid lines, and other visual elements.
C. Adding and Customizing the Indicator
// Add a Triangular Moving Average
const tma20 = tradingChart.indicators().addTriangularMovingAverage()
tma20.setPeriodCount(20)
tma20.setLineColor('#4d7dfe')
tma20.setLineWidth(2)
addTriangularMovingAverage(): TMA is a double smoothed Simple Moving Average, which puts more weight to the middle section of the data.
tma20.setPeriodCount(20):Sets the time period for the TMA to 20. This means the TMA will calculate the average based on the last 20 data points.
tma20.setLineColor('#4d7dfe): Changes the color of the TMA line to a specific shade of blue, making it visually distinct on the chart.
tma20.setLineWidth(2): Increases the line thickness of the TMA to 2 pixels, making the line more prominent on the chart.
D. Loading Data from a CSV File
// Reading data from a file.
await fetch(`${document.head.baseURI}examples/assets/0000/Alphabet Inc (GOOGL).csv`).then((res) => res.text()).then((text) => {
tradingChart.readCsvString(text, 'Alphabet Inc (GOOGL)')
})
fetch(): This function retrieves a CSV file containing historical data for Alphabet Inc. (GOOGL). The CSV file includes pricing information for the company’s stock, which is plotted on the chart.
readCsvString(): This function reads the CSV data and interprets it as pricing data for Alphabet Inc. The second argument (‘Alphabet Inc (GOOGL)’) sets the label for the chart, as seen at the top of the chart image.
E. Setting the Currency for the Chart
tradingChart.setCurrency('USD')
})
setCurrency('USD'): This sets the currency of the chart to USD, ensuring that the pricing data is interpreted and displayed in US dollars.
Advantages and Limitations of the Time-Series Moving Average
Like all technical indicators, the triangular moving average has its strengths and weaknesses. The key advantage of the TMA is that it provides a very smooth, noise-free representation of the long-term trend. By averaging the price data twice, it effectively filters out almost all of the short-term price fluctuations that can make other moving averages choppy.
This smoothness can be particularly beneficial in markets that are prone to a lot of “whipsaws” – false trend reversals caused by short-term volatility. The TMA will largely ignore these whipsaws and only react to more significant, sustained trend changes.
However, this immunity to short-term noise comes at a cost. The main drawback of the TMA is that it is exceptionally slow to react to real trend changes when they do occur. It will always lag significantly behind the price action, and this lag will be greater the more periods are used in the calculation.
For example, a 200-period TMA may continue rising long after the price has topped out and started a new downtrend. By the time the TMA finally turns down to confirm the new bearish trend, a substantial portion of the downtrend may have already occurred.
This lag effect means that the TMA is not well-suited for short-term trading strategies that aim to catch trend changes quickly. It is better used as a long-term trend filter and a way to identify key support and resistance zones.
Another limitation of the TMA is that it can completely lose its usefulness during long periods of sideways, trendless price action. In these conditions, the TMA will just flatten out and provide no clear trend bias. Traders relying on TMA signals may find themselves staying out of the market for extended periods in these situations.
Conclusion
In summary, the triangular moving average is a unique type of moving average indicator that provides a highly smoothed, long-term oriented view of the market trend. By averaging price data twice, it effectively eliminates most of the market “noise” that can obscure the underlying trend.
While this extreme smoothing can be beneficial for identifying major trends, it also causes the TMA to lag significantly behind the price action. This makes it less useful for strategies that require quick reaction to trend changes.
As with all technical analysis tools, the TMA is best used in conjunction with other forms of analysis. Combining the TMA with momentum oscillators, chart patterns, or fundamental analysis can help provide a more complete picture of the market.
If you’re interested in adding the TMA to your technical analysis toolkit, the interactive examples provided by LightningChart website is a great place to start. By experimenting with the code and seeing how the TMA behaves with real price data, you can gain a better understanding of its strengths and limitations and how it might fit into your own trading or investing methodology.
Regardless of how you choose to use it, always remember that no single indicator is perfect or infallible. Successful trading requires continuous learning, adaptability, and robust risk management. Used wisely and in the right context, however, the triangular moving average can be a valuable tool for identifying and riding long-term trends in the market.
Best Apache ECharts Alternative in 2026: When Canvas Hits Its Ceiling
Apache ECharts is an excellent charting library that's the honest starting point, and it's worth saying clearly. Free under the Apache 2.0 license, actively maintained by one of the most active open-source communities in data visualization, with 60,000+ GitHub stars...
Best D3.js Alternatives in 2026: Less Code, More Performance, Same Power
D3.js is the most starred data visualization library in existence 109,000+ GitHub stars and for justifiable reasons. It provides the building blocks to construct any visualization imaginable: data binding, SVG path generation, scale functions, geographic projections,...
Best ApexCharts Alternatives in 2026: Scale Beyond SVG, Add Real 3D
ApexCharts earned its position through a set of genuine strengths executed consistently well: MIT license, the best default visual aesthetics among free JavaScript chart libraries, official and actively maintained React, Vue, and Angular component wrappers, clean...

