Announcement

Collapse
No announcement yet.

Synchronization across time frames

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

  • Synchronization across time frames

    hi Alex,

    A while ago you talked about how to properly synch values across time frames in EFS2....but I am not able to locate that post.

    How would you define variables properly so say, macd of a 60min time frame is synched when efs is called from a 5 min chart?

    I am using:

    var myVar = macd(12, 26, 9, inv(60));

    but the data retrieved seems to be a (60 min) bar behind.

    Thanks,

    ziggy

  • #2
    z11
    I just ran your example and as far as I can see it is syncronizing correctly (see enclosed image)
    Alex

    Comment


    • #3
      Thanks for the reply Alex.

      Ok the problem appears then this:

      if I do in a 5 min Chart:

      var myVar = macd(12, 26, 9, inv(60));

      var v1 = myVar.getValue(0);
      var v2 = myVar.getValue(1);
      var v3 = myVar.getValue(2);
      var v4 = myVar.getValue(3);


      Then v1 v2 v3 v4 would have the same value?


      How would you get v2 to be the actual one prior bar's value in a 60 miin time frame? besides me forcing an offset counter?


      Thanks

      ziggy

      Comment


      • #4
        Hello ziggy,

        In your getValue() statements you need to reference prior bars with negative bar indexes. Currently, you are trying to access future bars.
        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


        • #5
          Sorry Jason, that was typo on my part ....did not type - signs...anyway, my issue remains...any ideas?

          Thanks,

          ziggy

          Comment


          • #6
            Hello ziggy,

            Because the macd series you have created is based on the 60 min interval, the bar index references within the getValue() statements refer to the values on the 60 min chart.

            If you want to access the values of a higher time-frame series that are plotted on the prior bar of the 5 min chart, you can do this 3 ways.

            1. Use the ref() function.
            2. Set up your v# variables as global variables and add an additional global variable to store the prior bar's value at BARSTATE_NEWBAR. v1_1 in the code example below would always refer to the prior bar's value of v1 from the 5 min chart.

            PHP Code:
            var myVar null;
            var 
            v1 null;
            var 
            v1_1;

            function 
            main() {
                if (
            myVar == nullmyVar macd(12269inv(60));
                
                if (
            getBarState() == BARSTATE_NEWBAR) {
                    
            v1_1 v1;
                }

                
            v1 myVar.getValue(0);

                return new Array(
            v1v1_1);

            3. Create your macd as a series through efsInternal() that is based on the chart interval, but calculates the series values from the 60 min interval. You do this by embedding your 60 min macd calc inside an efsInternal() call without passing any inv() parameters to efsInternal().

            PHP Code:
            var myVar null;
            var 
            myInv 60;

            function 
            main() {
                if (
            myVar == nullmyVar efsInternal("calc_macd");
                var 
            v1 myVar.getValue(0);
                var 
            v2 myVar.getValue(-1);
                var 
            v3 myVar.getValue(-2);
                var 
            v4 myVar.getValue(-3);
                
                return new Array(
            v1v2v3v4);
            }

            function 
            calc_macd() {
                return 
            macd(12269inv(myInv))

            Because the efsInternal() call in this example is not using any parameters that are inv() or a series created with an inv() parameter, the EFS2 engine creates this series in the constructs of your chart interval. Now the bar index references in the getValue() statements refer to the 5 min chart that the formula is running on. The calculation is still based on the 60 min interval however.
            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


            • #7
              Jason - thank you for such detailed explaination.

              Happy Holidays! To All!!

              ziggy

              Comment

              Working...
              X