Skip to content

Tutorial 190 | Markplex Centered Moving Average Envelope

T190-1

Tutorial 190 (based on tutorial 174) demonstrates how to write Markplex’s version of the Centered Moving Average (CMA) Envelope using TradeStation EasyLanguage. A centered moving average is placed at the center of the time period it is averaging rather than the end of it. This positions the moving average values at their central positions in time.

A disadvantage of the CMA is that because the values are displaced there are a number of bars at the end of the chart where there are not a sufficient number of future bars to calculate the average.

This tutorial demonstrates one approach to estimating the average for the last bars by replacing “missing” bars with the price of the last bar and then re-calculating and re-plotting the last few bars whenever the close is updated. The earliest bar of the estimate remains on the chart after a new bar develops.

When Length is an even number (i.e. there is a no bar that is in the center of the length) the plot is plotted one bar later. For example, if Length is equal to 10 and it is the last bar on the chart, the plot for the center moving average is made 4 bars ago and 4 estimated values are calculated and plotted
X
9 8 7 6 5 4 3 2 1 0
Where 0 is the last bar on the chart, 1 is the one before it etc. If the length were 11, the CMA is plotted around the center bar:
X
10 9 8 7 6 5 4 3 2 1 0

i.e. 5 bars on either side of the center bar.

Technical lessons

Technically, the tutorial program is very simple. It demonstrates more advanced uses of the Plot statement and a simple way of estimating the average.
T190-user-inputs
Link
Tutorial 190 applied to a 1 minute @ES chart. Length set to 30
Tutorial 190 applied to a 1 minute @ES chart. Length set to 30
Tutorial 190 applied to a Renko chart
Tutorial 190 applied to a Renko chart

Explanation of tutorial 190

Free Gold Pass download of the tutorial 190 code

If you are a Gold Pass member you can download the tutorial 190 programs for free. (Make sure that you are logged into Gold Pass): This content is for members only.
Hopefully you can understand this tutorial and replicate it for your own use and education. If you want to save some time typing in the code then the Tutorial 190 indicator AND the Tutorial 174 are available for  IMMEDIATE download for $24.95  by clicking the following ‘add to cart’ button. 

The tutorial is compatible with MultiCharts.

PART 2 Plotting when price crosses the upper or lower lines

Version 2 retains the features of the first version but adds the ability to show when a price bar has gone above the top line, or below the lower line.

For historic bars, the high ( HalfAvLen – 1 ) bars ago is compared with the just calculated moving average plus the adjustment amount, i.e. Average( PriceHi, Length ) * ( 1 + AdjPercAbove / 100 ). If it is greater then a dot is plotted at te high of the bar. The low ( HalfAvLen – 1 ) bars ago is compared with Average( PriceLo, Length ) * ( 1 – AdjPercBelow / 100 ) / Length. If it is Lower a dot is plotted at the low of the bar.

For bars in the estimated period, which are constantly changing, the estimated average is constantly recalculated for each bar in the estimated period. If a high of a bar is above the high average value a dot is plotted and similarly if the low of a bar is below the Low average value.

Some dots are plotted and subsequently are not valid. Since we cannot use a NoPlot() statement for historic bars, the color of the dots are changed to transparent using syntax such as the following: Plot6[HalfAvLen – 1 – Ctr]( L[HalfAvLen – 1 – Ctr], “EstXLo”, Transparent );

Explanation of tutorial 190 PART 2

Free Gold Pass download of the tutorial 190 PART 2 code

If you are a Gold Pass member you can download the tutorial 190- PART 2 program for free. (Make sure that you are logged into Gold Pass): This content is for members only.
T190-part2
Untitled ProjectT190-PART2

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.