Announcement

Collapse
No announcement yet.

setComputeOnClose vs. realtime - diffrent values

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

  • setComputeOnClose vs. realtime - diffrent values

    I use a function, which works very good, if I use setComputeOnClose or without setComputeOnClose until the moment, its realtime begining (with function and efsInternal the same thing).

    I cant imagen, whats the problem is, should I use Arrays with BarIndex and save all variables to this?

    Has high(-1) and so on wrong values at the beginning of realtime?

    I want only the the value at the current bar, how it appears, if I refresh the chart or new loading.
    Franz

  • #2
    Franz
    Please post a working sample of the code that illustrates the problem
    Alex

    Comment


    • #3
      Its not the script, only a example, to show what I mean.
      Its the best, if you test it on 2T chart, after some bars, the value is differently. If I reload the none-setComputeOnClose, I get correct values.

      PHP Code:
      function preMain()
      {
          
      setComputeOnClose();
      }

      var 
      myVar = new Array();
      function 
      main()
      {    
          
      myVar[4]=myVar[3];
          
      myVar[3]=myVar[2];
          
      myVar[2]=myVar[1];    
          
      myVar[1]=myVar[0];    
          
      myVar[0]=(close(0)+close(-1)+close(-2)+close(-3)+close(-4)+close(-5)-close(-3))/5;

          
      mysma 0;
          for (
      05i++) {mysma += myVar[i];}
          
      mysma /= 5;
          
          return 
      mysma;

      PHP Code:
      var myVar = new Array();
      function 
      main()
      {    
          
      myVar[4]=myVar[3];
          
      myVar[3]=myVar[2];
          
      myVar[2]=myVar[1];    
          
      myVar[1]=myVar[0];    
          
      myVar[0]=(close(0)+close(-1)+close(-2)+close(-3)+close(-4)+close(-5)-close(-3))/5;

          
      mysma 0;
          for (
      05i++) {mysma += myVar[i];}
          
      mysma /= 5;
          
          return 
      mysma;

      I wrote over 300 code-lines, therefore I hope, that there is a simple possibility of calculating real-time the correct value which agree later also with the setComputeOnClose values.
      Franz

      Comment


      • #4
        Franz
        In the second example you are transferring the values of the array on every tick whereas that should happen only once at every new bar as in the example below. For more information on getBarState() see this article in the EFS KnowledgeBase.
        Alex

        PHP Code:
        var myVar = new Array();
        function 
        main()
        {    

            if(
        getBarState()==BARSTATE_NEWBAR){
                
        myVar[4]=myVar[3];
                
        myVar[3]=myVar[2];
                
        myVar[2]=myVar[1];    
                
        myVar[1]=myVar[0]; 
            }   
            
        myVar[0]=(close(0)+close(-1)+close(-2)+close(-3)+close(-4)+close(-5)-close(-3))/5;

            
        mysma 0;
            for (
        05i++) {mysma += myVar[i];}
            
        mysma /= 5;
            
            return 
        mysma;

        Comment


        • #5
          Alex,

          thank you for your posting! I solved the problem with your help! You are the best!
          Last edited by franzmey; 01-18-2006, 04:36 AM.
          Franz

          Comment

          Working...
          X