Announcement

Collapse
No announcement yet.

Two questions

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

  • Two questions

    Apparently getCurrentBarIndex() returns the index of the bar currently being computed. What does the "index" mean? Is it related to the Show Bar Index optionh in the Cursor Window Properties box?

    The example following the above definition is:
    nBarIndex = getCurrentBar Index();
    if (nBarIndex != 0) return;

    which leads to my 2nd question..
    Does return have two meanings, as in
    1. at the end of an efs, to Return a value to the chart, and
    2. to define the end of a 'subroutine' and return the program flow to another point? In which case how can one tell where in the efs one is returning to?

    Thanks
    shaeffer
    (alias crosseyed after a weekend trying to decode efs's)

  • #2
    Hello shaeffer,

    Your understanding of getCurrentBarIndex() is correct. It is the same number that you see in the cursor window if you have the Show Bar Index option turned on.


    nBarIndex = getCurrentBar Index();
    if (nBarIndex != 0) return;

    Adding this to a formula tells the formula to do nothing unless the chart is processing real time data on bar index 0. If your formula is using setComputeOnClose(), then you would need to change it to,

    if (nBarIndex < -1) return;


    The return statement has one meaning except when it is used in the main() function. It can be used at the end of any user-defined function to return a value to the function where it was called from or simply return to the function to continue processing. When it's used in main, return is used to return any values you're plotting to the advanced chart. Many formulas use return to end processing if a variable fails some validation check, like a null check. In that case is returns null to the chart, which doesn't plot anything.

    if (close(-1) == null) return;
    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
      If I

      dd=getCurrentBarIndex()
      debugPrintln(dd)

      I only get 7 lines in the debug windo consiting of
      0
      0
      0
      0
      0
      -1
      -2
      -3

      in that order.

      The chart has about 24 bars of data.

      Am I missing something?

      Comment


      • #4
        Hello David,

        I'm not seeing any problem with that code on my end. Is your code snippet inside any other code block that may be restricting its execution? Do you have any other formulas running that are calling debugClear() by chance?
        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

        Working...
        X