Loading…

Triangular And Sine Weighted MA

Most common moving averages weight one end of the look-back window more heavily: a Linear Weighted MA leans on the newest bar, a plain SMA weights every bar equally. A centre-weighted average instead puts the most weight on the middle of the window and tapers toward both ends, which produces a noticeably smoother curve with fewer small wiggles - useful for reading the shape of a move rather than its most recent tick. This indicator plots two different constructions of that same idea: Triangular MA - built the standard published way, as a simple average of simple averages: SMA(SMA(Price, N1), N2), with N1=N2 for an odd period and N1=N/2+1, N2=N/2 for an even period. Nesting two flat averages this way produces a linearly tapering (triangular) weight distribution without ever building the weights by hand. Sine Weighted MA - built with explicit weights following one arch of a sine curve: w(k) = sin(pi*(k+1)/(N+1)) for k=0..N-1, normalised so the weights sum to 1. A sine arch tapers smoothly rather than linearly, giving slightly more emphasis to the true centre bars than the triangular construction does. Plotted side by side, the two make it easy to see how much the exact taper shape matters versus how much of the smoothing is simply "not an SMA and not an LWMA." Notes and limitations - Both averages are centre-weighted, so neither reacts to the very latest bar as quickly as an SMA or LWMA of the same nominal period - this is the intended trade-off for the smoother curve, not a defect. - The Triangular MA is computed as a direct nested double average each bar (no persisted intermediate array), which costs roughly O(N^2/4) work per bar - fine for the typical periods this indicator is meant for, but very large periods will visibly slow a full-history recalculation. - Needs slightly more than InpPeriod bars of history before the first bar is plotted, since the Triangular pass's two nested windows overlap by one bar for an even period. - Does not repaint - each closed bar's values are fixed once computed.

Indicator · MT4 · v1.0 · Free

About Triangular And Sine Weighted MA

Triangular And Sine Weighted MA is an indicator for MetaTrader 4. It has 2 settings, such as Period and Applied price. MQL source code included.

Files in the download: TriangularSineMa.mq4, TriangularSineMa.txt.

Settings

SettingDefaultWhat it does
Period14Period (N)
Applied pricePRICE_CLOSEApplied price

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Moving Average · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria