Skip to Content

Moving Average Crossover Suite

January 15, 2026 by
Moving Average Crossover Suite
Al-Juarismi-Lab

TradingView® Thinkorswim®

Description of the indicator.

This indicator, called «Moving Average Crossover Suite» is the classic moving average crossover indicator. For both PineScript and ThinkScript, it considers all types of moving averages available in each language. As is well known, this indicator, whether using two or three moving averages, of the same or different types, has been extensively mentioned in the literature on the subject, especially in Technical Analysis of the Financial Markets and in The Visual Investor, both by John Murphy.

First, it should be said that the code was not developed from scratch, but rather it was based on the functional code already written for both programming languages. As a contribution, color was added to the area and to the moving averages to enhance visual readability, as well as preconfigured alerts to improve performance. Of course, it goes without saying that it respects the principle that the separation between both averages tends to widen when the trend is stronger and to narrow when the opposite occurs.

Explanation of the code.

Block 5-9: We define the input variables using the input indication, which correspond to the type of price, the type of moving averages, and their sizes or periods.

Block 11-29: For didactic reasons, this script includes a block of code that fills the color between both moving averages regardless of which one has been declared as the fast or the slow, that is, it prevents visual errors in the colors by giving them relative assignments, both to the moving averages: Ma1, Ma2, and to their sizes: AvgType1, AvgType2. The reader will be able to easily solve a similar problem they encounter by recycling this code into their own code. Basically, the solution is based on changing the absolute allocation of the averages and their periods to relative allocation based on the logical condition of superiority or inferiority when being drawn on the chart. In fact, the last two lines of the code in this block plot them as a result.

Block 31-37: In this part of the code, the assignments that all our graphic elements will take are simply established, as has been pointed out in previous codes. It can be stated that the DefineGlobalColor function is suitable if we want the user to be able to change the color of the area from the study settings.

Block 39-42: In this section, the logical rules that the colors in the price chart must follow are simply defined, both for the averages and the area between them.

Block 44-45: We conclude by declaring two alerts, one for upward crossings and another for downward crossings, using the pre-built Alert function, whose parameters are, first the logical condition, then the notification text, the alert location, and the sound to be played when executed.

PineScript [TradingView®]:

ThinkScript [Thinkorswim®]:

Share