Announcement

Collapse
No announcement yet.

Displaying MAs of different timeframes

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

  • Displaying MAs of different timeframes

    How can I display an exponential MA of one timeframe on a chart of another timeframe?

    For example, displaying a 15-min 8EMA on the 1-min chart.

    I tried modifying the code of Library/ema.efs where I've changed the symbol for the getValue() routine and that doesn't seem to want to print on the chart.

    If I set the symbol to "ES M5,1", it prints fine. Setting to "ES M5,15" does not print.

    Thinking that getValue may get confused because the 15-min candle may not have closed on the 1-min chart, I also tried with the offset set to -1, but that didn't work either.

    Is there a reason this would not be possible?

    Michael
    ---------------------
    Here's the code:

    /************************************************** **************************************************
    Copyright © eSignal, a division of Interactive Data Corporation. 2002. All rights reserved.
    This sample eSignal Formula Script (EFS) may be modified and saved under a new
    filename; however, eSignal is no longer responsible for the functionality once modified.
    eSignal reserves the right to modify and overwrite this EFS file with each new release.
    ************************************************** ************************************************** */
    function preMain() {
    setPriceStudy(true);
    }

    var dLastMA = 0.0;
    var dThisMA = 0.0;
    var dPercent = 0.0;
    var dCount = 0;
    var bPrimed = false;


    function main(nInputLength) {
    if(nInputLength == null)
    nInputLength = 8;

    var nBarState = getBarState();
    var i;
    var dValue;
    var dSum = 0.0;

    if(nBarState == BARSTATE_ALLBARS) {
    // reset!
    dPercent = (2.0 / (nInputLength + 1.0));
    dLastMA = 0.0;
    dThisMA = 0.0;
    dCount = 0;
    }

    if(nBarState == BARSTATE_NEWBAR) {
    dLastMA = dThisMA;
    }
    dThisMA = dLastMA;

    if(bPrimed == false) {
    dValue = getValue("Close", 0, -nInputLength, "ES M5,15");
    if(dValue == null)
    return;

    for(i = 0; i < nInputLength; i++) {
    dSum += dValue[i];
    }

    dLastMA = dSum / nInputLength;
    dThisMA = dLastMA;

    bPrimed = true;
    } else {
    dValue = getValue("Close", 0, -1, "ES M5,15");
    if(dValue == null)
    return;

    dThisMA = (dValue - dLastMA) * dPercent + dLastMA;
    }


    return dThisMA;

    }

  • #2
    Michael
    FYI the code you posted works (see first image below). However the resulting plot is not synchronized to the 1 min by time stamp but by bar index. You would need to add all the time synchronization logic yourself.
    Multiple intervals/symbols are one of the main features provided by the new version of the EFS language called EFS2 and available with version 7.9. With EFS2 you would not need to worry about the synchronization as the formula engine takes care of all that. An efs written using the new EFS2 functions would return the plot shown in the second image below.
    Alex



    Comment


    • #3
      Alex,

      Thanks for the quick response.

      Michael

      Comment

      Working...
      X