Announcement

Collapse
No announcement yet.

Odd Bars Give Odd Data

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

  • Odd Bars Give Odd Data

    Okay, this may be a strange question, but I've gotta ask someone who has a little more experience than me.

    I'm writing a program that's concerned with the way the market behaves for an hour at a time. More specifically, the high and the low during an hour. That's all fine and good and works perfectly if the chart I'm using breaks the bars up into a number that starts and ends on the hour.

    Let me give an example to demonstrate my problem. Let’s say I'm using a 13 minute chart and I want the high and low between 11:00 and 12:00. The nearest bar to 11:00 is actually 11:03 and the nearest to 12:00 is actually 12:08. And let’s say that at 12:05 the stock actually went higher than it had been for the whole previous hour, but I don't want that value because I'm only interested in the values between 11:00 and 12:00. (The same problem happens at the beginning as the end of the hour).

    So I'm wondering if there's anyway to break down the time, no matter what chart I'm on, and only use the values in the time frame that I'm concerned with.

    Thanks for any ideas.
    ALP

  • #2
    Possible Solution..

    I believe you would have to pull the needed data as an ARRAY - or series of arrays..

    If you are on a 13 minute chart and wanted to get the 1 hour high/low range from 11AM to 12PM, you would need to build an array of 1 minute data (going back far enough in time to get the time range you want), then rebuild the high/low data.

    I don't believe there is an easier way to accompish this. Below if the "getValue()" function that you would need to use to collect the data. You might want to check out "arrays of structures" to simplify managing the array of data..

    B
    -------------------------------------------------------------------------

    getValue( barType [, nOffset] [, nNumBars] [,Symbol] )

    Returns a data series value or values RELATIVE to the bar currently being built.


    · barType: "Open", "High", "Low", "Close", "Time", "rawtime", "Volume", "oi", "year", "month", "day", "hour", "minute", "second"
    · nOffset: Offset from the "relative" bar. The relative bar is maintained by the formula engine. It is the index of the bar currently being computed.
    · nNumBars: Number of bars to return
    · Symbol: The symbol for which to return data. Symbol may have an Interval suffix (e.g., "IBM,5")

    Examples:

    var vValue = getValue( "open", 0 ); //returns the current bar's open value

    var vValue = getValue( "open", 0, 1 ); //ditto

    var vValue = getValue( "close", -1 ); //get the previous bar's close

    var vValue = getValue( "high", -7 ); //get the high from 7 bars ago

    var aValues = getValue( "close", 0, -10 ); //fills array aValues with the 10 most recent closes.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Okay, I like your idea, but I don't understand how to use getValue() to get 1 minute data. I mean, it seems to me that if I'm on a 13 minute chart and I request an array of past data, it's going to give me 13 minute data.

      Can I get some more clarification please?

      Comment


      • #4
        Here is an example..

        First, if you only need the new data EVERY HOUR, then only run this routine on NEW HOURS.

        The first thing you want to do it get the DATE, HIGH and LOW information for AT LEAST the past hour... so, you need to create a function to handle this...

        Now, you have all of the data in three arrays.. Next, you need to loop thru the arrays to calculate the 1 hour high/low.

        PHP Code:
        function fGetLastHourHighLow(vstarthour) {
          var 
        tempSymbol ""+getSymbol()+",1";

        var 
        tempDATEValues getValue"hour"0, -90tempSymbol  ); //fills array aValues with the 90 most recent DATE STRUCTURES for CURRENT SYMBOL on a 1 minute chart.

        var tempHIGHValues getValue"high"0, -90tempSymbol  ); //fills array aValues with the 90 most recent HIGHS for CURRENT SYMBOL on a 1 minute chart.

        var tempLOWValues getValue"low"0, -90tempSymbol  ); //fills array aValues with the 90 most recent LOWS for CURRENT SYMBOL on a 1 minute chart.

        //  now, we're going to loop thru the data to get what you need
        vTempHigh 0;
        vTempLow 9999999999999;
        var 
        0;  
        var 
        CompletedFunction false;


          if (
        tempDATEValues.Length 0) {   //  valid data in arrays
           
        while ( (!CompletedFunction) && (<= (tempDATEValues.Length -1) )  ) {
               if (
        tempDATEValues[x] == vstarthour) {
                  
        // this array element matches our target HOUR.
                  
        vTempHigh  Math.max(vTempHightempHIGHValues[x]);
                  
        vTempLow  Math.min(vTempLowtempLOWValues[x]);
               }

               if (
        tempDATEValues[x] > vstarthour) {
                  
        // this array element is BEYOND our target HOUR.
                  
        CompletedFunction true;
               }
               
        += 1;
            }
          }



        once this function is completed, you should have your 1 hour HIGH/LOW values stored within..

        vTempHigh
        vTempLow

        Let me know if you need more help..

        B
        Last edited by Doji3333; 01-16-2006, 01:26 PM.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          First, thank you for all your help.

          I'm having difficulty with getValue returning the right information. I would have never thought to change the symbol to +",1" but when I do this, the hour changes.

          If I call:
          var tempSymbol = ""+getSymbol()+",1";
          var vTime = getValue("Time");
          var vTimeSymbol = getValue("Time", tempSymbol);
          debugPrint("vTime: "+vTime+"\nvTimeSymbol: "+vTimeSymbol+"\n");

          Then I get:
          vTime: Fri Jan 13 2006 11:03:00 ...
          vTimeSymbol: Fri Jan 13 2006 16:25:00 ...

          This same error is occurring with a call to "hour" and I'm not sure how to correct it. I thought the time should be the same, but apparently changing the chart to a 1 minute changes how the bars count or something.

          Any insight?

          Comment


          • #6
            Here is some sample code..

            I believe the only limitation is this MAY NOT work for historical data, but should work for RT data (as the chart builds)..

            You can see I've added some debug lines to try to find out what's going on and I believe the problem is related to when it pulls the data.

            Give it a try on RT data and see what happens..

            B
            Attached Files
            Brad Matheny
            eSignal Solution Provider since 2000

            Comment


            • #7
              Hello ALP,

              There's another way to solve this problem utilizing the multiple-interval synchronization (i.e. inv() ) feature built into the new EFS2 engine. By setting up your time template with a 60-minute interval where the start and end time is set to 00:00, you can let the EFS2 engine do the synchronizing for you so that all you have to do is reference the 60 minute interval through the data series calls. Try the following code.

              PHP Code:
              function preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("Last Hour H/L");
                  
              setCursorLabelName("LH High"0);
                  
              setCursorLabelName("LH Low"1);
                  
              setDefaultBarFgColor(Color.blue0);
                  
              setDefaultBarFgColor(Color.red1);
              }

              function 
              main() {
                 return new Array (
              high(0inv(60)), low(0inv(60)) );



              Set up your time template with the following settings for the 60-minute interval. The reason you need to set it up this way is so that each 60-minute window begins and ends right on the hour. Otherwise, the 60-minute bar would start at the bar time of your first 13 minute bar, which might be on the half hour (i.e. 07:30).

              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


              • #8
                Limited working

                Okay, so now that I actually have live data again (after a holiday weekend) I tested it. I had to tweak it a bit because I actually needed to be able to set the minutes as well as the hour. Oh, and it's actually ".length" not ".Length".

                Anyway, it did work. It really kills me that it won't work for history though. I mean, sure the most important data is the live stuff, but it'd be really useful to use this function on past data. Any other suggestions?

                ...Jason, I just saw your response. I'll give it a try, thanks.

                Comment

                Working...
                X