Announcement

Collapse
No announcement yet.

indicator not updating

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

  • indicator not updating

    The following code just sums up the tick data since the opening of the market. However, it is not updating automatically through out the day. I have to refresh to update. What am I doing wrong?

    PHP Code:
    var fpArray = new Array();

    function 
    preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("Cumul Tick Interday");
     
        
    setDefaultBarStyle(PS_SOLID0); 
        
    setDefaultBarStyle(PS_SOLID1);
        
    setDefaultBarStyle(PS_SOLID2);
        
    setDefaultBarStyle(PS_SOLID3); 
       
        
    setDefaultBarFgColor(Color.black1); 
        
    setDefaultBarFgColor(Color.red2); 
        
    setDefaultBarFgColor(Color.blue3);    

        
    setDefaultBarThickness(40);    
        
    setDefaultBarThickness(11);  
        
    setDefaultBarThickness(22);   
        
    setDefaultBarThickness(23); 

        
    setPlotType(PLOTTYPE_HISTOGRAM0);   
        
    setPlotType(PLOTTYPE_LINE1);
        
    setPlotType(PLOTTYPE_LINE2);
        
    setPlotType(PLOTTYPE_LINE3);

        
    setShowCursorLabel(false1); 
        
    setShowCursorLabel(false2);
        
    setShowCursorLabel(false3);    
            
        
    addBand(5000PS_SOLID1Color.black"a");
        
    addBand(-5000PS_SOLID1Color.black"b");
        

        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("nSym"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("$TICK");
            
    addOption("$TICKQ");       
            
    setDefault("$TICK");
        }

    }
    var 
    vSum 0;
    var 
    vSum0 0
    var 
    vSum1 0;
    var 
    myColor Color.fushcia;
    var 
    myPrevColor Color.blue;
    var 
    bInit false;

    function 
    main(nSym) {

        
    setCursorLabelName(nSym0); 
        
        if (
    getBarState()==BARSTATE_NEWBAR){   
            
    vSum1 vSum;
            
    myPrevColor myColor;
            
    bInit false;
        }

        
    vSum efsInternal("aSum"nSym); 
        
    vSum0 vSum
        
        if (
    vSum vSum1 && vSum 0){          
            
    myColor Color.RGB(0,230,0);
            
    setDefaultBarFgColor(myColor);
        }   
            else if (
    vSum <= vSum1 && vSum 0){    
            
    myColor Color.green;
            
    setDefaultBarFgColor(myColor);
        }
            else if (
    vSum vSum1 && vSum 0){    
            
    myColor Color.RGB(255,120,0);
            
    setDefaultBarFgColor(myColor);
        }
            else if (
    vSum <= vSum1 && vSum 0){   
            
    myColor Color.red;
            
    setDefaultBarFgColor(myColor);
        }
        else{
            
    myColor myPrevColor;
            
    setDefaultBarFgColor(myColor);
        } 


        return new Array(
    vSum,vSum0); 

    }

    function 
    aSum(nSym){

        if (
    getBarState()==BARSTATE_NEWBAR){   
            var 
    nSum 0.0;
        }
        
        var 
    vTime getValue("Time");
        var 
    vFirstIndex getFirstBarIndexOfDay(vTimenSym);
        if (
    vFirstIndex == null && getDay(0) == getDay(-1)) {
            return;
        }
       
        var 
    vValue getValue("Close"0vFirstIndexnSym);
        if(
    vValue == null) {
            return;
        }
        
        for(
    0< -vFirstIndex getCurrentBarIndex(); i++) {        
            
    nSum += vValue[i];
        }
        

        return (
    nSum);

    Last edited by richard1000; 11-08-2010, 12:21 PM.

  • #2
    setDefaultBarFgColor is a premain function--you want setBarFgColor.
    Last edited by codehead; 11-08-2010, 01:04 PM.

    Comment


    • #3
      Hi,

      Here is my version of what I understand you are trying to plot.

      Wayne

      PHP Code:
      var fpArray = new Array();
      var 
      vSum 0;
      var 
      vSum1 0;
      var 
      myColor Color.fushcia;
      var 
      myPrevColor Color.blue;
      var 
      bInit false;

      function 
      preMain() {
          
      setPriceStudy(false);
          
      setStudyTitle("Cumul Tick Interday");
       
          
      setDefaultBarStyle(PS_SOLID0); 
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarStyle(PS_SOLID2);
          
      setDefaultBarStyle(PS_SOLID3); 
         
          
      setDefaultBarFgColor(Color.black1); 
          
      setDefaultBarFgColor(Color.red2); 
          
      setDefaultBarFgColor(Color.blue3);    

          
      setDefaultBarThickness(40);    
          
      setDefaultBarThickness(11);  
          
      setDefaultBarThickness(22);   
          
      setDefaultBarThickness(23); 

          
      setPlotType(PLOTTYPE_HISTOGRAM0);   
          
      setPlotType(PLOTTYPE_LINE1);
          
      setPlotType(PLOTTYPE_LINE2);
          
      setPlotType(PLOTTYPE_LINE3);

          
      setShowCursorLabel(false1); 
          
      setShowCursorLabel(false2);
          
      setShowCursorLabel(false3);    
              
          
      addBand(5000PS_SOLID1Color.black"a");
          
      addBand(-5000PS_SOLID1Color.black"b");
          
          var 
      x=0;
          
      fpArray[x] = new FunctionParameter("nSym"FunctionParameter.STRING);
          
      with(fpArray[x++]){
              
      addOption("$TICK");
              
      addOption("$TICKQ");       
              
      setDefault("$TICK");
          }
      }

      function 
      main(nSym) {

          if(
      getDay() != getDay(-1)) {
              
      vSum=0;
              
      vSum1=0;
          }

          if(!
      bInit){
              
      setCursorLabelName(nSym0); 
              
      bInit true;
          }
          if (
      getBarState()==BARSTATE_NEWBAR){   
              
      vSum1 vSum;
              
      vValue getValue("Close"0nSym);
              
      vSum += vValue;
              
      myPrevColor myColor;
          }

          if (
      vSum vSum1 && vSum 0){          
              
      myColor Color.RGB(0,230,0);
              
      setDefaultBarFgColor(myColor);
          }   
              else if (
      vSum <= vSum1 && vSum 0){    
              
      myColor Color.green;
              
      setDefaultBarFgColor(myColor);
          }
              else if (
      vSum vSum1 && vSum 0){    
              
      myColor Color.RGB(255,120,0);
              
      setDefaultBarFgColor(myColor);
          }
              else if (
      vSum <= vSum1 && vSum 0){   
              
      myColor Color.red;
              
      setDefaultBarFgColor(myColor);
          }
          else{
              
      myColor myPrevColor;
              
      setDefaultBarFgColor(myColor);
          } 

          return new Array(
      vSum,vSum); 

      Last edited by waynecd; 11-08-2010, 10:25 PM.

      Comment


      • #4
        waynecd, thanks. Exactly what I was looking for. Only problem is the tick sum indicator only updates after the bar interval is finished. It would be better if tick sum is constantly updated as new tick data is coming in. Any suggestions?

        Comment


        • #5
          After a little testing during market hours I found my original revision to your script does not do what you intended.

          I revised it but haven't tested it real time. I'll leave that to you.

          IMPORTANT NOTE: It is set for intraday minute charts only. Also it is important for the Time Template to be set for 9:30 - 16:00 EST for the efs to synchronize with the $TICK/$TICKQ plots since they only trade during these hours.

          See attached efs.

          Wayne
          Attached Files
          Last edited by waynecd; 11-09-2010, 08:36 PM.

          Comment


          • #6
            this is what it looks like.

            Wayne
            Attached Files

            Comment


            • #7
              Re: indicator not updating

              richard1000
              You need to consider that the legacy getValue() function you used to call the data of the external symbol does not synchronize data between different symbols by date and time [like the efs2 functions] but by bar index which can return unexpected results if the two data series are not exactly aligned on each and every bar [for example because of different trading hours or even because one symbol simply did not trade over a period of any number of bars]
              In order to maintain the proper synchronization between symbols you need to run the called function in the context of the external symbol. To do this you need to pass the symbol series using the sym() function as the last parameter of the efsInternal() call [and not just the symbol string as in your script]
              Enclosed below is a simplified example of how you would do what you are trying to accomplish [you can complete it as per your requirements]
              In the following image you can see my version of the script running on two charts one for MSFT based on a 24 hour time template and the other of $TICK. As you can see the values returned by the script in the two charts are the same and the profiles of the plots also match on the bars in which the external symbol was in session [during the out of session periods the plot remains stationary at the last calculated value]



              With regards to the script notice that in the called function I no longer need to call the specific symbol when using close(0). This is because the entire function is running in the context of the symbol series I passed in the efsInternal() call.
              Also notice that in my script I am using the ref() function [which if I remember correctly I already mentioned to you elsewhere] to retrieve the value returned at the prior bar thereby saving me from having to use a routine to transfer and store the returned value at every new bar
              Lastly you should find this script to be more efficient [aside from functioning on all intervals and/or time templates]
              Alex

              PHP Code:
              function preMain(){
                  
              setPlotType(PLOTTYPE_HISTOGRAM);
                  
              setDefaultBarThickness(5)
              }

              var 
              xSum null;
              var 
              nColor Color.lime;
              var 
              nColor1 Color.lime;

              function 
              main(){
                  if(
              getBarState() == BARSTATE_ALLBARS) {
                      
              xSum efsInternal("calc",sym("$tick"));//calls the function and passes the sym() series
                  
              }
                  if(
              getBarState() == BARSTATE_NEWBAR) {
                      
              nColor1 nColor;
                  }
                  var 
              vSum xSum.getValue(0);
                  var 
              vSum1 xSum.getValue(-1);
                  if (
              vSum == null || vSum1 == null) return;//null check on the value of the xSum series
                  
              if (vSum vSum1 && vSum 0){          
                      
              nColor Color.RGB(0,230,0);
                  }   
                  else if (
              vSum <= vSum1 && vSum 0){    
                      
              nColor Color.green;
                  }
                  else if (
              vSum vSum1 && vSum 0){    
                      
              nColor Color.RGB(255,120,0);
                  }
                  else if (
              vSum <= vSum1 && vSum 0){   
                      
              nColor Color.red;
                  }
                  else{
                      
              nColor nColor1;
                  } 
                  
              setBarFgColor(nColor);
                  return 
              xSum.getValue(0);
              }
              //function runs in the context of the sym series being passed
              function calc(){
                  var 
              ySum1 0;
                  if(
              day(0)!=day(-1)){//on the first bar of the day 
                      
              ySum1 0;//the variable ySum1 is set to 0
                  
              }else{//else ie on all other bars 
                      
              ySum1 ref(-1);//it is set to the value returned at the prior bar
                  
              }
                  var 
              ySum ySum1 close(0);//cumulative calculation
                  
              return ySum;


              Originally posted by richard1000
              The following code just sums up the tick data since the opening of the market. However, it is not updating automatically through out the day. I have to refresh to update. What am I doing wrong?

              PHP Code:
              var fpArray = new Array();

              function 
              preMain() {
                  
              setPriceStudy(false);
                  
              setStudyTitle("Cumul Tick Interday");
               
                  
              setDefaultBarStyle(PS_SOLID0); 
                  
              setDefaultBarStyle(PS_SOLID1);
                  
              setDefaultBarStyle(PS_SOLID2);
                  
              setDefaultBarStyle(PS_SOLID3); 
                 
                  
              setDefaultBarFgColor(Color.black1); 
                  
              setDefaultBarFgColor(Color.red2); 
                  
              setDefaultBarFgColor(Color.blue3);    

                  
              setDefaultBarThickness(40);    
                  
              setDefaultBarThickness(11);  
                  
              setDefaultBarThickness(22);   
                  
              setDefaultBarThickness(23); 

                  
              setPlotType(PLOTTYPE_HISTOGRAM0);   
                  
              setPlotType(PLOTTYPE_LINE1);
                  
              setPlotType(PLOTTYPE_LINE2);
                  
              setPlotType(PLOTTYPE_LINE3);

                  
              setShowCursorLabel(false1); 
                  
              setShowCursorLabel(false2);
                  
              setShowCursorLabel(false3);    
                      
                  
              addBand(5000PS_SOLID1Color.black"a");
                  
              addBand(-5000PS_SOLID1Color.black"b");
                  

                  var 
              x=0;
                  
              fpArray[x] = new FunctionParameter("nSym"FunctionParameter.STRING);
                  
              with(fpArray[x++]){
                      
              addOption("$TICK");
                      
              addOption("$TICKQ");       
                      
              setDefault("$TICK");
                  }

              }
              var 
              vSum 0;
              var 
              vSum0 0
              var 
              vSum1 0;
              var 
              myColor Color.fushcia;
              var 
              myPrevColor Color.blue;
              var 
              bInit false;

              function 
              main(nSym) {

                  
              setCursorLabelName(nSym0); 
                  
                  if (
              getBarState()==BARSTATE_NEWBAR){   
                      
              vSum1 vSum;
                      
              myPrevColor myColor;
                      
              bInit false;
                  }

                  
              vSum efsInternal("aSum"nSym); 
                  
              vSum0 vSum
                  
                  if (
              vSum vSum1 && vSum 0){          
                      
              myColor Color.RGB(0,230,0);
                      
              setDefaultBarFgColor(myColor);
                  }   
                      else if (
              vSum <= vSum1 && vSum 0){    
                      
              myColor Color.green;
                      
              setDefaultBarFgColor(myColor);
                  }
                      else if (
              vSum vSum1 && vSum 0){    
                      
              myColor Color.RGB(255,120,0);
                      
              setDefaultBarFgColor(myColor);
                  }
                      else if (
              vSum <= vSum1 && vSum 0){   
                      
              myColor Color.red;
                      
              setDefaultBarFgColor(myColor);
                  }
                  else{
                      
              myColor myPrevColor;
                      
              setDefaultBarFgColor(myColor);
                  } 


                  return new Array(
              vSum,vSum0); 

              }

              function 
              aSum(nSym){

                  if (
              getBarState()==BARSTATE_NEWBAR){   
                      var 
              nSum 0.0;
                  }
                  
                  var 
              vTime getValue("Time");
                  var 
              vFirstIndex getFirstBarIndexOfDay(vTimenSym);
                  if (
              vFirstIndex == null && getDay(0) == getDay(-1)) {
                      return;
                  }
                 
                  var 
              vValue getValue("Close"0vFirstIndexnSym);
                  if(
              vValue == null) {
                      return;
                  }
                  
                  for(
              0< -vFirstIndex getCurrentBarIndex(); i++) {        
                      
              nSum += vValue[i];
                  }
                  

                  return (
              nSum);

              Comment


              • #8
                Thanks again Alex. Two points.

                1. How do I know which functions are legacy and which are from efs2?

                2. I thought I could use getFirstBarIndexofDay and use brute force way of summing it up. But I now see the errors of my way. Yes you did mention ref() before. I just forgot to use it in this context. It's like the mother of all recursive function and should be learned by anyone who programs.

                Comment


                • #9
                  richard1000
                  1. As a general rule all the functions that use a string parameter to call external symbols and/or intervals are legacy functions. The efs2 functions instead use the sym() or inv() functions to accomplish that task. That said there are some functions [such as for example open(), high(), low(), etc] that can use either syntax [and will consequently behave differently depending on that]. This is because eSignal chose to overload those functions so as to maintain backwards compatibility.
                  2. When used properly the ref() function can indeed be quite useful. Note however that it only applies to values returned by the formula
                  Alex


                  Originally posted by richard1000
                  Thanks again Alex. Two points.

                  1. How do I know which functions are legacy and which are from efs2?

                  2. I thought I could use getFirstBarIndexofDay and use brute force way of summing it up. But I now see the errors of my way. Yes you did mention ref() before. I just forgot to use it in this context. It's like the mother of all recursive function and should be learned by anyone who programs.

                  Comment


                  • #10
                    richard1000

                    2. I thought I could use getFirstBarIndexofDay and use brute force way of summing it up. But I now see the errors of my way. Yes you did mention ref() before. I just forgot to use it in this context. It's like the mother of all recursive function and should be learned by anyone who programs.
                    As an aside you could also do it using getFirstBarIndexOfDay() and a loop however even in that case you would still want to use the efs2 construct for the reason explained earlier
                    Enclosed below is how you could write the function in this case (the main function would remain unchanged). The result should be the same [albeit less efficient IMHO] as you can see in the enclosed screenshot
                    Alex

                    PHP Code:
                    //function runs in the context of the sym series being passed
                    function calc(){
                        var 
                    ySum 0;
                        var 
                    xTime getValue("time");
                        var 
                    xFstBarIndxDay getFirstBarIndexOfDay(xTime);
                        for(var 
                    i=0;i<=getCurrentBarIndex()-xFstBarIndxDay ;i++){//run a loop
                            
                    ySum +=close(-i);//summing up all the close() values
                        
                    }
                        return 
                    ySum;




                    Originally posted by richard1000
                    Thanks again Alex. Two points.

                    1. How do I know which functions are legacy and which are from efs2?

                    2. I thought I could use getFirstBarIndexofDay and use brute force way of summing it up. But I now see the errors of my way. Yes you did mention ref() before. I just forgot to use it in this context. It's like the mother of all recursive function and should be learned by anyone who programs.

                    Comment

                    Working...
                    X