Announcement

Collapse
No announcement yet.

How to access specific time bars

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

  • How to access specific time bars

    I need to read a number of previous days bars for the same time period. For example, all the 9:30 bars on a 5 minutes chart for the past 20 days, then all 9:35 bars, then all 9:40 bars...
    The goal is to calculate volume averages for specific time periods for $TVOL so that I can see where actual trading volumes stand relative to the averages at any given point of the day.

    So far the only time functions I've found are getPreviousTradingDay() and getFirstBarIndexOfDay() but those don't let me access bars for a specific date and time, just the first bar for the previous or next day.

    One way to work around this is to count the number of bars in the chart for the previous day (which is a complete day for sure) and then work with bars offsets to move around days. But then again, how do I know what's the last bar index for the previous day?

    // This gives the first bar
    var startBar = getFirstBarIndexOfDay(getPreviousTradingDay());

    // Get the last bar, how to do this? no getLastBarIndexOfDay()...
    //var endBar = getLastBarIndexOfDay(getPreviousTradingDay());

    var BarsInOneDay = endBar - startBar;
    var acc = 0;
    for( i = 1; i <= 5; i++ ) {
    // get all bars for the same period i days ago
    acc += close(-BarsInOneDay*i);
    }

    // Return time-specific MA
    return(acc/5);

  • #2
    There are 12 5 min bars per hour, and 6.5 hrs in a day,

    so volume(12*6.5); is the bar from this time yesterday.

    To get the previous days volume, i would look at

    volume(2*12*6.5) etc.

    Comment


    • #3
      probtrader
      You may also want to look into the dsgetValueAtTime() function programmed by Chris Kryza which is included in his dsUtilities.efsLib function library. You can download the library here
      Alex

      Comment


      • #4
        Originally posted by dloomis
        There are 12 5 min bars per hour, and 6.5 hrs in a day,
        Yes, but that's assuming the time template is set to equity hours, 9:30-4:00 EST. It could be set to dynamic, 1 day or anything else thus changing the length of the day on the chart.

        Is there a way to read the current time template in EFS?


        so volume(12*6.5); is the bar from this time yesterday.

        To get the previous days volume, i would look at

        volume(2*12*6.5) etc.
        Offset should be negaitve, you probably mean volume(-(12*6.5)) and volume(-(2*12*6.5)).

        Comment


        • #5
          Originally posted by Alexis C. Montenegro
          probtrader
          You may also want to look into the dsgetValueAtTime() function programmed by Chris Kryza which is included in his dsUtilities.efsLib function library. You can download the library here
          Alex
          Alexis, how do I install EFS libraries? I can't find any help page.

          Comment


          • #6
            probtrader
            Just download them to the FunctionLibrary folder in eSignal. See this article in the EFS KnowledgeBase
            Alex

            Comment


            • #7
              Originally posted by Alexis C. Montenegro
              probtrader
              You may also want to look into the dsgetValueAtTime() function programmed by Chris Kryza which is included in his dsUtilities.efsLib function library. You can download the library here
              Alex
              Alex, I installed the libraries and can now load them in an EFS script but I can't find any documentation.
              When I try to open the libraries in the EFS editor I am prompted for a password.

              Comment


              • #8
                probtrader
                The documentation of the dsUtilities function library is available at the same location from which you downloaded the library. The source code for the library is not available
                Alex

                Comment


                • #9
                  Originally posted by Alexis C. Montenegro
                  probtrader
                  The documentation of the dsUtilities function library is available at the same location from which you downloaded the library. The source code for the library is not available
                  Alex
                  Alex, I downloaded the .chm files but when I open them I get a broken web link.
                  Do you know where can I access the documention online?

                  Comment


                  • #10
                    Originally posted by probtrader
                    Alex, I downloaded the .chm files but when I open them I get a broken web link.
                    Do you know where can I access the documention online?
                    Chris Kryza was kind enough to send me an update of the .chm help files. See attachments....
                    Attached Files

                    Comment


                    • #11
                      I tried to implement a same-time volume moving average using series offset but I can't make it work. For some reason the code at line 100 never gets executed, at least judging by the missing prints in the console output. I don't understand what makes the code exits right after the 'for()' loop.

                      Also, the EFS seems to have a problem when accessing volume bars older than offset 428 on a 5 minutes chart.
                      Attached Files
                      Last edited by probtrader; 01-08-2006, 05:29 PM.

                      Comment


                      • #12
                        Hello probtrader,

                        From what I see on my end your formula is working fine. The only problem I see is the bar index set for nOffset is off by a value of 1. Try changing line 88 to:

                        nOffset = ((i+1)*nBars);

                        Regarding line 100 not executing, I think you are just misinterpreting your formula output results. It is executing as it should. Keep in mind that if your for loop is set to run 5 iterations based on the nDays parameter, you will see 5 prints of the debugPrintln statements that are inside the for loop before you get a print from line 100. You should be seeing "Calculating STVMA at bar " once for every 6 blocks of debug prints. 5 from the for loop and then one from line 100.

                        Also, the EFS seems to have a problem when accessing volume bars older than offset 428 on a 5 minutes chart.
                        This is related to how much data is loaded in your chart when you run the study. When the study is processing at bar -428 and nOffset is -26, your chart must have at least 454 bars loaded. Otherwise, a call to volume(-26) will return null.
                        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


                        • #13
                          Originally posted by JasonK
                          When the study is processing at bar -428 and nOffset is -26, your chart must have at least 454 bars loaded. Otherwise, a call to volume(-26) will return null.
                          What I'm trying to achieve is to calculate a VMA for the same time-of-the-day bar. I can't tell in advance how many bars I need in the chart. Is there any way to make the EFS more dynamic and load the last 60 9:30 bars from the script?

                          BTW, I tried to run this using the dsUtilities function dsgetValueAtTime("9:30", volume()) but if I request 60 bars my eSignal crashes. I believe it's related to a resource problem (out of memory).

                          Comment


                          • #14
                            Hello probtrader,

                            To force your Advanced Chart to load a specific number of days, you need to set up a custom Time Template. For the Intraday Default enter 60 for the #Days setting.

                            One thing you should do for a study like this that needs a certain number of bars to be processed before it can return valid results is to check to see that you have enough bars processed during the loading process before allowing the code to go into your algorithm to calculate the stvma. This number of bars is based on what the max value of nOffset will need to be, which can be determined using the nDays and nBars variables used to assign the index value to this variable in your for loop inside the sameTimeVMA() function. Add the following line before your for loop.

                            PHP Code:
                                if ( -(nDays*nBars) + getCurrentBarIndex() < getOldestBarIndex()) return;

                                var 
                            acc 0;
                                for(var 
                            0nDaysi++ ) {
                            ...
                            ... 
                            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


                            • #15
                              Originally posted by JasonK
                              Hello probtrader,

                              To force your Advanced Chart to load a specific number of days, you need to set up a custom Time Template. For the Intraday Default enter 60 for the #Days setting.
                              [/php]
                              I was looking for a way to load enough bars from the EFS.

                              dsgetValueAtTime() must do something like that. I wrote a script that use this function, it works for a short number of periods but when I set the MA parameter to 60 my eSignal crashes, probably because of a memory resource problem.

                              Comment

                              Working...
                              X