Announcement

Collapse
No announcement yet.

Referring to Seconds of a 1 Minute Bar

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

  • Referring to Seconds of a 1 Minute Bar

    Hi

    I'd like to compare the price and the volume of two different moments t(0) and t(1) within a one minute bar (basically like 2 snapshots at two precise moments, like second no.14 and 24 for example).

    How can I get the volume and price data of a specific second?

    Thanks a lot.

  • #2
    Hello laocoon,

    This can be accomplished using the inv() function to specify the 1-second interval data for the close() and volume() series. This will give you access to the 1-second bars that exist within each bar of your 1-minute chart. Keep in mind that these are bars, so you will get the last price for the 1-second bar and the total volume traded during the specific second. Also keep in mind that for infrequently traded securities there may not be any trades during a specific second so you will need to check for that in your routine as well. Here is a very basic example of how to set up the data series of the 1-second interval and how to loop through that data while on a 1-minute chart. This should help get you started. Make note that this example only runs on bar -1 so that you can see what happens for that specific bar. Compare the formula output results to a time and sales window and a 1S chart to get a better understanding of what this does.

    PHP Code:
    var xPrices null;
    var 
    xVolume null;
    var 
    xTime null;

    function 
    main() {
        if (
    xPrices == null) {
            
    xPrices close(inv("1S"));
            
    xVolume volume(inv("1S"));
            
    xTime   rawtime(inv("1S"));
        }
        
        if (
    getCurrentBarIndex() == -1) {
            var 
    0;
            while (
    xTime.getValue(i) >= rawtime(0)) {
                
    debugPrintln(xTime.getValue(i) + "  close: " xPrices.getValue(i) +
                    
    "  volume: " xVolume.getValue(i));
                
    i--;
            }
        }
        
        return;


    To get at the two specific seconds you could add those two values as formula parameters and modify the while loop to only look for those two 1-second bars. Assign the values to separate variables so that you can do your comparison later in the formula. To ensure that you have valid data for those two moments, first check the variables for null values. If one or both are found to be null, there were no trades during the specified seconds bars you were requesting. In that case, prevent the formula from doing a comparison or add additional logic to the while loop to look further back in time if no data is found for the original second bar that you requested. Another thing that you'll want to be conscious of is the amount of data loaded into your 1-minute chart. This type of multiple interval study can be very process intensive because it is accessing tick data and synchronizing it to your intraday chart. To minimize the processing requirements you will want to limit the number of days of data loaded into your chart with a custom time template. I would recommend restricting your 1-minute interval to load 3 days of data or less.
    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


    • #3
      That should do the trick....

      Thanks a lot for the detailed reply.

      Comment


      • #4
        You're most welcome.
        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