SMA Directional Matrix - A New Indicator For Technical Analysis

LuxAlgo
4 min readOct 29, 2020

Today we present a new technical indicator that displays a simple & elegant panel showing the direction of simple moving averages with periods in a user-selected range (Min, Max). The displayed number in the panel is the period of a simple moving average and the symbol situated at the right of it is associated with the direction this moving average is taking.

Pinescript code is shared, you can also find the indicator here.

1. What Is A Simple Moving Average?

Simple moving average (red) using a period equal to 50

The simple moving average is a trend following indicator ubiquitous to most traders, and allows to determine the direction of the current trend as well as determining potential support and resistance points.

In term of digital signal processing a simple moving average is a FIR lowpass filter derived from a weighted sum between past prices inputs and a set of uniform coefficients. The simple moving average of period p can be calculated as follows:

Where Cₜ denote the closing price at time t.

2. Indicator Settings

  • Min : Minimum period of the moving average
  • Max : Maximum period of the moving average
  • Src : Source input of the moving averages
  • Number Of Columns: Number of columns to be displayed in the panel, handy when using a large range of periods.

3. Usage

Looking at the direction of moving averages with different periods is extremely useful when it comes to having information about the short/mid/long term overall market sentiment, and can also tell us if the market is trending or ranging.

Here we use periods ranging from 25 to 50, we can see that shorter moving averages react to the recent upward price variation, longer-term moving averages however are still affected by the overall downward variation you can see on the image. We can as such get information about the presence of potentials divergences, with shorter-term moving averages reacting to the divergence while the longer-term moving averages will still display the direction of the main trend.

As such the indicator can give information about how clean a trend is, with a clean trend being defined as a variation containing no retracements. When our trend contains no retracement, the mid/long term moving averages will all have the same direction, however, when a retracement is present, the midterm moving averages might be affected by it, thus displaying a direction contrary to the main trend.

When the market is ranging we can expect the panel to display an equal number of decreasing/increasing moving averages.

4. Code

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=4
study("SMA Directional Matrix",overlay=true,scale=scale.none)
min = input(14)
max = input(28)
src = input(close)
col = input(4,"Number Of Columns")
transp = input(true,"Transparent Panel")
//------------------------------------------------------------------------------
a(x)=> min(x,100) >= 10 and x < 100 ? 2 : x >= 100 ? 3 : 1
b(x,y)=> a(y) - a(x)
//------------------------------------------------------------------------------
up = "📈"
dn = "📉"
string txt = na
for i = min to max
sym = src - src[i] > 0 ? up : dn
p = tostring(i)
r = b(i,max)
per = r == 1 ? "0"+p : r == 2 ? "00"+p : p
space = (i - min)%col == (col-1) ? "\n" + "\n" : ""
txt := txt + "|" + per + " : " + sym + space
//------------------------------------------------------------------------------
n = bar_index
css = transp ? #00000000 : color.black
tss = transp ? color.gray : color.white
print(txt) =>
var lbl = label.new(n, 1, txt, xloc.bar_index, yloc.price, css,
label.style_label_left, tss, size.normal, text.align_left)
label.set_xy(lbl, n, 1), label.set_text(lbl, txt)
print(txt)

--

--

LuxAlgo

LuxAlgo is the world's largest provider of technical indicators.