Announcement

Collapse
No announcement yet.

AskForInput

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

  • AskForInput

    All help appreciated. When I use the AskForInput statement in Pre-main, the EFS does a run through Main first, then backtracks to the Pre-main.

    var fp9 = new FunctionParameter("sFilenme", FunctionParameter.STRING);
    fp9.setName("File name (junk)");
    fp9.setDefault("junk");


    askForInput();

    //End PreMain

    }

    function main(nMaval,nMavaj,nMavat,nMavad,Busema,nLookback, nTakeprofitP,nTakeprofitD,sFilenme)
    {

    This causes the file open procedure to create a file called "junk" from within the Main, then create a second file from the Pre-main using whatever I input as file name.

    What am I doing wrong?

    Cheers, and merry Xmas to you all.

    Mervk

  • #2
    I'd change the line:

    //End PreMain

    to:

    //End PreM-a-i-n

    or something else.

    There is a known "feature" in EFS regarding the text "main". It gets confused if you have more than one "main", even in comments.

    May or may not be your problem... If not, you might want to post the code logic that decides to do the file creation.
    Last edited by shortandlong; 12-22-2009, 09:57 PM.

    Comment


    • #3
      Thank you, but deleted the line, and still didn't alter anything. Code is below:

      var fp9 = new FunctionParameter("sFilenme", FunctionParameter.STRING);
      fp9.setName("File name (junk)");
      fp9.setDefault("junk");
      var fp10 = new FunctionParameter("bAutotrade", FunctionParameter.BOOLEAN);
      fp10.setName("Auto trade? (default = false)");
      fp10.setDefault(false);





      }

      function main(nMaval,nMavaj,nMavat,nMavad,Busema,nLookback, nTakeprofitP,nTakeprofitD,sFilenme,bAutotrade)
      {
      if (init == 0)
      {
      var a = new File(sFilenme+".txt"); //the file will be created in: eSignal/FormulaOutput/
      a.open("at"); // Opens and overwrites the file
      if (!a.isOpen())
      {
      debugPrintln("Could not open file!");
      }
      a.writeln("dir,entry,exit,TP/SL,Accum,Highest,lowest,Cur time,Conditions,Tick value,MA(30)");
      a.flush();
      a.close();
      init = 1;
      }

      Thanks for looking...

      Cheers

      Mervk

      Comment


      • #4
        askForInput() appears to be asynchronous, meaning execution continues while the input dialog box is displayed. This is normally a good thing as ticks continue to be processed using the old parameters.

        Also note that any variables with global scope (outside preMain() and main()) are reinitialized when the input dialog is closed by the user.

        Sample EFS that illustrates this below:

        PHP Code:
        var bGlobalVal 0;

        function 
        preMain() {

            var 
        fp9 = new FunctionParameter("sFilenme"FunctionParameter.STRING);
            
        fp9.setName("File name (junk)");
            
        fp9.setDefault("junk");

            
        askForInput();
        }

        function 
        main(sFilenme) {

            if (
        getCurrentBarIndex() == 0) {
                
        debugPrintln ("getCurrentBarIndex() == 0, sFilenme = " sFilenme ", bGlobalVal = " bGlobalVal);
            }
            
            if (
        getBarState() == BARSTATE_ALLBARS) {
                
        debugPrintln ("getBarState() == BARSTATE_ALLBARS, sFilenme = " sFilenme ", bGlobalVal = " bGlobalVal);
                
        bGlobalVal 1;
            }

        Output with OLDEST LINES AT THE TOP (from formulaoutput.log):

        // lines below occur before dialog box is closed by user...
        getBarState() == BARSTATE_ALLBARS, sFilenme = junk, bGlobalVal = 0
        // the following are ticks received while dialog box still displayed...
        getCurrentBarIndex() == 0, sFilenme = junk, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = junk, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = junk, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = junk, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = junk, bGlobalVal = 1
        // dialog box closed by user, note bGlobalVal has been reset...
        getBarState() == BARSTATE_ALLBARS, sFilenme = NOTJUNK, bGlobalVal = 0
        getCurrentBarIndex() == 0, sFilenme = NOTJUNK, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = NOTJUNK, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = NOTJUNK, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = NOTJUNK, bGlobalVal = 1
        getCurrentBarIndex() == 0, sFilenme = NOTJUNK, bGlobalVal = 1

        I tested this with an index ($INDU). Otherwise the output window fills up too fast.

        The best I can suggest is set your filename FunctionParameter default value to blank and test it in main - basically suspending your processing until filename is non-blank.
        Last edited by shortandlong; 12-23-2009, 10:48 AM.

        Comment


        • #5
          "The best I can suggest is set your filename FunctionParameter default value to blank and test it in main - basically suspending your processing until filename is non-blank."

          Thank you, this is the answer I was searching for. I shall simply return until it is populated. The simple things are the hardest to remember some times ....

          Thanks again.

          Mervk

          Comment

          Working...
          X