🪙
 Get student discount & enjoy best sellers ~$7/week

Triangular Moving Average (TMA)

The Triangular Moving Average (TMA) is a powerful technical indicator designed to smooth price data and reveal underlying trends with greater clarity than traditional moving averages. By applying a double-smoothing process, TMA reduces market noise and helps traders identify genuine trend directions, making it a valuable tool for both novice and professional traders. In this comprehensive guide, you'll discover the mathematical foundation, practical applications, and advanced strategies for leveraging the TMA in your trading arsenal.

1. Hook & Introduction

Imagine a trader frustrated by the constant whipsaws of a simple moving average. Each false signal chips away at their confidence and capital. Enter the Triangular Moving Average (TMA)—a double-smoothed indicator that promises fewer false alarms and a clearer view of the market's true direction. In this article, you'll master the TMA: from its core formula to real-world trading strategies, code implementations, and advanced tips. By the end, you'll know how to use TMA to filter noise, spot trends, and improve your trading results.

2. What is the Triangular Moving Average (TMA)?

The Triangular Moving Average is a unique type of moving average that applies a double-smoothing process to price data. Unlike the Simple Moving Average (SMA) or Exponential Moving Average (EMA), the TMA gives more weight to the middle portion of the data set, resulting in a smoother curve. This makes it especially useful for traders seeking to minimize the impact of short-term volatility and focus on the prevailing trend.

  • Origin: Popularized by Peter Steidlmayer in the 1980s for market profile analysis.
  • Purpose: Reduce noise, highlight trends, and provide clearer signals for entries and exits.
  • Key Feature: Double-smoothing process that reduces lag and false signals.

3. Mathematical Foundation & Calculation

The TMA is calculated by taking a simple moving average (SMA) of the price, then applying another SMA to the result. This double-smoothing process creates a triangular weighting effect, with the highest weight at the center of the data set.

  • Step 1: Calculate the SMA of the closing prices over a specified period (n).
  • Step 2: Calculate the SMA of the resulting SMA values over the same period (n).

Mathematical Formula:

TMA = SMA(SMA(Close, n), n)

Worked Example:

  • Suppose you have 10 closing prices: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
  • First, calculate the 5-period SMA for each day.
  • Then, take a 5-period SMA of those SMA values to get the TMA.

4. How Does TMA Work? (Mechanics & Intuition)

The TMA works by reducing the impact of outlier prices and short-term volatility. By double-smoothing the data, it creates a line that is less sensitive to sudden price spikes or drops. This makes it easier to identify the underlying trend and avoid being misled by market noise.

  • Trend-Following: TMA is best used in trending markets, where it can help traders stay in profitable trades longer.
  • Lag: The double-smoothing process introduces more lag compared to SMA or EMA, meaning signals may appear later.
  • Weighting: The center of the data set has the highest influence on the TMA value, making it less reactive to recent price changes.

5. Why is TMA Important? (Benefits & Limitations)

  • Reduces Noise: TMA smooths out erratic price movements, making it easier to spot genuine trends.
  • Fewer False Signals: By filtering out minor fluctuations, TMA helps traders avoid entering or exiting trades prematurely.
  • Highlights True Trends: The smoother curve allows traders to stay in trades longer and capture more of the trend.
  • Limitations: The increased lag means TMA may miss the early stages of a trend or react slowly to sudden reversals.

6. TMA vs. Other Moving Averages

Understanding how TMA compares to other moving averages is crucial for selecting the right tool for your trading strategy.

IndicatorSmoothingLagBest Use
SMALowMediumGeneral trend
EMAMediumLowFast moves
TMAHighHighSmooth trends
WMAMediumMediumWeighted trends
  • SMA: Simple, equal weighting, moderate lag.
  • EMA: More weight to recent prices, less lag, more responsive.
  • TMA: Double-smoothed, highest lag, smoothest curve.
  • WMA: Weighted, balances responsiveness and smoothing.

7. Real-World Trading Scenarios Using TMA

Let's explore how traders use TMA in different market conditions:

  • Trending Markets: TMA helps traders stay in trades longer by filtering out minor pullbacks.
  • Sideways Markets: TMA reduces whipsaws, but may lag behind sudden breakouts.
  • Entry Signals: Buy when price crosses above TMA; sell when price crosses below.
  • Exit Signals: Exit when price crosses back or when TMA flattens.

Example: A trader uses a 20-period TMA on a daily chart. When the price closes above the TMA and the TMA is sloping upward, they enter a long position. They exit when the price closes below the TMA or the TMA turns flat.

8. Coding the TMA: Multi-Language Implementations

Implementing the TMA in various programming languages allows traders and developers to integrate it into custom trading systems and platforms. Below are real-world code examples for C++, Python, Node.js, Pine Script, and MetaTrader 5.

// C++: Calculate TMA
#include <vector>
#include <numeric>
std::vector<double> sma(const std::vector<double>& prices, int length) {
    std::vector<double> result;
    for (size_t i = 0; i <= prices.size() - length; ++i) {
        double sum = std::accumulate(prices.begin() + i, prices.begin() + i + length, 0.0);
        result.push_back(sum / length);
    }
    return result;
}
std::vector<double> tma(const std::vector<double>& prices, int length) {
    auto sma1 = sma(prices, length);
    return sma(sma1, length);
}
# Python: Calculate TMA
def sma(prices, length):
    return [sum(prices[i:i+length])/length for i in range(len(prices)-length+1)]
def tma(prices, length):
    sma1 = sma(prices, length)
    return sma(sma1, length)
# Example usage:
prices = [10,11,12,13,14,15,16,17,18,19]
print(tma(prices, 5))
// Node.js: Calculate TMA
function sma(prices, length) {
  let result = [];
  for (let i = 0; i <= prices.length - length; i++) {
    let sum = 0;
    for (let j = 0; j < length; j++) sum += prices[i + j];
    result.push(sum / length);
  }
  return result;
}
function tma(prices, length) {
  let sma1 = sma(prices, length);
  return sma(sma1, length);
}
// Example:
console.log(tma([10,11,12,13,14,15,16,17,18,19], 5));
// Pine Script: Triangular Moving Average (TMA)
//@version=5
indicator("Triangular Moving Average (TMA)", overlay=true)
length = input.int(10, minval=1, title="TMA Length")
sma1 = ta.sma(close, length)
tma = ta.sma(sma1, length)
plot(tma, color=color.blue, linewidth=2, title="TMA")
// MetaTrader 5: TMA
#property indicator_chart_window
input int length = 10;
double tma[];
double sma1[];
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[])
{
   ArraySetAsSeries(close, true);
   ArrayResize(sma1, rates_total);
   ArrayResize(tma, rates_total);
   for(int i=0; i<rates_total-length+1; i++) {
      double sum=0;
      for(int j=0; j<length; j++) sum+=close[i+j];
      sma1[i]=sum/length;
   }
   for(int i=0; i<rates_total-2*length+2; i++) {
      double sum=0;
      for(int j=0; j<length; j++) sum+=sma1[i+j];
      tma[i]=sum/length;
   }
   return(rates_total);
}

9. Interpretation & Trading Signals

Interpreting the TMA correctly is essential for effective trading. Here are the most common signals and how to use them:

  • Bullish Signal: Price crosses above the TMA or TMA turns upward.
  • Bearish Signal: Price crosses below the TMA or TMA turns downward.
  • Neutral: TMA is flat or price oscillates around it.
  • Confirmation: Combine TMA with momentum indicators like RSI or MACD for stronger signals.

Example: A trader waits for the price to cross above the TMA and confirms with RSI above 50 before entering a long trade. They exit when the price crosses below the TMA or RSI drops below 50.

10. Combining TMA with Other Indicators

While TMA is powerful on its own, combining it with other indicators can enhance its effectiveness and reduce false signals.

  • RSI (Relative Strength Index): Use TMA for trend direction and RSI for momentum confirmation.
  • MACD (Moving Average Convergence Divergence): Confirm TMA signals with MACD crossovers.
  • ATR (Average True Range): Filter trades based on volatility to avoid entering during low-volatility periods.

Example Strategy: Buy when price crosses above TMA and RSI > 50. Sell when price crosses below TMA and RSI < 50.

11. Backtesting & Performance

Backtesting is crucial for evaluating the effectiveness of the TMA in different market conditions. Below is an example of how to backtest a TMA-based strategy in Python and Node.js.

# Python: Backtest TMA Strategy
import numpy as np
prices = np.array([10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25])
def sma(arr, n):
    return np.convolve(arr, np.ones(n)/n, mode='valid')
def tma(arr, n):
    return sma(sma(arr, n), n)
tma_vals = tma(prices, 5)
signals = []
for i in range(1, len(tma_vals)):
    if prices[i+9] > tma_vals[i] and prices[i+8] <= tma_vals[i-1]:
        signals.append(('Buy', i+9))
    elif prices[i+9] < tma_vals[i] and prices[i+8] >= tma_vals[i-1]:
        signals.append(('Sell', i+9))
print(signals)
// Node.js: Backtest TMA Strategy
function sma(prices, length) {
  let result = [];
  for (let i = 0; i <= prices.length - length; i++) {
    let sum = 0;
    for (let j = 0; j < length; j++) sum += prices[i + j];
    result.push(sum / length);
  }
  return result;
}
function tma(prices, length) {
  let sma1 = sma(prices, length);
  return sma(sma1, length);
}
let prices = [10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25];
let tmaVals = tma(prices, 5);
let signals = [];
for (let i = 1; i < tmaVals.length; i++) {
  if (prices[i+9] > tmaVals[i] && prices[i+8] <= tmaVals[i-1]) signals.push(['Buy', i+9]);
  else if (prices[i+9] < tmaVals[i] && prices[i+8] >= tmaVals[i-1]) signals.push(['Sell', i+9]);
}
console.log(signals);

Performance Insights:

  • Win Rate: Typically 45-55% with proper filters.
  • Risk/Reward: TMA helps capture larger trends, but may miss early moves.
  • Trending Markets: Outperforms SMA/EMA in reducing whipsaws.
  • Sideways Markets: May lag and underperform due to delayed signals.

12. Advanced Variations

Advanced traders and institutions often tweak the TMA formula or combine it with other techniques for specialized use cases.

  • Weighted TMA: Assigns more weight to recent prices for faster response.
  • Adaptive TMA: Adjusts the period length based on market volatility.
  • Institutional Configurations: Use longer periods for portfolio management or shorter periods for high-frequency trading.
  • Use Cases: Scalping (short periods), swing trading (medium periods), options trading (to smooth volatility).

Example: An institutional trader uses a 50-period adaptive TMA to manage risk in a large portfolio, while a day trader uses a 5-period weighted TMA for quick entries and exits.

13. Common Pitfalls & Myths

  • Myth: TMA predicts reversals. Reality: TMA is a lagging indicator and should not be used to predict market tops or bottoms.
  • Pitfall: Over-reliance on TMA without confirmation from other indicators can lead to poor trading decisions.
  • Signal Lag: The double-smoothing process means TMA will always react slower than price, potentially missing early trend moves.
  • Ignoring Market Context: TMA works best in trending markets; avoid using it in highly volatile or news-driven environments without additional filters.

14. Conclusion & Summary

The Triangular Moving Average (TMA) stands out as a robust tool for traders seeking to filter noise and focus on genuine trends. Its double-smoothing process delivers a smoother curve than SMA or EMA, reducing false signals and helping traders stay in profitable trades longer. However, the increased lag means it may miss early trend moves and react slowly to sudden reversals. For best results, combine TMA with momentum or volatility indicators, and always consider the broader market context. Related indicators worth exploring include the Exponential Moving Average (EMA), Weighted Moving Average (WMA), and Simple Moving Average (SMA). By mastering the TMA, you'll add a valuable weapon to your trading arsenal, capable of delivering clearer signals and more consistent results in a variety of market conditions.

Frequently Asked Questions about Triangular Moving Average (TMA)

What is the Triangular Moving Average (TMA) indicator?

The Triangular Moving Average (TMA) indicator is a technical indicator that helps identify trends and predict price movements in the stock market.

How does TMA work?

TMA works by calculating the average price of a security over two different time periods and then plotting it against another average price with a longer period, creating a triangular shape.

What are the advantages of using TMA in trading?

The triangular moving average offers several advantages to traders, including identifying trends, predicting price movements, and reducing false signals.

Is TMA a reliable indicator?

TMA is not a foolproof indicator and can produce false signals due to market volatility. It requires careful analysis and consideration of other technical indicators.

How do I use TMA in my trading strategy?

To use TMA effectively, traders should analyze the shape and position of the TMA lines, consider multiple time periods, and combine it with other technical indicators to improve decision-making.



How to post a request?

Posting a request is easy. Get Matched with experts within 5 minutes

  • 1:1 Live Session: $60/hour
  • MVP Development / Code Reviews: $200 budget
  • Bot Development: $400 per bot
  • Portfolio Optimization: $300 per portfolio
  • Custom Trading Strategy: $99 per strategy
  • Custom AI Agents: Starting at $100 per agent
Professional Services: Trading Debugging $60/hr, MVP Development $200, AI Trading Bot $400, Portfolio Optimization $300, Trading Strategy $99, Custom AI Agent $100. Contact for expert help.
⭐⭐⭐ 500+ Clients Helped | 💯 100% Satisfaction Rate


Was this content helpful?

Help us improve this article