Announcement

Collapse
No announcement yet.

reloadEFS()

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

  • reloadEFS()

    Do not do this til you understand what reloadEFS() is all about!

    I want to reload the efs every time a new bar starts

    Any one see anything wrong here?

    var loadup=0;

    function main(){

    if(getBarState()==BARSTATE_NEWBAR&&getCurrentBarIn dex()==0&&loadup==0){
    reloadEFS();
    debugPrintln("reload")
    loadup=1;
    }

    if(getBarState()!=BARSTATE_NEWBAR&&getCurrentBarIn dex()==0&&loadup==1){ //edited to 1 from 0
    loadup=0;
    }

  • #2
    Dave,

    It does not look like it will work. When it gets to reloadefs(), none of the code after that will execute, so I believe you are in an endless do loop where the chart will fully load and as soon as your conditional is met, reloadefs will execute, and nothing after.
    i.e.

    these steps will not implement

    debugPrintln("reload")
    loadup=1;
    put them in front of the reloadefs()

    here is something I put together




    When you reload the efs, do you want all the bars to reload or like the last 90 (the last 90 would make implementation much easier.)


    PHP Code:
    var loadup=0;
    var 
    reloads 0;
    function 
    preMain(){
    }
    function 
    main(){

        if (
    getBarState() == BARSTATE_ALLBARS) {//true once during initial load and subsequent reload
            
    loadup=0;
            
    debugPrintln("reload "+reloads);
            
    reloads getGlobalValue (("d1"));
        }
        
        if ((
    getCurrentBarIndex()< -90) || (Math.abs(getOldestBarIndex()) < 160)){return;} // minimizes load time

        
    if(getBarState()==BARSTATE_NEWBAR){
            if (
    loadup ==2){
                
    setGlobalValue (("d1"reloads));
                
    reloadEFS();
            }
            if (
    getCurrentBarIndex()==0){
                
    loadup++;
                
    reloads++;
            }
        }

    I set this up to reload every 2nd bar.

    Something else you may want to put in there is to setting global variables and then reading them back in on reload ( I put that in there, it is an option you can use to ensure things are passed between periods of reload depending on what you are doing.) In this case, passing this variable is not necessary because it is a global variable anyway, but for some reason if you had set a value as a local variable somewhere in the code, you could set it like I did in this example in a function and read it back in on reload



    Regards,
    Last edited by ; 01-22-2004, 10:03 PM.

    Comment


    • #3
      David and Steve
      I know the following solution works as I have used it in various formulas for a while
      Alex

      PHP Code:
      var vLastCount null

      function 
      main(){

      if(
      vLastCount == null
              
      vLastCount getNumBars(); 
          if(
      vLastCount != getNumBars()) { 
              
      vLastCount getNumBars(); 
              
      reloadEFS(); 
              
      //debugPrintln("reload");
          
      return; 
         } 
      //your code here

      Comment


      • #4
        Steve,

        You will reload every second bar (well second bar in RT, not historical)...and do it forever because loadup will == 2 each time two new bars happen.

        Are you seeing other behavior?

        Garth
        Garth

        Comment


        • #5
          Garth,

          It should go every second bar because on reload, I am setting loadup variable back to zero every time it reloads

          if (getBarState() == BARSTATE_ALLBARS) {//true once during initial load and subsequent reload
          loadup=0;
          }

          then it is only incremented on new bars once we are fully loaded

          if(getBarState()==BARSTATE_NEWBAR){
          ....
          if (getCurrentBarIndex()==0){
          loadup++;


          The ticks are coming in really slow and I have not run it in playback mode so I am still monitoring it live, I am not sure how it is working, yet

          Thanks!

          Comment


          • #6
            Old thread, but as yet, unanswered...

            Garth, as you had indicated, the thing will reload every second bar forever, forgot to get back on this one... It had not seemed so obvious at the time, maybe I was so close to it, but in hindsight yes, quite obvious. Maybe because it was just intended to demonstrate reloadEFS()... who knows, but you were right, thanks!

            Regards

            Comment

            Working...
            X