Sponsored Indicator: Cumulative Moving Average for Think or Swim

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:

CumMovAvg_Daily

Here’s what it looks like if you start on July 14 2009 at 1030 ET on a 15 min chart:

CumMovAvg_Intraday

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):

CumMovAvg_Reset

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!

Tags: , , ,

9 Responses to “Sponsored Indicator: Cumulative Moving Average for Think or Swim”

  1. Jim Says:

    I am interested in importing a “Vol By Price” overlay into Think or Swim similar as to on stockcharts

    If you can offer any tips or insight into doing this it would be appreciated

    Thanks in advance

  2. Jim Says:

    I am interested in importing a “Vol By Price” overlay into Think or Swim similar as to on stockcharts

    If you can offer any tips or insight into doing this it would be appreciated

    Thanks in advance.

  3. Prospectus Says:

    Until Think or Swim supports it server-side, that’s not really possible, unfortunately.

  4. jenks Says:

    hi, not sure if you are available for this– i do box trades overnight. the problem is I am not aware of automatically having multiple targets and stops that move when the targets are hit. appreciate any thoughts.

  5. Prospectus Says:

    Sorry, I’m not sure what you’re asking about?

  6. jenks Says:

    is there anyway to program this example-

    sellstop 3 es at 870
    buystop 3es at 820

    if es goes to 870, i would want to buy 1 es, and move mt stop from 820 to 870.

  7. Prospectus Says:

    I think you could manually set up a few OCO orders in Think Desktop to handle some of this, but not from the Thinkscript code. At least not yet.

  8. Frank Says:

    I’m looking to import in Ninjatrader your script.

    Is it possible to do so in a programmed C#?

    As i understand your .ts file could be imported, but how?

  9. Prospectus Says:

    It needs to be completely rewritten for Ninja. I’ll put that on my todo list that’s already a mile high.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: