Announcement

Collapse
No announcement yet.

Histogram on 2 moving averages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Histogram on 2 moving averages

    Hi all,

    I am trying to plot a histogram showing the difference between 2 moving averages, a 20-bar weighted ma of the close and a 20-bar weighted ma of the midpoint (H+L/2).

    Now I know that basically that's what an MACD is for, but I can't seem to do it with an MACD study because the MACD edit studies function assumes the same source for both averages (usually Close). What I'm trying to do is plot a difference between not only two different ma's but two different types of ma.

    There's got to be a really simple way to do this but I'm darned if I can figure what it is...

    Any ideas?

    Thanks in advance for any help!

    Veda

  • #2
    Veda
    Here is a basic example of what you would need to do.
    In the main function declare the two moving averages using the appropriate Moving Average functions eg
    PHP Code:
    var myAvg1 wma(20);
    var 
    myAvg2 wma(20,hl2()); 
    Once you have done that run a null check on the current value of each. This will prevent the efs from returning invalid results while the averages are priming.
    PHP Code:
    if(myAvg1.getValue(0)==null || myAvg2.getValue(0)==null) return; 
    At that point in the return statement subtract the value of one average from the other
    PHP Code:
    return (myAvg1.getValue(0) - myAvg2.getValue(0)); 
    All you need to do is add a preMain function in whch you will define the Cursor Window label, the color and type of plot, etc
    For some more details on the syntax of the efs2 functions used in the example and a basic efs template to write the script see this thread
    Alex


    Originally posted by vedaball
    Hi all,

    I am trying to plot a histogram showing the difference between 2 moving averages, a 20-bar weighted ma of the close and a 20-bar weighted ma of the midpoint (H+L/2).

    Now I know that basically that's what an MACD is for, but I can't seem to do it with an MACD study because the MACD edit studies function assumes the same source for both averages (usually Close). What I'm trying to do is plot a difference between not only two different ma's but two different types of ma.

    There's got to be a really simple way to do this but I'm darned if I can figure what it is...

    Any ideas?

    Thanks in advance for any help!

    Veda

    Comment

    Working...
    X