Announcement

Collapse
No announcement yet.

A Question

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

  • A Question

    the term (getCurrentBarIndex()==0)

    1 what does it mean
    2 where should it be used
    3 when & how should it be used

  • #2
    1 what does it mean

    It means you have read all historical data (-ve bar indexes) and are now at the most recent.

    2 where should it be used

    Anytime you need to know if all historical bars have been iterated, or anytime you need to know if you are at the most recent bar.

    As new bars complete, the latest bar is always 0, and the last bar that was 0 is now -1. etc...

    3 when & how should it be used

    In many scripts it will never have to be used. For certain scripts you really want to know that you have processed all historical data, or maybe you want to make sure you ignore all data until the most recent bar.

    So:

    if (getCurrentBarIndex == 0)
    return;

    at the start of an efs will make sure your script doesn't do anything until all the historic bars have been processed.

    Garth
    Garth

    Comment


    • #3
      shogun,
      With all due respect to Garth, who obviously knows much more about programming than I do, I think there is an error in that last reply to your question.

      I think he meant to say != 0. For example,
      var vIndex = getCurrentBarIndex();
      if(vIndex != 0) return;

      This should cause the efs to wait until all bars are loaded.

      Bob

      Comment


      • #4
        Bob,

        Thanks - you are, of course, correct.

        Garth
        Garth

        Comment


        • #5
          thanks gspiker / rmclean

          why is it that the following will not run,


          {
          1/ if (getCurrentBarIndex()==0)
          2/ {
          3/ if ((close()>Fast_MA)&&(close(-1)<=prevFast))


          but when i remove line 1/ it runs perfect ,

          your comments have clarified that i don't need line 1/ but i dont see why it will stop the program from running, if i had changed the ()==0) to ()!=0) would that have worked.

          used in the following context it works,

          {
          4/ if (getCurrentBarIndex()==0)
          5/ {
          6/ if ((Fast_MA>Slow_MA)&&(prevFast<=prevSlow))
          Last edited by shogun; 03-22-2004, 10:42 AM.

          Comment


          • #6
            1/ if (getCurrentBarIndex()==0)
            2/ {
            3/ if ((close()>Fast_MA)&&(close(-1)<prevFast))
            With the first line in place the 3rd line will only be evaluated for bar 0. Therefore unless 1 & 3 are both true at the same time you will never execute the code under #3. Whereas if line 1 is commented out, line 3 will run for each historical bar and at anytime in history that #3 is true you will execute the under #3.

            debugPrintln() works really well for debug on this kind of logic.

            debugPrintln(" Index = " + getCurrentBarIndex() + " close = " + close());

            etc...

            Garth
            Garth

            Comment


            • #7
              thanks for your quick replies, you have cleared that up for me , i will take a look at how to use the "debugprintin(),

              Comment


              • #8
                getcurrentbarindex

                Shogun,

                I use this command to determine if we are at the MOST RECENT BAR on the chart. Thus, for your RTDO code, we don't want it to execute trades on PAST BARS - so I use this command to enclose the routines for your entry orders.

                here is a little help

                getCurrentBarIndex() will NOT equal 0 (zero) when the EFS is running on PAST BARS (those where we DON'T want any trading action for RTDO).

                getCurrentBarIndex() WILL equal 0 (zero) when the EFS is running on the CURRENT BAR (where we DO want trading action for RTDO).

                B
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment


                • #9
                  doji3333

                  that explains a side effect i get when i remove "getcurrentbarindex()" . when i load a efs with "DO" attached it throws loads or buy/sell mkt orders through, so it is obviously reading the past bars,

                  Comment


                  • #10
                    another question

                    when building a formula efs and we use the "Strategy" functions normally there is a full stop between "Strategy" & the function

                    ie, Strategy.isLong()

                    but some times it is written without the full stop , why is this & are they both the same ?

                    ie, StrategyisLong

                    here are two examples i have come accross,both seem to perform the same task.

                    1/ (!Strategy.isLong())

                    2/ (!StrategyisLong)

                    note the second does not have the left & right brakets

                    Comment


                    • #11
                      The second example is a boolean variable and not a strategy function. You missed that there is not a period on the second line.

                      Comment


                      • #12
                        "boolean" is one of them words that i just never could understand,

                        i know it means "true or false" but why ?

                        why does 1/ need a period & 2/ does not .

                        or is it just a case of "YES" is the same as "yes" it is just written differently.

                        aarrrrrr

                        Comment


                        • #13
                          To clarify,

                          One is a function call - Strategy.isLong()
                          and the other appears to be a poorly picked variable name - StrategyisLong

                          Poorly picked because it can cause this type of confusion...

                          Garth
                          Garth

                          Comment


                          • #14
                            your only right ,

                            just looked at both formulas and "StrategyisLong" is indeed a variable.

                            thanks.

                            Comment


                            • #15
                              edit - already put together this response, then noticed you had put up new post, I will post anyways, maybe this will help

                              There is a simple explanation. A boolean is either a 1 or a zero. this This cooresponds directly to true or false. If you test a boolean in an if statement.

                              e.g.

                              var tmp = 0;

                              if (tmp){
                              debugPrintln ("boolean true");
                              }
                              else{
                              debugPrintln ("boolean false");
                              }

                              this test with tmp = 0 or tmp = false would write boolean false

                              if tmp = 1 or tmp = true would write boolean true

                              using either 0 or 1 or false and true are synonymous

                              Regarding "why does 1/ need a period & 2/ does not "

                              IMHO 2/ is a bad selection of variable name, because of this confusion. It is a variable, just as tmp is a variable above. you could assign 2/ a value of 365.

                              e.g.

                              var tmp = 100;
                              var = StrategyisLong = 365;
                              debugPrintln (StrategyisLong);
                              debugPrintln (StrategyisLong+tmp);

                              the first output would be 365, the second output would be 465

                              The problem is that it is so close in format to the function used in 1/

                              The function in 1/ returns a boolean value based on trade status associated with the strategy analyzer. If you are using this set of functions and you are in a long trade

                              var = StrategyisLong = 365;
                              debugPrintln (Strategy.isLong());
                              debugPrintln (StrategyisLong);

                              the first output would be true, the second output would be 365
                              Last edited by Guest; 03-26-2004, 08:42 AM.

                              Comment

                              Working...
                              X