Announcement

Collapse
No announcement yet.

Very Easy Question

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

  • Very Easy Question

    I'm probably overtired and doing something silly but can anyone tell me why ...

    TestA.efs works ok

    TestB.efs doesn't

    on eSignal Version 10.6.2415.1208
    Attached Files
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

  • #2
    still not sure why TestA works and TestB doesn't but this fixes it ..

    function main()
    {
    var vBarState = getBarState();

    if(getCurrentBarCount() < 3)
    return null;

    if (vBarState == BARSTATE_NEWBAR)
    {
    if (bInit == false)
    {

    bInit = true;

    db("testB1");
    db("testB2",getValue("year",-2));
    db("testB3",getYear(-2));

    }
    }

    return null;
    }

    useful to know when debugging.
    Paul Williams
    Strategy & Applications
    www.futurenets.co.uk

    Comment


    • #3
      Very Easy Question II

      Can anyone tell me why I'm able to reference bars using with +ve indexes in the attached TestC.efs.
      Attached Files
      Paul Williams
      Strategy & Applications
      www.futurenets.co.uk

      Comment


      • #4
        Nice catch.
        This also interests me so I ran a few tests.

        I ran tests on a 3 minute chart of "ES #F".

        Conclusion: When more than one function call exists within the bInit conditional , it runs normally until it executes the first function call,
        it then retains the functions return value in memory. On this first run it will keep in memory the value of variables before the second function call.
        (note that minute 06:36 doesn't change even though the chart advanced to time 07:09 by the time I ran these tests)

        Then the bInit conditional runs a second time with the value of bInit it had before the second function call.
        If bInit was set to true before the second function call then the bInit condition doesn't run again since now bInt==true;
        If bInit was set to true after the second function call then the bInit conditional runs a second time all the way calling the remaining functions.

        So if bInit is set to true before the second function call, the bInit conditional will not run the remaining code on the second run.

        The fact that the script runs the bInit conditional inside of the "BARSTATE_NEWBAR" conditional, didn't affect the outcome when I tested it with and without the "BARSTATE_NEWBAR" conditional.

        The last test below shows that the bInit conditional is only interrupted if there is a second function call since with only one function call all the debugPrintln(...) lines of code below the function call executed.


        PHP Code:
                if (bInit == false
                {
                    
        bInit true;
                    
        db("testB1");
                
        debugPrintln("21: bInit = "+bInit);
                    
        db("testB2",getValue("year",-2));     
                
        debugPrintln("22: bInit = "+bInit);
                    
        db("testB3",getYear(-2));     
                
        debugPrintln("23: bInit = "+bInit);
                }
            }

        //returns the following:
        //21: bInit = true
        //12 20 14 36 testB1 undefined undefined undefined 
        PHP Code:
                if (bInit == false
                {
                    
        db("testB1");
                    
        bInit true;
                
        debugPrintln("21: bInit = "+bInit);
                    
        db("testB2",getValue("year",-2));     
                
        debugPrintln("22: bInit = "+bInit);
                    
        db("testB3",getYear(-2));     
                
        debugPrintln("23: bInit = "+bInit);
                }
            }

        //returns the following:
        //21: bInit = true
        //12 20 14 36 testB1 undefined undefined undefined 
        PHP Code:
                if (bInit == false
                {


                    
        db("testB1");
                
        debugPrintln("21: bInit = "+bInit);
                    
        bInit true;
                    
        db("testB2",getValue("year",-2));     
                
        debugPrintln("22: bInit = "+bInit);
                    
        db("testB3",getYear(-2));     
                
        debugPrintln("23: bInit = "+bInit);
                }
            }
        //returns the following:
        //21: bInit = false
        //12 20 14 36 testB1 undefined undefined undefined 
        PHP Code:
                if (bInit == false
                {
                    
        db("testB1");
                
        debugPrintln("21: bInit = "+bInit);
                    
        db("testB2",getValue("year",-2));     
                    
        bInit true;
                
        debugPrintln("22: bInit = "+bInit);
                    
        db("testB3",getYear(-2));     
                
        debugPrintln("23: bInit = "+bInit);
                }
            }
        //returns the following:
        //23: bInit = true
        //12 20 14 39 testB3 2012 undefined undefined
        //22: bInit = true
        //12 20 14 39 testB2 2012 undefined undefined
        //21: bInit = false
        //12 20 14 39 testB1 undefined undefined undefined
        //21: bInit = false
        //12 20 14 36 testB1 undefined undefined undefined 
        PHP Code:
                if (bInit == false
                {

                    
        bInit true;

                    
        db("testB1");
                    
        debugPrintln("21: bInit = "+bInit);
        //            bInit = true;
                    //db("testB2",getValue("year",-2));     
        //            bInit = true;
                    
        debugPrintln("22: bInit = "+bInit);
                   
        // db("testB3",getYear(-2));     
                    
        debugPrintln("23: bInit = "+bInit);
                }
        //returns the following:
        //23: bInit = true
        //22: bInit = true
        //21: bInit = true
        //12 20 16 9 testB1 undefined undefined undefined 
        Wayne
        Last edited by waynecd; 12-21-2012, 08:14 AM.

        Comment


        • #5
          thanks again Wayne. appreciated.
          Paul Williams
          Strategy & Applications
          www.futurenets.co.uk

          Comment


          • #6
            You're welcome.

            Wayne

            Comment


            • #7
              not sure why "Very Easy Question II" (Above) has been merged with this one ... they're unrelated.
              Paul Williams
              Strategy & Applications
              www.futurenets.co.uk

              Comment


              • #8
                Originally posted by futurenets View Post
                Can anyone tell me why I'm able to reference bars using with +ve indexes in the attached TestC.efs.
                I don't know if it helps but within "BARSTATE_ALLBARS" eSignal seems to already know how many bars will be loaded, maybe because of the default or selected Time Template and interval.

                Here are the results for "BARSTATE_ALLBARS" and the most current bar. NOTE: I changed "function db(a,b,c,d)" somewhat.

                PHP Code:
                function preMain() {
                    
                setPriceStudy(true);
                    
                setStudyTitle("www.futurenets.co.uk TestC eSignal Version 10.6.2415.1208");
                }

                var 
                bInit false;
                var 
                Flag 0;
                function 
                main() 
                {
                    if (
                getBarState() == BARSTATE_ALLBARS)
                    {
                        var 
                OldestBar getOldestBarIndex();
                        
                OldestBar *= -1//OldestBar is now +ve
                        
                db("testC1",OldestBar);
                        
                db("testC2",getValue("rawtime",OldestBar));
                        
                db("testC3",getValue("year",OldestBar)); 
                        
                debugPrintln();        
                    }
                    if(
                getCurrentBarIndex()==&& getBarState()== BARSTATE_NEWBAR){
                        if(
                Flag!=1){
                            var 
                OldestBar1 getOldestBarIndex();
                            
                OldestBar1 *= -1//OldestBar1 is now +ve
                            
                db("testC4",OldestBar1);
                            
                db("testC5",OldestBar1,getValue("rawtime",OldestBar1));
                            
                db("testC6",OldestBar1,getValue("year",OldestBar1));        
                            
                Flag=1;
                        }
                    }
                    
                    return 
                null;
                }

                function 
                db(a,b,c,d) {
                    
                debugPrintln("\t1: "+getMonth() + " " getDay() + " " getHour() + " " getMinute() + " " " " c  " " d+"\t"+getCurrentBarCount());
                    if(
                != "testC1" && != "testC2" && != "testC3"){
                        
                debugPrintln("\n"+"\t2: "+getMonth(-b) + " " getDay(-b) + " " getHour(-b) + " " getMinute(-b) + " " " " c  " " d+"\t"+getCurrentBarCount());
                    }
                }
                /*
                returns:
                testC6    2: 12 20 16 57 313 null undefined    314
                testC6    1: 12 21 9 21 313 null undefined    314

                testC5    2: 12 20 16 57 313 null undefined    314
                testC5    1: 12 21 9 21 313 null undefined    314

                testC4    2: 12 20 16 57 313 undefined undefined    314
                testC4    1: 12 21 9 21 313 undefined undefined    314

                testC3    1: 12 20 16 57 2012 undefined undefined    1
                testC2    1: 12 20 16 57 1356099660 undefined undefined    1
                testC1    1: 12 20 16 57 313 undefined undefined    1
                */ 
                Last edited by waynecd; 12-21-2012, 07:24 AM.

                Comment

                Working...
                X