Announcement

Collapse
No announcement yet.

main() - return value or series?

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

  • main() - return value or series?

    In the tutorials (see "Introductory Tutorial 3") I see examples of the return from main() being a series (eg "return rsi(21);", but most of the function examples return single values (eg they use rsi(21).getValue().

    What is the difference, which is preferable, should I be confused etc?

    Thanks

  • #2
    Hello Dave,

    The particular syntax you posted, rsi(21).getValue(0), does not exist in Tutorial 3. However, that method can also be used, but is not necessary as the EFS2 engine returns the current bar's value of the rsi(21) series for you. It is essentially the same thing as return rsi(21).
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Jason - looks like my "documentation" is as confusing as yours! The "rsi(21).getValue(0)" quote is from the function reference docs, not the tutorial.

      The point I'm trying to make is that it is confusing that the tutorial clearly (and consistently) returns series, but the function reference examples return single values.

      From what you say, I gather that main() is coerced to return single (current) values even if the return statement specifies a series? I didn't see this observation in the specification for main(), perhaps it could be included, hence perhaps saving others time and confusion in the future.

      Comment


      • #4
        a PS - more of a query

        I still don't understand why I might want to return a series from main(), as per the tutorial, but not the function reference examples.

        Now I have found the "getSeries()" function, with a specific example of main() being forced to return a series

        Why is there so much emphasis on returning series in some places and single values on others?

        Thanks

        Dave

        Comment


        • #5
          Hello Dave,

          Returning a value or a series has more to do with the specific needs of the formula in question. In general, it's a matter of preference as to which method you want to use. There are multiple ways to accomplish the same result.

          When you get into plotting series that are based on higher time frames than the chart interval, the getSeries() method forces the plot to be synchronized in real time with the completed bar reference to the higher time frame so that when a formula is reloaded the plot reflects the same result in real time as it will once the real time bars become historical bars. If you plot a higher time frame series without getSeries(), the plotted result reflects what the values of the higher time frame series was at the close of each chart interval, which creates a jagged line plot vs the stair-stepped appearance.

          Run this code on a 1-minute chart for a while and then reload it.

          PHP Code:
          var xMA null;

          function 
          main() {
              if (
          xMA == nullxMA sma(10inv("5"));
              
              return 
          xMA.getValue(0);

          You'll see that in real time the current bars plotting becomes jagged, or non stair-stepped for lack of a better description. When you reload it, it will change the historical plot to the stair-stepped appearance. This happens because the historical processing only processes completed bar data.

          If you don't want the jagged plot and you always want the current real time plot to be stair-stepped, return the series like below.

          PHP Code:
          var xMA null;

          function 
          main() {
              if (
          xMA == nullxMA sma(10inv("5"));
              
              return 
          getSeries(xMA);

          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            OK, that certainly clears up a lot of confusion.
            Thanks again, Dave.

            Comment

            Working...
            X