Announcement

Collapse
No announcement yet.

Data from previous bar

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data from previous bar

    How do I get data from the close of the previous bar???

    How do I get data from the close of 2 bars ago???

    Thanks,

    John

  • #2
    xoprofittaker
    That depends on the type of data.
    If it is a series then you can access the value either directly by specifying the bar index within the function eg
    PHP Code:
    var myClose1 close(-1);//the Close at the prior bar
    var myHigh2 high(-2);//the High of two bars ago 
    var myVar3 sma(10,-3);//the value of a 10 period simple MA at three bars ago
    //etc 
    or you can use the getValue(-n) method where -n is the bar index eg.
    PHP Code:
    var myStudy sma(10);//declare and initialize the series
    var myVar1 myStudy.getValue(-1);//retrieves the value of myStudy one bar back
    var myVar2 myStudy.getValue(-2);//the value of myStudy two bars back
    //etc 
    If instead the data is not a series then see this reply to a similar question
    Alex

    Comment


    • #3
      Alexis or anyone else:

      I just can't seem to figure out SERIES data.

      Everytime I think I "get" it, I run into another problem.

      I must have a MENTAL BLOCK.

      I want to be able to define xOPEN, xHIGH, xMIDPOINT, xLOW, and xCLOSE so I can reference values in this manner:

      xMIDPOINT(-1) : previous day's midpoint

      xMIDPOINT(0) : current day's midpoint.

      PHP Code:
      var xInit   false;
      var 
      xMiddle null;

      var 
      xOpen   null;
      var 
      xHigh   null;
      var 
      xLow    null;
      var 
      xClose  null;

      function 
      main( ) {


          if(
      xInit==false){         


               
      xOpen   =  openinv("D") ) ;

               
               
      xHigh   =  highinv("D") ) ;

               
      xLow    =  lowinv("D") ) ;

               
      xClose  =  closeinv("D") ) ;

               
      xInit=true;

          } 
      // xInit 


      var zOpen   xOpen.getValue(0) ;

      var 
      zClose1 xClose.getValue(-1) ;

      var 
      zHigh   xHigh.getValue(-1) ;

      var 
      zLow    xLow.getValue(-1) ;

      var 
      zMid1   rnd( ((zHigh zLow) * .50) , )   ;
      var 
      zGap    rnd( (zOpen zClose1) , 2) ;


      debugPrint"zMid1  xInit   : " zMid1  "\n" ); 
      debugPrint"zGap  xInit   : " zGap "\n" ); 

      return ; 
      // main

      }


      //==rnd will round to N digits.
      function rnd(valueN) {
          var 
      n;
          var 
      mult=1;
          for(
      n=0;n<N;n++) mult*=10;
          
      value*=mult;
          return 
      Math.roundvalue,N)/mult;


      From what I have read, that should create a series.

      It works.

      I am still baffled.

      It is just not INTUITIVE.

      Sometimes, I can create a series that works and sometimes what I code just doesn't work.

      Why doesn't xMidpoint = ( xHigh + xLow) * .50 ;

      Create a series?

      What don't I understand?

      THANKING YOU IN ADVANCE

      Comment


      • #4
        MidPoint

        TRO

        I'm wondering if the definition is

        MidPoint = (H+L)/2; found in the following thread.

        Click here to view post by ckryza

        Also, I'm doing a search on "waist" or "candlewaist". I seem to remember Alex helping out with code for that study...

        Hope this helps.
        kz

        Comment


        • #5
          Re: MidPoint

          Usually, computers multiply faster than they divide .

          That's why I have midpoint = ( h + l ) * .50

          Same as (h + l) / 2, just faster.

          I see the "waist", but I haven't studied that.


          Originally posted by zeller4
          TRO

          I'm wondering if the definition is

          MidPoint = (H+L)/2; found in the following thread.

          Click here to view post by ckryza

          Also, I'm doing a search on "waist" or "candlewaist". I seem to remember Alex helping out with code for that study...

          Hope this helps.
          kz

          Comment


          • #6
            Good to note about multiplying...

            I was mainly pointing out MidPoint with Capital "P" if Case Sensitive is a potential problem.

            kz

            Comment


            • #7
              I finally fiquered out how to do what I wanted to do.

              I wrote the TRO SM MIDDLE study that uses series and calculates the midpoint.

              It's still not clear to me.

              Whoever created JAVA is a SADIST!

              It's not intuitive and it is CASE SENSITIVE... WHAT WERE THEY THINKING?

              Such a waste of time.




              Originally posted by zeller4
              Good to note about multiplying...

              I was mainly pointing out MidPoint with Capital "P" if Case Sensitive is a potential problem.

              I know you'll get to the bottom of it...

              kz

              Comment


              • #8
                Hello Avery,


                Originally posted by buzzhorton
                Alexis or anyone else:

                I just can't seem to figure out SERIES data.

                Everytime I think I "get" it, I run into another problem.

                I must have a MENTAL BLOCK.

                I want to be able to define xOPEN, xHIGH, xMIDPOINT, xLOW, and xCLOSE so I can reference values in this manner:

                xMIDPOINT(-1) : previous day's midpoint

                xMIDPOINT(0) : current day's midpoint.

                PHP Code:
                var xInit   false;
                var 
                xMiddle null;

                var 
                xOpen   null;
                var 
                xHigh   null;
                var 
                xLow    null;
                var 
                xClose  null;

                function 
                main( ) {


                    if(
                xInit==false){         


                         
                xOpen   =  openinv("D") ) ;

                         
                         
                xHigh   =  highinv("D") ) ;

                         
                xLow    =  lowinv("D") ) ;

                         
                xClose  =  closeinv("D") ) ;

                         
                xInit=true;

                    } 
                // xInit 


                var zOpen   xOpen.getValue(0) ;

                var 
                zClose1 xClose.getValue(-1) ;

                var 
                zHigh   xHigh.getValue(-1) ;

                var 
                zLow    xLow.getValue(-1) ;

                var 
                zMid1   rnd( ((zHigh zLow) * .50) , )   ;
                var 
                zGap    rnd( (zOpen zClose1) , 2) ;


                debugPrint"zMid1  xInit   : " zMid1  "\n" ); 
                debugPrint"zGap  xInit   : " zGap "\n" ); 

                return ; 
                // main

                }


                //==rnd will round to N digits.
                function rnd(valueN) {
                    var 
                n;
                    var 
                mult=1;
                    for(
                n=0;n<N;n++) mult*=10;
                    
                value*=mult;
                    return 
                Math.roundvalue,N)/mult;


                From what I have read, that should create a series.

                It works.

                I am still baffled.

                It is just not INTUITIVE.

                Sometimes, I can create a series that works and sometimes what I code just doesn't work.

                Why doesn't xMidpoint = ( xHigh + xLow) * .50 ;

                Create a series?

                What don't I understand?

                THANKING YOU IN ADVANCE
                To create a custom series you have to run it through efsInternal(). When you use variables that contain series objects in a math equation, the EFS2 engine automaticlly retrieves the current values from those series so it can return a number as a result. It was designed this way to make things easier on the novice users.

                xMidpoint = (xHigh.getValue(0) + xLow.getValue(0)) * .50;

                is the same as

                xMidpoint = ( xHigh + xLow) * .50 ;

                which returns a number.

                To create the xMidpoint series do this

                PHP Code:
                function main() {
                    ....
                    if (
                xMidpoint == nullxMidpoint efsInternal("calcMidpoint"xHighxLow);

                    ....
                }

                function 
                calcMidpoint(xHxL) {
                    return (
                xH.getValue(0) + xL.getValue(0)) * .50;

                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


                • #9
                  Thanks Jason,

                  But what I wanted to do was access the previous middle as xMiddle(-1).

                  I just can't seem to figure it out.

                  Nothing about this is intuitive... at least not to me.

                  I can access the data and it's correct.

                  I just want to use the "x(-1)" type of reference instead of "x.getValue(-1)" ... I AM SO CONFUSED.

                  Once it finally sinks in, I know I'll have a good laugh.

                  P.S. The jury is still out on this: "It was designed this way to make things easier on the novice users."

                  PHP Code:
                  var xInit    false;
                  var 
                  xMiddle1 null;

                  var 
                  xMidpoint null;
                  var 
                  xOpen   null;
                  var 
                  xHigh   null;
                  var 
                  xLow    null;
                  var 
                  xClose  null;

                  function 
                  preMain() {

                      
                  setPlotType(PLOTTYPE_SQUAREWAVE ,0);

                      
                  setDefaultBarThickness(2,0);   
                  }

                  function 
                  main( ) {

                      if(
                  xInit==false){         

                           
                  xOpen   =  open(   ) ;
                           
                           
                  xHigh   =  high(   ) ;

                           
                  xLow    =  low(   ) ;

                           
                  xClose  =  close(   ) ;

                           
                  xInit=true;

                      } 
                  // xInit 
                       
                  if (xMidpoint == nullxMidpoint efsInternal("calcMidpoint"xHighxLow);

                  // debugPrint( "xMidpoint.getValue(0) : " + xMidpoint.getValue(0)   + "\n" );

                  xMiddle rndxMidpoint.getValue(0) , )  ;

                  xMiddle1 rndxMidpoint.getValue(-1) , )  ;

                  debugPrint"xMiddle1 : " xMiddle1   "\n" );

                  debugPrint"xMiddle  : " xMiddle  "\n" );

                  return new Array( 
                  getSeries(xMidpoint)  ) ;

                  }

                  function 
                  calcMidpoint(xHxL) {
                      return (
                  xH.getValue(0) + xL.getValue(0)) * .50;
                  }

                  // rnd function - round to iDecimals places
                  function rnd(valueiDecimals ) {  

                  value =  value Math.pow(10iDecimals);

                      return 
                  Math.round(valueiDecimals) / Math.pow(10iDecimals);

                  Last edited by buzzhorton; 08-04-2006, 01:26 PM.

                  Comment


                  • #10
                    Hello Avery,

                    Originally posted by buzzhorton
                    Thanks Jason,

                    But what I wanted to do was access the previous middle as xMiddle(-1).

                    I just can't seem to figure it out.

                    Nothing about this is intuitive... at least not to me.

                    I can access the data and it's correct.

                    I just want to use the "x(-1)" type of reference instead of "x.getValue(-1)" ... I AM SO CONFUSED.

                    Once it finally sinks in, I know I'll have a good laugh.

                    P.S. The jury is still out on this: "It was designed this way to make things easier on the novice users."

                    PHP Code:
                    var xInit    false;
                    var 
                    xMiddle1 null;

                    var 
                    xMidpoint null;
                    var 
                    xOpen   null;
                    var 
                    xHigh   null;
                    var 
                    xLow    null;
                    var 
                    xClose  null;

                    function 
                    preMain() {

                        
                    setPlotType(PLOTTYPE_SQUAREWAVE ,0);

                        
                    setDefaultBarThickness(2,0);   
                    }

                    function 
                    main( ) {

                        if(
                    xInit==false){         

                             
                    xOpen   =  open(   ) ;
                             
                             
                    xHigh   =  high(   ) ;

                             
                    xLow    =  low(   ) ;

                             
                    xClose  =  close(   ) ;

                             
                    xInit=true;

                        } 
                    // xInit 
                         
                    if (xMidpoint == nullxMidpoint efsInternal("calcMidpoint"xHighxLow);

                    // debugPrint( "xMidpoint.getValue(0) : " + xMidpoint.getValue(0)   + "\n" );

                    xMiddle rndxMidpoint.getValue(0) , )  ;

                    xMiddle1 rndxMidpoint.getValue(-1) , )  ;

                    debugPrint"xMiddle1 : " xMiddle1   "\n" );

                    debugPrint"xMiddle  : " xMiddle  "\n" );

                    return new Array( 
                    getSeries(xMidpoint)  ) ;

                    }

                    function 
                    calcMidpoint(xHxL) {
                        return (
                    xH.getValue(0) + xL.getValue(0)) * .50;
                    }

                    // rnd function - round to iDecimals places
                    function rnd(valueiDecimals ) {  

                    value =  value Math.pow(10iDecimals);

                        return 
                    Math.round(valueiDecimals) / Math.pow(10iDecimals);

                    EFS does not have an "x(-1)" option available. That type of syntax does not exist for a custom series established with efsInternal. The proper way to reference previous values of the xMidpoint series is with the xMidpoint.getValue(-1) method.
                    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