Announcement

Collapse
No announcement yet.

reload efs from within code

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

  • reload efs from within code

    Hello,

    I have an efs that I want to reload every say 15 mins - to iron out any false signals from using different time intervals, I know there is a reloadefs function - but how can I time the use of the function.

    Thanks in advance.

    Paul Murray

  • #2
    I don't have any code for you, but I could tell you generally how I would approcah coding this EFS.

    First a warning, in using the reset EFS function it is REALLY easy to get eSignal locked in an infinite loop. My suggestion is prior to loading any new (or modified) formula with this command that you back up you chart file so you can swap in the old (no loop) chart if you end up locking eSignal.

    So, if you are running your formula on a 15 minute chart (or some inteval that goes evenly into 15 minutes) then this isn't too tough (I think).

    1) Set compute on close or add all the above code under a check for newbar (execute it if true)
    2) Check to see if the current bar is equal to the last bar of the chart
    3) If it isn't bail out
    4) If it is then reset the EFS

    The above assumes a 15 minute chart. If it is a 5 minute chart (for example), then you would create a local global variable to use as a counter. After the check for newbar you would increment the counter until 15 minutes has passed. reset the counter and the EFS.

    Hope this helps.

    Garth
    Garth

    Comment


    • #3
      Garth

      Thanks for the reply.

      Will have to study the efs glossary for checking the time, so I can see how many mins have elapsed, or asyou suggest create a variable and increment it.

      Will take care not to create an infinite loop.

      Paul.

      Comment


      • #4
        Paul,

        I worked on this late last night. However, if I had posted the snippet I had come up with earlier, it would not have worked. I slept on it and came up with this...


        PHP Code:
        //set this outside main function as a global variable;
        var myStartTime;

        if (
        getBarState() == BARSTATE_ALLBARS) {
         
        myStartTime rawtime(0);
        }

        if ( 
        getBarState() == BARSTATE_NEWBAR ) {
         var 
        myTime rawtime(0);
         
         if(((
        myTime-myStartTime)%(15*60) == 0) && (myStartTime!=myTime)){
          
        reloadEFS();
         }

        As Garth indicated, it is REALLY easy to get eSignal locked in an infinite loop with reloadEFS(). His recommendation on backing up the chart is a very good one as well, based on some bad experiences I had previously using reloadEFS().

        Comment


        • #5
          Thanks for sharing, Steve.

          Comment


          • #6
            Thanks steve, tried it and in a loop cant get out, cant get out, cant get out ........

            HHHHEEELLLPPPPP!!!!

            Comment


            • #7
              Hmmmm,

              we use to call that sub-optimal.

              Paul.

              Comment


              • #8
                Paul,

                You have to make sure that as you add Steve't code to your EFS that you set

                var myStartTime;

                Outside of main() and preMain() functions.

                The rest of the code should be some of the first real code inside of main().

                Hope you backed up your chart file ;-)

                Garth
                Garth

                Comment


                • #9
                  Steve,

                  I had forgotten about rawtime()...good idea. I was thinking of using the regular time functions but remembered how much CPU they soak up.

                  Nicely done...it should work great.

                  Garth
                  Garth

                  Comment


                  • #10
                    Paul,

                    The modulo command returns the remainder of an integer division operation. I tried to design this such that the remainder of this operation should be zero right when the efs has been loaded and then once every 900 seconds.

                    The problem is that I had used the wrong command in there. This command getBarState() == BARSTATE_ALLBARS loads the very first bar. Therefore, you will initialize at the first bar in history. I should have used this command

                    isLastBarOnChart()

                    which will be satisfied once all the bars have loaded. This will require setting of some other flags however since I believe this other command will be true every tic thereafter as well. If you would like to troubleshoot, try running this without the reloadEFS() command and instead stick a debugPrintln command to determine what is happening. I'll look at this further tonight

                    Comment


                    • #11
                      I can't seem to find isLastBarOnChart in the Knowledgebase except in the beantick code.

                      Where else should I be looking?

                      Comment


                      • #12
                        Hi Steve,

                        thanks for thinking about it a little more, I was thinking would the ALLBARS put it into the loop.

                        Buzz - there is an EFS glossary - but it is well buried inside the system.



                        Paul.

                        Comment


                        • #13
                          Paul,

                          You are correct. The BARSTATE_ALLBARS query is met at the very first historical bar. At that point, I had set the zero time. As the historical bars load, eventually, the 900 seconds conditional is true, ... while still processing the historical chart data. At that point it is reloading again, even though it hadn't loaded the historical data all the way... thus the loop. Also, I will probably not use the modulo command as it will not work on tick charts as they are not in even 900 second blocks...

                          Comment


                          • #14
                            Does this accomplish the same thing as last bar on chart?



                            if(getCurrentBarIndex() != 0)
                            return;

                            Comment


                            • #15
                              Paul,

                              This seems to work well in tick playback. I moved it to a separate function and then called the function every new bar, including the number of seconds and the number of bars per reload in the function call. The conditionals in the function are "bar dominant" which can be modified. As Garth indicated and I was able to demonstrate, reloadEFS() can be fickle.

                              btw, the calls to the Date object are for the debug output only... both of these calls, the debug statements and the conditionals associated with them are not required.

                              PHP Code:
                              debugPrintln("");debugPrintln("1: Initial Load");
                              var 
                              myStartTime;
                              var 
                              myStartBar;
                              var 
                              reloadFlag false;
                              var 
                              reloadTime null;
                              var 
                              nStudy "pmurraymc"

                              function preMain(){
                               
                              debugPrintln("9: preMain");
                               
                              setPriceStudy(true);
                               
                              setStudyTitle(nStudy);
                               
                              setCursorLabelName("1st",0);
                               
                              setDefaultBarFgColor(Color.blue0);
                               
                              setDefaultBarThickness(1,0);
                              }

                              function 
                              main() {
                               
                               if ( 
                              getBarState() == BARSTATE_NEWBAR ) {
                                
                              ReloadCheck(900,20); // feeding number of seconds and a barcount
                               
                              }
                              }

                              function 
                              ReloadCheck(nSec,nBars){
                               if(!
                              reloadFlag isLastBarOnChart()){
                                
                              myStartTime rawtime(0);
                                
                              myStartBar getCurrentBarCount();
                                var 
                              tmp = new Date().getTime();
                                if(
                              reloadTime != null){
                                 
                              debugPrintln("");
                                 
                              debugPrintln("31: reloadEFS() took ==>> "+(tmp-reloadTime)+" miliseconds");
                                }
                                
                              debugPrintln("33: isLastBarOnChart() = "+isLastBarOnChart()+", getCurrentBarCount() = "+getCurrentBarCount()+", reloadFlag = "+reloadFlag);
                                
                              reloadFlag true;
                               }
                               else if(
                              reloadFlag){
                                var 
                              myTime rawtime(0);
                                var 
                              myBar getCurrentBarCount();
                                
                              debugPrintln("39: isLastBarOnChart() = "+isLastBarOnChart()+", getCurrentBarCount() = "+getCurrentBarCount()+", reloadFlag = "+reloadFlag);
                                if((((
                              myTime myStartTime) > nSec) && ((myBar-myStartBar) > nBars))||(myBar-myStartBar nBars)){
                                 
                              debugPrintln("41: Reloading, (myTime - myStartTime) = "+(myTime myStartTime)+" seconds, (myBar-myStartBar) = "+(myBar-myStartBar)+" bars");
                                 
                              reloadFlag false;
                                 
                              reloadTime = new Date().getTime();
                                 
                              reloadEFS();
                                }
                               }

                              Last edited by Guest; 08-11-2006, 04:57 PM.

                              Comment

                              Working...
                              X