Announcement

Collapse
No announcement yet.

Help with programming first indicator

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

  • Help with programming first indicator

    Hi,

    I am trying to code a two line indicator (Blau's Ergodic - I found the ECO.efs formula, but I have a different version I want to use). I have read the introductory PDFs and looked at some examples. However, I get errors in my few lines of code. My guess is that my errors are so basic that they will jump out at anyone with experience. Here is the efs code as it appears in main(). The preMain() function simply indicates it is not a price study and to draw it as a line.

    var mtm = close() - close(-1);
    var ergodic = (100 * (ema(5, ema(34, mtm)) / ema(5, ema(34, Math.abs(mtm))), 5));
    return ergodic;

    I get two errors -- first, that the second argument to the ema function, mtm, is incorrect. The variable mtm is simply meant to be a given bar's close minus the prior bar's close. Is there a reason that won't work as the second arg, or that an ema of an ema of mtm wouldn't work?

    Second, abs is reported to be an unknown function, however, Math.abs shows up as a valid auto-complete and in the javascript documentation.

    I'm new with efs, so this is probably simple stuff for someone. I'd appreciate help that anyone might be able to provide such that I can work with this. Thanks!

    Regards,

    Gordon

  • #2
    Re: Help with programming first indicator

    Hi,

    There are a number of issues here because you are taking moving average of moving averages. But, note the syntax for ema:

    ema( length [, source | sym() | inv()] [, barIndex] )

    Your error "the second argument to the ema function, mtm, is incorrect" is likely referring to the part of code

    ema(34, Math.abs(mtm))

    So the second parameter needs to be a source, eg. high(), or symbol or interval or a bar index which needs to be negative. Math.abs(mtm) is none of those.

    Also, you cannot simply divide series like this. You need to initialize the series in a bInit routine, for example

    if ( bInit == false ) {

    myStudy1 = ema( 20 );
    myStudy2 = sma( 10 );
    myStudy3 = wma( 40 );

    bInit = true;

    }


    and create functions to feed the series data in. I am being vague here because your code would need some work but there are samples of this done by Jason and Alex on the forums that show you how to manipulate (eg. difference) series. Just do a little search and you will find them. Also look at efsExternal() and efsInternal().

    Hope this helps.

    Regards,
    Jane



    Originally posted by gordonwrose
    Hi,

    I am trying to code a two line indicator (Blau's Ergodic - I found the ECO.efs formula, but I have a different version I want to use). I have read the introductory PDFs and looked at some examples. However, I get errors in my few lines of code. My guess is that my errors are so basic that they will jump out at anyone with experience. Here is the efs code as it appears in main(). The preMain() function simply indicates it is not a price study and to draw it as a line.

    var mtm = close() - close(-1);
    var ergodic = (100 * (ema(5, ema(34, mtm)) / ema(5, ema(34, Math.abs(mtm))), 5));
    return ergodic;

    I get two errors -- first, that the second argument to the ema function, mtm, is incorrect. The variable mtm is simply meant to be a given bar's close minus the prior bar's close. Is there a reason that won't work as the second arg, or that an ema of an ema of mtm wouldn't work?

    Second, abs is reported to be an unknown function, however, Math.abs shows up as a valid auto-complete and in the javascript documentation.

    I'm new with efs, so this is probably simple stuff for someone. I'd appreciate help that anyone might be able to provide such that I can work with this. Thanks!

    Regards,

    Gordon

    Comment

    Working...
    X