Announcement

Collapse
No announcement yet.

reloadEFS - who understands this behavior?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • reloadEFS - who understands this behavior?

    Hello cracks,

    I know that calling reloadEFS() in main could create a loop
    but I don´t understand in the lower example
    why it does create a loop after pressing "reload"-button with the variable nLoop=4
    but doesn´t create a loop with nLoop=1.

    Please could anyone clarify?

    PHP Code:
    function preMain() {
         
    setPriceStudy(true);
         
    setShowCursorLabel(false); 
    }

    debugClear(); 
    var 
    nLoop   0
    var 
    bReload false

    function 
    main() {     
         
    trigger();     // sets bReload or not
         
    if (bReload) {
             
    bReload     false;
             
    nLoop++;
             
    debugPrintln("  Reloaded Chart  ,     nLoop: "+nLoop);
             if (
    nLoop==|| nLoop==4)       reloadEFS();     // !!!!!!!!  works with nLoop==1 but not with nLoop==4
             
    else {    // Reload-Button
                 
    drawTextRelative(115" Reload @URL=EFS:reloadexec"nullnullText.BUTTON 
                                  
    Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull10"Reload");
             }
         }
         return 
    close(); 
    }  

    function 
    trigger() {
         var 
    nState getBarState();
         var 
    nIndex getCurrentBarIndex();
         if (
    nIndex == && (nState == BARSTATE_NEWBAR || nState == BARSTATE_ALLBARS)) {
             
    bReload true;
         } 
         return;


    function 
    reloadexec() {    // Button execute
         
    debugPrintln("*** Reload ***");
         
    reloadEFS();
         return; 

    Last edited by ackmann; 02-07-2009, 11:12 PM.

  • #2
    Re: reloadEFS - who understands this behavior?

    ackmann
    Actually it will also not work when nLoop==1 depending on the initial value you assign to nLoop when you declare it
    To verify this try setting var nLoop=-1 and you will see that at nLoop==1 you will get the same "nested reloadEFS..." message that you get at nLoop==4 when you set var nLoop=0
    This is because when you first load the script it initially reloads the formula at nLoop==1 using only the reloadEFS() command in the main function since you are incrementing the nLoop counter prior to checking its state. Notice in fact that when you first load the script the nLoop counter will display 2. When you subsequently click the Reload button and the nLoop counter is at 3 you are executing both the reloadEFS in the reloadexec and main functions thereby triggering an infinite loop condition that the efs engine recognizes and prevents (see also Steve Hare's explanation in this thread on a similar topic)
    To resolve this try replacing reloadEFS() in the reloadexec function with main(). Once you do this you will see that at nLoop==1 and at nLoop==4 the formula executes 2 reloads without however triggering the nested reloadEFS condition
    Alex


    Originally posted by ackmann
    Hello cracks,

    I know that calling reloadEFS() in main could create a loop
    but I don´t understand in the lower example
    why it does create a loop after pressing "reload"-button with the variable nLoop=4
    but doesn´t create a loop with nLoop=1.

    Please could anyone clarify?

    PHP Code:
    function preMain() {
         
    setPriceStudy(true);
         
    setShowCursorLabel(false); 
    }

    debugClear(); 
    var 
    nLoop   0
    var 
    bReload false

    function 
    main() {     
         
    trigger();     // sets bReload or not
         
    if (bReload) {
             
    bReload     false;
             
    nLoop++;
             
    debugPrintln("  Reloaded Chart  ,     nLoop: "+nLoop);
             if (
    nLoop==|| nLoop==4)       reloadEFS();     // !!!!!!!!  works with nLoop==1 but not with nLoop==4
             
    else {    // Reload-Button
                 
    drawTextRelative(115" Reload @URL=EFS:reloadexec"nullnullText.BUTTON 
                                  
    Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull10"Reload");
             }
         }
         return 
    close(); 
    }  

    function 
    trigger() {
         var 
    nState getBarState();
         var 
    nIndex getCurrentBarIndex();
         if (
    nIndex == && (nState == BARSTATE_NEWBAR || nState == BARSTATE_ALLBARS)) {
             
    bReload true;
         } 
         return;


    function 
    reloadexec() {    // Button execute
         
    debugPrintln("*** Reload ***");
         
    reloadEFS();
         return; 

    Comment


    • #3
      Re: reloadEFS - who understands this behavior?

      cracks?

      Your question in the post seems to contradict the embedded statement in your efs. One refers to creating a loop when nLoop=4 and the other refers to it working with nLoop==1.

      Try starting off with nLoop set to '-1' instead of zero, and try using more debug statements is my advice.


      Originally posted by ackmann
      Hello cracks,

      I know that calling reloadEFS() in main could create a loop
      but I don´t understand in the lower example
      why it does create a loop after pressing "reload"-button with the variable nLoop=4
      but doesn´t create a loop with nLoop=1.

      Please could anyone clarify?

      PHP Code:
      function preMain() {
           
      setPriceStudy(true);
           
      setShowCursorLabel(false); 
      }

      debugClear(); 
      var 
      nLoop   0
      var 
      bReload false

      function 
      main() {     
           
      trigger();     // sets bReload or not
           
      if (bReload) {
               
      bReload     false;
               
      nLoop++;
               
      debugPrintln("  Reloaded Chart  ,     nLoop: "+nLoop);
               if (
      nLoop==|| nLoop==4)       reloadEFS();     // !!!!!!!!  works with nLoop==1 but not with nLoop==4
               
      else {    // Reload-Button
                   
      drawTextRelative(115" Reload @URL=EFS:reloadexec"nullnullText.BUTTON 
                                    
      Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull10"Reload");
               }
           }
           return 
      close(); 
      }  

      function 
      trigger() {
           var 
      nState getBarState();
           var 
      nIndex getCurrentBarIndex();
           if (
      nIndex == && (nState == BARSTATE_NEWBAR || nState == BARSTATE_ALLBARS)) {
               
      bReload true;
           } 
           return;


      function 
      reloadexec() {    // Button execute
           
      debugPrintln("*** Reload ***");
           
      reloadEFS();
           return; 

      Comment


      • #4
        Thank you very much for the fast reply!

        Alex, Steve
        thank you both very much for that fast reply.
        Alex, your detailed explanation already helped a lot. Thanks again. I will try the replacement reloadEFS() -> main this evening.

        I understood that the reloadEFS produced a loop but I think my question is,
        why it doesn´t produce a loop in the initial load ?
        Because in the initial load all bars are loaded two times.
        Is there any possibility to load all bars automatically (without button) more than two times (-or does this the reloadEFS() -> main replacement do)?
        nLoop = 1 as start value was intended by me.
        acki

        Comment


        • #5
          Re: Thank you very much for the fast reply!

          acki
          Assuming I understood correctly what you are asking that is because even though you initially set nLoop to 0 [when you declare the variable] you then increment the value of that variable by 1 at nLoop++ so on initial load the value of nLoop is already 1 hence executing the reloadEFS() command inside the condition if(nLoop==1...).
          As both Steve and I suggested try setting the variable nLoop to -1 when you declare it and you will see that the script will not reload immediately after the initial load. Also, as Steve has already suggested, try using more debug statements as that will help you better understand what is occurring in your script
          Alex


          Originally posted by ackmann
          Alex, Steve
          thank you both very much for that fast reply.
          Alex, your detailed explanation already helped a lot. Thanks again. I will try the replacement reloadEFS() -> main this evening.

          I understood that the reloadEFS produced a loop but I think my question is,
          why it doesn´t produce a loop in the initial load ?
          Because in the initial load all bars are loaded two times.
          Is there any possibility to load all bars automatically (without button) more than two times (-or does this the reloadEFS() -> main replacement do)?
          nLoop = 1 as start value was intended by me.
          acki

          Comment


          • #6
            Alex,

            I think we have a missunderstanding based on some missing information from me (sorry):
            That is I tested the EFS-script not in realtime but in the evening when no new data come in.

            Of course if the initial value of nLoop=-1 there is no initial reload.
            That was clear before. Some debugPrint-statements didn´t help me. Unfortunately also the suggested relaodEFS -> main replacement didn´t bring the desired result.

            But if you try the EFS-script when no new data come in you will see that the initial reloadEFS()-command (in the example at nLoop=1) will execute but all following reloadEFS()-command (at nLoop=4) will not (regardless the start value of nLoop).

            And what goes not in my head (just tell me if I´m stupid! ) is,
            why the initial reloadEFS doesn´t produce an infinitive loop while the following reloadEFS do?
            I am sorry that I was not able to make my question clear for you, but hopefully now my problem is understandable.

            acki

            Comment


            • #7
              acki
              Try the enclosed revision of your script and look at the sequence of events listed in the Formula Output window (a sample is also enclosed below)
              You will see that after the script has reloaded the global variable bReload is false which means that all the commands included in the if (bReload) condition are not executed hence no infinite loop.
              Keep in mind [and this may be where your confusion arises] that the relaodEFS() command does not reset global variables (as explained in this KB article on the reloadEFS() function) so unless you reset them at BARSTATE_ALLBARS they will maintain the state prior to the reload.
              Keep also in mind that in the condition
              if (nIndex == 0 && (nState == BARSTATE_NEWBAR || nState == BARSTATE_ALLBARS))
              you are setting bReload to true ONLY when nIndex==0 and nState==BARSTATE_NEWBAR. This is because the condition nIndex==0 and nState==BARSTATE_ALLBARS will never be true by definition as BARSTATE_ALLBARS occurs on the oldest bar index (ie the first time main is called)
              Hope this helps
              Alex

              PHP Code:
              function preMain() {
                   
              setPriceStudy(true);
                   
              setShowCursorLabel(false); 
              }

              var 
              nLoop   0
              var 
              bReload false

              function 
              main() {  
                   
              debugPrintln("bar index "+getCurrentBarIndex()+" line10 nLoop is "+nLoop+" bReload is "+bReload);
                   
              trigger();     // sets bReload or not
                   
              if (bReload) {
                       
              debugPrintln("bar index "+getCurrentBarIndex()+" line13 nLoop is "+nLoop+" bReload is "+bReload)
                       
              bReload     false;
                       
              debugPrintln("bar index "+getCurrentBarIndex()+" line15 nLoop is "+nLoop+" bReload is "+bReload);
                       
              nLoop++;
                       
              debugPrintln("bar index "+getCurrentBarIndex()+" line17 nLoop is "+nLoop)
                       if (
              nLoop==|| nLoop==4) {
                          
              reloadEFS();     // !!!!!!!!  works with nLoop==1 but not with nLoop==4
                          
              debugPrintln("bar index "+getCurrentBarIndex()+" line20 EFS reloaded by main reloadEFS command")
                          
              debugPrintln("bar index "+getCurrentBarIndex()+" line21 nLoop is "+nLoop)
                       }else {    
              // Reload-Button
                           
              drawTextRelative(115" Reload @URL=EFS:reloadexec"nullnullText.BUTTON 
                                            
              Text.RELATIVETOLEFT Text.RELATIVETOBOTTOMnull10"Reload");
                       }
                   }
                   return 
              close(); 
              }  

              function 
              trigger() {
                   var 
              nState getBarState();
                   var 
              nIndex getCurrentBarIndex();
                   if (
              nIndex == && (nState == BARSTATE_NEWBAR || nState == BARSTATE_ALLBARS)) {
                       
              bReload true;
                   } 
                   return;


              function 
              reloadexec() {    // Button execute
                   
              debugPrintln("*** Reload ***");
                   
              reloadEFS();
                   return; 




              Originally posted by ackmann
              Alex,

              I think we have a missunderstanding based on some missing information from me (sorry):
              That is I tested the EFS-script not in realtime but in the evening when no new data come in.

              Of course if the initial value of nLoop=-1 there is no initial reload.
              That was clear before. Some debugPrint-statements didn´t help me. Unfortunately also the suggested relaodEFS -> main replacement didn´t bring the desired result.

              But if you try the EFS-script when no new data come in you will see that the initial reloadEFS()-command (in the example at nLoop=1) will execute but all following reloadEFS()-command (at nLoop=4) will not (regardless the start value of nLoop).

              And what goes not in my head (just tell me if I´m stupid! ) is,
              why the initial reloadEFS doesn´t produce an infinitive loop while the following reloadEFS do?
              I am sorry that I was not able to make my question clear for you, but hopefully now my problem is understandable.

              acki

              Comment


              • #8
                Last attempt

                Alex,

                thank you for so much work and for your last answer which allows me to formulate my question the last time (I promise!!! ) as precise as I can:
                I took your version of the code and ran it without data coming in (I unplugged the network). In the attached screenshots you see the results at nLoop=1 and nLoop=4.

                Everything is similar:
                1. bReload is the same
                2. The processed lines are the same
                3. In both cases all bars were loaded before
                4. nLoop=1 and nLoop=4 both lead to the main reloadEFS() command

                But why is then the "nLoop=4 reloadEFS() command" nested whereas the "nLoop=1 reloadEFS() command" is not.

                Where is the difference between the two situations (nLoop=1 and nLoop=4) which I don´t see so far?

                acki
                Attached Files
                Last edited by ackmann; 02-12-2009, 07:48 AM.

                Comment


                • #9
                  Re: Last attempt

                  acki
                  They are not the same as I see it. The difference is in the fact that at nLoop==3 you are clicking the Reload button to reload the efs hence using the reloadEFS() command in the reloadexec() function which sets nLoop to 4 and executes the reloadEFS() command in the main function thereby triggering the nested reloadEFS condition.
                  At nLoop==1 instead which occurs as you initially load the efs in the chart you are not reloading the efs using the command in the reloadexec() function but using only the one in the main() function
                  If instead of clicking the button you were to run this efs with real time data you would see that at the third new real time bar [ie at nLoop==4] the efs would reload using ONLY the reloadEFS() command in the main() function and you would not get a nested reloadEFS error message.
                  Alex


                  Originally posted by ackmann
                  Alex,

                  thank you for so much work and for your last answer which allows me to formulate my question the last time (I promise!!! ) as precise as I can:
                  I took your version of the code and ran it without data coming in (I unplugged the network). In the attached screenshots you see the results at nLoop=1 and nLoop=4.

                  Everything is similar:
                  1. bReload is the same
                  2. The processed lines are the same
                  3. In both cases all bars were loaded before
                  4. nLoop=1 and nLoop=4 both lead to the main reloadEFS() command

                  But why is then the "nLoop=4 reloadEFS() command" nested whereas the "nLoop=1 reloadEFS() command" is not.

                  Where is the difference between the two situations (nLoop=1 and nLoop=4) which I don´t see so far?

                  acki

                  Comment


                  • #10
                    Thanks again for the explanation!

                    Alex,

                    Thanks again for the explanation!

                    acki

                    Comment


                    • #11
                      Re: Thanks again for the explanation!

                      acki
                      You are most welcome
                      Alex


                      Originally posted by ackmann
                      Alex,

                      Thanks again for the explanation!

                      acki

                      Comment

                      Working...
                      X