An anonymous donor requested a cumulative moving average indicator for Think or Swim that could start at a given date (on a daily chart) or start at a chosen time on a specific day for intraday charts. This donor suggested that I share it with everyone else, so here it is!
Basically, the code line:
CMA = totalSum(price)/barNumber()
can be used to get a quick cumulative average of all values on a chart. Kind of like a VWAP, but it’s not weighted by volume at all–each bar’s price value is weighted equally. But what if you want to start at some place inside the chart? You can use “if” statements to assign a new variable that contains “double.nan” if a bar is before your start date/time, and contains price values after the start conditions are met. Then you “totalsum” that variable. You also have to keep track of the bar number when you start recording data, since the first bar isn’t bar#1 anymore.
The indicator I wrote is smart enough to ignore the start time automatically if you are using a daily chart. Here’s a CMA on a daily chart of ES starting on the low day on Mar 6, 2009:
Here’s what it looks like if you start on July 14 2009 at 1030 ET on a 15 min chart:
I also figured out a way to automatically reset the indicator each day for true intraday traders. If you enable this option, it ignores the start date and only cares about the start time (1030 ET in this example):
This indicator is provided free to all through the generosity of a donor (look for “Cumulative_Mov_AvgSTUDY.ts” over on my Google site). Thank you to all of my donors and customers–you are helping me slowly build to a point where I can develop code full time. For now I’m still very much buried under my day job and a few custom software projects, hence the dearth of updates here. Thanks for reading!