Announcement

Collapse
No announcement yet.

getting highs and lows

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

  • getting highs and lows

    How do I get the highs and lows between 2 times of the day?

    I've worked out how to isolate the most recent day and I can isolate the hour and minute using the appropriate functions.

    But, for example, if I wanted to know what the high and low between 09:15 and 10:15 and I'm looking at a chart with an interval of 4 minutes - how do I do that?

    Thanks.
    Standing on the shoulders of giants.

  • #2
    Potential solution.

    you could use a while loop (looping backward) to accomplish this....

    first, you would have to set the DATE and TIME ranges for your scan and establish the DATE variables to run the scan...

    // Setting range of dates and times
    var vstartdate = 11804; // 1/18/04
    var vstarttime = 1100; //11AM
    var venddate = 11804; // 1/18/04
    var vendtime = 1200; //12 noon

    // establishing date variables..
    var vHour;
    var vMin;
    var vSec;
    var vDay;
    var vMonth;
    var vYear;

    next, you need to create variables to hold the HIGH/LOW for your scan...

    var scanhigh = null;
    var scanlow = null;

    the other thing that you would need is a BAR COUNTER - for error checking. Let's say you tell your scan to find a date that does not exist - without error checking - this could hang your esignal app.

    // creating bar counter variables...
    var nLastRawTime = 0;
    var BLBarOffset = 0;

    All of these (above) would be declared outside the main() function...

    Now, within your main() function, you need to add the bar counter function...

    function main() {

    var vTime = new Date();
    //---------------------------------------------------
    // Get Date/Time Variables for current bar
    vTime = getValue("Time", 0);
    vHour = vTime.getHours();
    vMin = vTime.getMinutes();
    vSec = vTime.getSeconds();
    vDay = vTime.getDate();
    vMonth = vTime.getMonth() +1;
    vYear = vTime.getYear();

    if (getValue("rawtime", 0) != nLastRawTime) {
    nLastRawTime = getValue("rawtime", 0);
    BLBarOffset += 1;
    }

    return;
    }

    Now, I would create a function that would accomplish the scan (and pass your date range variables.....

    function fFindDateTimeHighLow(vstartdate,vstarttime,venddat e,vendtime)
    {

    // create necessary logical variables....
    var barpointer = 0; // used to loop backward across the chart
    var continuescanning = true; // logical control variable for our scan
    var temphigh = null; // used to hold our high scanned price
    var templow = null; // used to hold our high scanned price

    while (continuescanning) {

    // Get Date/Time Variables for current bar we're pointing to in our loop
    vTime = getValue("Time", barpointer);
    vHour = vTime.getHours();
    vMin = vTime.getMinutes();
    vSec = vTime.getSeconds();
    vDay = vTime.getDate();
    vMonth = vTime.getMonth() +1;
    vYear = vTime.getYear();

    // creating comparison date/time variables..
    var vcurrentbartime = (vHour*100)+vMin;
    var vcurrentbardate = (Month*10000)+(vDay*100)+vYear;

    if ( (vcurrentbartime <= vendtime) && (vcurrentbartime >= vstarttime) && (vstartdate = vcurrentbardate ) ) {
    // within out date/time range - find high/low
    temphigh = Math.max(temphigh ,high(barpointer));
    templow = Math.min(templow ,low(barpointer));
    }


    if ( (vcurrentbardate < vstartdate) || ((BLBarOffset-barpointer) == 1) ) {
    // beyond our range or at end of data - QUIT.
    continuescanning = false;
    }

    barpointer--;
    } // end of while loop

    // record our highs/lows to our main variables (if they are not == null;
    if ( (temphigh != null) && (templow != null)) {
    scanhigh = temphigh;
    scanlow = templow;
    }

    } // end of function.

    Now, I wrote this off the top of my head, so there might be some errors. But this is the way you want to try to accomplish this task. Others might have another idea of how to accomplish it - but this is how I would do it..

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Hi Brad,

      Many thanks for the comments and the code snippets. You've re-introduced me to some JavaScript functions that I'd forgotten about - thanks.

      I'm going to go off and play with those code snippets and see how I can work them into what I'm doing.

      One of the concepts that I'm struggling with though is that of bars that do not conform to the time period that I want to examine.

      Say, for example, I have a 10 minute chart and I want to find the high price between 11:53 and 12:17

      The 10 minute chart will give me the high and low of each 10 minute bar but will include the time period between 11:50 and 11:53 and also between 12:17 and 12:20.

      Any ideas?
      Standing on the shoulders of giants.

      Comment


      • #4
        you could...

        use getValue to return an array of 1 minute data..

        The only problem with this is there is no date marker for the data returned.. So you would have to extimate the # of minutes back to get the high/low range...

        for example... you're watching a 5 minute chart and it's currently 12 noon... and you want the high/low range from 10:12 to 10:15.

        you would have to calc the difference betweek the two times.. - do this by creating times as # of minutes..

        12 noon would be 720
        10:12 = 612
        10:15 = 615

        difstart = 720-612 = 108 minutes back
        difend = 720-615 = 105 minutes back.

        get it??

        It is a little more complicated - but it can be done..

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Many thanks for the reply Brad. I actually think that this approach is far simpler and a much better way to tackle the problem.

          You comments are much appreciated.

          I've hit a couple of problems when I try to ask for X number of bars but the chart is showing X-n number of bars - that seems to throw an error so I have to work around that as well.

          Many thanks.
          Standing on the shoulders of giants.

          Comment

          Working...
          X