+ Reply to Thread
Results 1 to 6 of 6

A not so Simple Moving Average

  1. #1
    Registered User
    Join Date
    05-31-2017
    Location
    florida
    MS-Off Ver
    10
    Posts
    8

    A not so Simple Moving Average

    I have a slightly complex problem I'm trying to figure out in excel. I need a simple moving average, lets say for a period of 3, however, I only want it to average negative or positive numbers in the range. So, in other words, say we're only averaging negatives in this range (-5,-4,-6) we would get a return of -5. But lets say the next number is a positive (-5,-4,-6,3), I still need it to return -5 by completely over looking the positive integers and only looking at the last 3 negative ones. And again, if the range continued to this (-5,-4,-6,3,-8), we should get -6. Is this possible??

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: A not so Simple Moving Average

    NOTE: Formula needs Ctrl + Shift + Enter when completed! I have 20 numbers in A1 to A20 with negative numbers mixed in. In Cell A25 I have the formula: =AVERAGE(IF(A1:A20<0,A1:A20,"")) for the NEGATIVES ( the Less Than 0 portion) and in cell A26 I have =AVERAGE(IF(A1:A20>0,A1:A20,"")). Make sure the CURLY Brackets surround the formula, which you get if you were in a cell Editing one of the above formulas (in A25 or A26) and do the Ctrl + Shift + Enter when completed. I got averages for the LESS Than 0 (Negatives) in cell A25; And Greater Than 0 (Positives) in A26.
    GiVe Me SoMe CrEdiT if this WoRkS for YoU! THx

  3. #3
    Registered User
    Join Date
    05-31-2017
    Location
    florida
    MS-Off Ver
    10
    Posts
    8

    Re: A not so Simple Moving Average

    It works, but not as intended. I need a constant average of the 3 most recent negative or positive numbers in a range. Notice, in my last example (-5,-4,-6,3,-8) the 3 is excluded from the calculation because it is positive and the -5 is excluded from the calculation because it is more than 3 negative integers back in the series of numbers. It's only calculating the average based on the -8,-6,and -4. But I appreciate the effort, and any other help.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,369

    Re: A not so Simple Moving Average

    Try

    Data in column B1 down

    "Helper" in D

    in D1 and copy down

    =COUNTIF($B$1:B1,"<0")

    To get average

    =AVERAGE(IF((D1:D100>=MAX(D1:D100)-2)*(B1:B100<0),B1:B100))


    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

  5. #5
    Registered User
    Join Date
    05-31-2017
    Location
    florida
    MS-Off Ver
    10
    Posts
    8

    Re: A not so Simple Moving Average

    That was a huge help! It still needed some doctoring but here is what was required.

    For the negative aspect: =AVERAGE(IF(($D$1:D9>=MAX(D2:D9)-2)*($B$1:B9<0),$B$1:B9))
    And the positive aspect: =AVERAGE(IF(($E$1:E3>=MAX(E2:E3)-2)*($B$1:B3>0),$B$1:B3))

    Now, it's just a matter of applying it to inter day trading data (Open, High, Low, Close) per a five minute chart. And then finally applying it to an actual trading platform to graph it out in real time. By all means, if anyone is interested in helping with this little project, contact me personally. If it works well, it'll be the only technical indicator of its kind.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,369

    Re: A not so Simple Moving Average

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Simple Moving Average Bottom Up Instead of Top Down; Newest Date at top
    By rmccain in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-22-2016, 07:32 PM
  2. Replies: 1
    Last Post: 10-20-2014, 03:20 PM
  3. [SOLVED] Help Calculating A Simple Moving Average
    By artiststevens in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-13-2013, 11:40 PM
  4. [SOLVED] Moving average/average function/adjustable length
    By Lv27 in forum Excel General
    Replies: 3
    Last Post: 08-16-2012, 09:43 AM
  5. Simple Moving Averages & VB Coding
    By ashleys.nl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2012, 08:34 PM
  6. Charts 5 day moving average, 10 day moving average
    By monalisa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2008, 09:50 PM
  7. Moving average of a moving average in the same cell
    By philroberts1983 in forum Excel General
    Replies: 8
    Last Post: 09-16-2008, 07:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1