Announcement

Collapse
No announcement yet.

1st tick?

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

  • 1st tick?

    I have an EFS script in which I want to grab an indicator value on the 1st tick of a new bar. My script uses:

    if(getBarState()==BARSTATE_NEWBAR) {
    do_some_stuff }

    This doesn't work for me (under esignal v7.8 7.7 or 7.6). What I do inside the curly brackets is to grab the indicator value and print it to the alert list along with the (getCurrentBarIndex) value and the time.

    What happens is that it waits until the first new tick of a newbar, then returns the indicator value of the previous bar (based on the time I print out and the barindex being -1.

    What is wrong with this??? Every single piece of example code says to use BARSTATE_NEWBAR to get the first tick of new bar but this definately doesn't work for me!!

  • #2
    grantanderson
    The code enclosed below returns to the Formula Output Window the value of close() and of the 1 period MA (also based on Close) at the first tick of a new bar. Both those values will essentially be the same as the Open of the new bar.
    It may be that on a new bar you are instead asking for the prior value (ie for example close(-1)) but without seeing all the code it is not possible to tell if that is the case
    Alex

    PHP Code:
    var vMA = new MAStudy(10"Close"MAStudy.SIMPLE);

    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("MA");
        
    setCursorLabelName("MA"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarThickness(1,0);
    }

    function 
    main() {
       
        if(
    getBarState()==BARSTATE_NEWBAR){
           var 
    vLast close();
           var 
    vLastMA vMA.getValue(MAStudy.MA);
        }
       
        
    debugPrintln(vLast+"  "+vLastMA);
        
        return 
    vMA.getValue(MAStudy.MA);

    Comment


    • #3
      Okay, well this is the only code in main for testing purposes. According to the esignal documentation, you would expect the BARSTATE_NEWBAR to be executed on 1st tick of a new bar? I want to check the Kalman Filter value on the 1st tick. It does have a value as soon as the bar opens, and you can see it on the chart, but this code doesn't retrieve it. If you try the code below on say 10min bars, at 1:50pm, you'd get the result for the 1:40pm (ie 2nd to last bar printed to the alert list as-

      Symbol KF = <somevalue> at 1:40pm BI -1

      The "barindex" (BI) of -1 kind of gives the game away.

      if(getBarState()==BARSTATE_NEWBAR) {
      var vKF = KF.getValue(MesaKalman.KALMAN);
      var BI = getCurrentBarIndex();
      Alert.addToList(getSymbol(), "KF = " + vKF + " at " + getHour() + ":" + getMinute() + " BI " + BI);
      }


      So what is wrong with this? It sets the variables when it gets the 1st tick so "KF" should be Kalman value for this brand new bar, and time (getHour + getMinute) should also return the current bar time. Finally getCurrentBarIndex should be 0. None of this occurs however as it gives you the 2nd to last bar...

      Comment


      • #4
        Just for completeness I placed your script into esignal as it is, and your script works.

        So since there is nothing in my function main other than that below is there something you can put in a script somewhere to tell it to ignore each new bar? It makes no sense...

        Comment


        • #5
          grantanderson
          Try the code enclosed below and see if it gives you the expected results.
          If not someone from eSignal may have to look into this
          Alex

          PHP Code:
          function preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("KF test");
              
          setCursorLabelName("KF");
          }

          var 
          KF null;

          function 
          main() {

              if (
          KF == nullKF = new MesaKalman("Close");
              
              var 
          vKF KF.getValue(MesaKalman.KALMAN);
              
              if(
          vKF == null)
              return;

              if(
          getBarState()==BARSTATE_NEWBAR) {
                  var 
          vX vKF;
                  
          debugPrintln(vX);
                  var 
          BI getCurrentBarIndex();
                  
          Alert.addToList(getSymbol(), "KF = "+vX+" at "+getHour()+":"+getMinute()+" BI "+BI);
              }

              return 
          vKF;

          Comment


          • #6
            Hello grantanderson,

            What symbol(s) are you testing with?
            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
              Originally posted by JasonK
              Hello grantanderson,

              What symbol(s) are you testing with?
              It fails with anything, but usually the forex symbols EUR A0-FX, GBP A0-FX etc. For some reason my code doesn't work (it waits for first tick then returns the previous bar details), but the example code somebody replied with works fine!

              I'm trying to build up my previous code around their working template but when I dumped it all back the thing failed again. It makes no sense!!

              Comment


              • #8
                Oops, my fault... At the top of my original code I had setComputeOnClose which I presume confuses it somewhat!!

                I used to take the last value of 2nd to last bar (-1) but have changed it now to take first value on new bar. But the setComputeOnClose was still there...

                Thanks for all your help, sorry it was due to my stupidity though!

                Comment


                • #9
                  Hello grantanderson,

                  setComputeOnClose() was going to be my next question. Glad to hear you've got it working now.
                  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