Announcement

Collapse
No announcement yet.

Max of opening range

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

  • Max of opening range

    Im trying to capture the high for the first ten bars of an intraday price study. I tried to capture the data using an array and do a math max function, but there seems to be a flaw in my code. I would greatly appreciate any help anyone could offer. Thanks.

    Code is attached
    Attached Files

  • #2
    There are much better programmers than me in these forums, but until one of them posts, maybe my thoughts will inspire you...

    You've got vHigh = max(aMyArray). Doesn't this need a semi-colon at the end of the line? Also, try a semi-colon at the end of the next line. Also, is there a function max() that takes an array as a parameter? Don't you have to say Math.max() and don't you have to give it two, non-array parameters?

    If I were trying to find the high of the first ten intraday bars I would wait until the tenth bar and then call the Donchian Study function. Use getday() != getday(-1) to find the start of a new day and then increment a counter every bar (where getBarState() == BARSTATE_NEWBAR) until you get to the tenth bar. Then vHigh = fMyDonch.getValue(DonchianStudy.UPPER); where you have previously instantiated fMyDonch with a 10 bar lookback.
    Last edited by Foz; 06-25-2004, 03:17 PM.

    Comment


    • #3
      Hello Gregory and Foz,

      Foz, Good reply by the way. To clarify a couple things for you, the ";" at the end of a line is optional. It just tells the JavaScript engine that it has reached the end of a line. It helps speed things up a bit, but not required.

      You are correct about Math.max(). If your interested in the reference material on the Math object, click here.

      Gregory, using the Donchian study in the way Foz described is certainly one way to accomplish this. Or you could try the following. See my notes in the code below.

      PHP Code:
      function main() {
          var 
      vH;
          var 
      vRawTime;
          var 
      vBarTime;
          var 
      vAbsTime;
          var 
      vIndex;
          var 
      vHigh;
          var 
      aMyArray = new Array();

          var 
      nState getBarState();
          if(
      nState == BARSTATE_ALLBARS) {
              
      vLastRawTime null;
              
      vLastValue null;
              
      vInterval getInterval();
              
      vSymbol getSymbol();
              
      vSymbol += ",D";
          }

          
      vRawTime getValue("rawtime");
          if(
      vRawTime == null)
              return;

          
      vRawTime Math.floor(vRawTime RawTime.DAY);

          
      // Start of Performance addition
          
      if(vRawTime != null && vLastRawTime != null) {
              if(
      vRawTime == vLastRawTime) {
                  return 
      vLastValue;
              }
          }


          if(
      vInterval == null)
              return 
      null;

          if(
      vInterval == "D")
              return 
      null;

          
      vBarTime getValue("time");
          if(
      vBarTime != null) {
              
      vAbsTime getPreviousTradingDay(vBarTimevSymbol);
              if(
      vAbsTime == null) return;

              
      vIndex getFirstBarIndexOfDay(vAbsTimevSymbol);
              if(
      vIndex != null) {
                  
      //aMyArray = getValueAbsolute("High", 0, 10, vIndex, vSymbol); 
                  // vIndex above is the bar index for the date (vAbsTime) of the daily interval.
                  // Do the following to get the first bar index of the intra-day chart interval.
                  
      var vIndex1 getFirstBarIndexOfDay(vBarTime); 
                  
      // No need to pass the symbol here, it will use the chart symbol by default.
                  // vSymbol above is set to "Symbol,D" to retreive data from the daily interval.
                  
      aMyArray getValueAbsolute("High"vIndex110);
                  if (
      aMyArray == null) return; // Always do null checks when requesting arrays of data.
                  
      var vHigh aMyArray[0];  // Initialize vHigh to a valid value for the first comparison.
                  
      for(var 110; ++i) {  // Loop through the other 9 array elements to find the max.
                      
      vHigh Math.max(vHighaMyArray[i]);
                  }
                  return 
      vHigh;
              }
          }

      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