Announcement

Collapse
No announcement yet.

How to reset main() function parametrs ?

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

  • How to reset main() function parametrs ?

    Well,
    I have the main() function that gets parameters from FunctionParameters and askForInput.
    I load the first time the efs on the chart and parameters are null.
    I input the parameter for the first time and these parameters stay as an input also if I reload the efs. They never resets.
    To reset parameters to null I have to remove and reload efs.
    Is there another way to resets automatically input parameter everytime I reload a chart ???
    Thanks
    Massimo

  • #2
    I'll try to be more clear.
    Is possible to reset edit parameters to default value without removing and reloading the formula efs.
    Thanks

    Comment


    • #3
      Hi maxmax68

      Just create a global variable, equate it to the menu variable in the bInit routine. Always use the global variable in the efs body/functions instead of the menu variable. Now you can change the value at will in the efs body or functions. Here is a simple example:

      PHP Code:
      debugClear();
      var 
      aFPArray = new Array();
      function 
      preMain() {
          var 
      x=0;
          
      aFPArray[x] = new FunctionParameter("xType"FunctionParameter.STRING);
          
      with(aFPArray[x++]){
              
      setDefault("Old Value");
          }
      }
      var 
      newType null;
      var 
      bInit false;
      function 
      main(xType){
          var 
      testResultsnull;
          if(!
      bInit){
              
      bInit true;
              
      newType xType;
          }
          if(
      getCurrentBarIndex() == 0){//use whatever condition fits your needs
              
      debugPrintln("Old newType = "+newType);
              
      newType "New Value";
              
      debugPrintln("new newType = "+newType);
              
      testResults test(newType);
          }
          return;
      }

      function 
      test(fnewType){//modify the parameter name slightly for best results
          //do something with "fnewType"
          
      return ;//return something;

      Wayne
      Last edited by waynecd; 02-13-2011, 07:45 AM.

      Comment


      • #4
        Hi waynecd,
        forgive me for my delayed response but I was on holiday.
        First of all thank you for your kind reply.
        Unfortunately it doesn't fix my problem.
        Using your efs as an example the point is this:
        We have an input parameter "xType" for main function.
        When we load first time the efs on the chart we have for default xType=Old Value.
        Then we edit parameter to a Another Value and we use efs.
        Later we reload the efs and we see that xType is not set to the default Old Value but stays to Another Value.
        To go back the default value we have to remove the efs.
        I was wondering if there was a trick to avoid this.
        Regards,
        Massimo

        Comment


        • #5
          Hi Massimo,

          A code snipet of how you are setting and changing the default value and where would be helpful.

          Later we reload the efs and we see that xType is not set to the default Old Value but stays to Another Value.
          have the main() function that gets parameters from FunctionParameters and askForInput.
          I'm unsure about how you are reloading or why. You don't need to reload a script to change a value defined in preMain FunctionParameters. You just:
          -right click on the chart with the efs
          -select "Edit Studies"
          -change the settings to whatever value value you want as long as it is of the correct value and scope allowed by the FunctionParameters variable type (BOOLEAN, STRING, etc) and the efs requirements.
          -finally click ok. The efs will recalculate using the new value.

          Wayne
          Last edited by waynecd; 02-20-2011, 07:22 PM.

          Comment


          • #6
            Hi Wayne,
            I don't know how to explain better the question.
            Take your code snipet, it's enough.
            -load it on a chart.
            -right click on the chart with the efs
            -select "Edit Studies"
            -change the settings to whatever value you want as long as it is of the correct value and scope allowed by the FunctionParameters variable type (BOOLEAN, STRING, etc) and the efs requirements.
            -finally click ok. The efs will recalculate using the new value.
            -now on the chart you see the name_of_efs(new_edit_value)
            -try to right click on the chart with the efs and reload the efs. It does not come back to default value !!!
            -you will always see on the chart the name_of_efs(new_edit_value) untill you don't right click on the chart with the efs and remove the efs

            My problem is: I want to come back to default value everytime I reload the efs.

            Massimo

            Comment


            • #7
              If you reload using the "Edit Studies - Reload" or refresh via the chart icon, I don't believe you can capture the event so it will retain the last value assigned to the global variable or "FunctionParameters" variable whichever you use. It will not revert to the default once the value has been changed.

              If you are reloading the study from within the efs itself then you need to reset the variable before the "reloadEFS()" command in the conditional statement.

              Since changing a value via the "FunctionParameters" variable in "Edit Studies" also reloads the efs, I would reload it that way.

              Alternatively you could code a button function into the efs so that a button is drawn on the chart that once clicked will change the value back to the default and then reload the study.

              Apart from that, I am out of ideas.

              Good luck.

              Wayne
              Last edited by waynecd; 02-21-2011, 10:35 AM.

              Comment


              • #8
                A Reset Button. Very nice idea !!!
                Thank You Wayne.

                Max

                Comment

                Working...
                X