Announcement

Collapse
No announcement yet.

Why doesn't this work?

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

  • Why doesn't this work?

    Hello,

    I want to display the moving average of the last five 60 minute highs on a 5 minute chart.

    I thought this would work:

    vEMA = ema(5, high(0, 60));

    but it doesn't. It display's nothing at all.

    Help please. Thank you.

  • #2
    Re: Why doesn't this work?

    BerkoBob
    It does not work because the syntax you are using is incorrect.
    See this thread for a complete set of examples on how to use the efs2 functions
    FWIW similar examples are also available in the EFS KnowledgeBase articles relative to each study
    Alex


    Originally posted by BerkoBob
    Hello,

    I want to display the moving average of the last five 60 minute highs on a 5 minute chart.

    I thought this would work:

    vEMA = ema(5, high(0, 60));

    but it doesn't. It display's nothing at all.

    Help please. Thank you.

    Comment


    • #3
      Thank you Alexis - as usual - it works.

      I used the EFS2 Toolbox in the EFS editor so I don't know why it gave me the wrong syntax. I guess I used it incorrectly.

      Now that I have my correct syntax,

      vEMA = ema(5, high(inv(60)));

      do I need to execute this statement for each iteration i.e. in main() or should it be set just once i.e. in preMain()?

      I'm still not clear on how these objects work.

      Thanks again Alexis.

      Comment


      • #4
        BerkoBob

        do I need to execute this statement for each iteration i.e. in main() or should it be set just once i.e. in preMain()?
        You do not need to execute that statement on each iteration and although you could initialize it in preMain I would suggest initializing it once only in main either at BARSTATE_ALLBARS eg
        PHP Code:
        if(getBarState()==_BARSTATE_ALLBARS){
            
        vEMA ema(5high(inv(60)));//note vEMA should be a global variable

        or using some initialization routine such as
        PHP Code:
        if(!bInit){//where bInit is declared globally and set initially to false
            
        vEMA ema(5high(inv(60)));//note vEMA should be a global variable
            
        bInit=true;

        At that point you can call the values of this series using the .getValue() method of the series object eg vEMA.getValue(0) for the value of the current bar vEMA.getValue(-1) for the value of the previous bar etc
        Alex


        Originally posted by BerkoBob
        Thank you Alexis - as usual - it works.

        I used the EFS2 Toolbox in the EFS editor so I don't know why it gave me the wrong syntax. I guess I used it incorrectly.

        Now that I have my correct syntax,

        vEMA = ema(5, high(inv(60)));

        do I need to execute this statement for each iteration i.e. in main() or should it be set just once i.e. in preMain()?

        I'm still not clear on how these objects work.

        Thanks again Alexis.

        Comment

        Working...
        X