Announcement

Collapse
No announcement yet.

Multiple efsExternal(0 Initialization Problem

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

  • Multiple efsExternal(0 Initialization Problem

    Hi,

    I have the following in an efs script:

    if (getBarState() == BARSTATE_ALLBARS) {
    resetVars();
    }
    if(!bInit) {
    trailUp = efsExternal("\\PFormulas\\Trail_Up_v1.00.efs", "e", "e",
    ps, 0.30, 2, 6, 0, Tick);
    tU_p_series = getSeries(trailUp, 0);
    tU_series = getSeries(trailUp, 1);

    trailDwn = efsExternal("\\PFormulas\\Trail_Down_v1.00.efs", "e", "e",
    ps, 0.30, 2, 6, 0, Tick);
    tD_p_series = getSeries(trailDwn, 0);
    tD_series = getSeries(trailDwn, 1);

    testLong = efsExternal("\\PFormulas\\BackTesting\\Patterns\\c 2_Buy_v1.06b.efs", ps, Tick, 1);
    nL_id_series = getSeries(testLong, 0);
    nL_series = getSeries(testLong, 1);
    nL_stp_series = getSeries(testLong, 2);

    testShort = efsExternal("\\PFormulas\\BackTesting\\Patterns\\c 2_Sell_v1.06b.efs", ps, Tick, 1);
    nS_id_series = getSeries(testShort, 0);
    nS_series = getSeries(testShort, 1);
    nS_stp_series = getSeries(testShort, 2);

    bInit = true;
    }

    For some reason the series will not initialize properly. Obviously I am not resetting the global variables correctly but the resetting seems to be OK. I have searched the forums but have never seen anyone use more than one efsExternal inside bInit and so I'd like to ask, if anyone knows, how does one initialize multiple efsExternal inside the bInit code block? If I comment out all but one of the efsExternals in the above, the code initializes and runs properly.

    Thank you in advance for any help anyone might be able to offer.
    Regards,
    Jane

  • #2
    Jane,

    I can't see anything wrong based on the snipet you posted. I have had no problems initializing multiple efsInternal() or efsExternal(), or combo's of the two, in a script.

    Post up a complete script (minimal case example) and I will look it over. You may even find the issue if you start trimming your script to post up a smallest case example...or at least I often find the issue when I start to creat a small script to post up.

    Garth
    Garth

    Comment


    • #3
      Thank you very much for your offer of help Garth. I truly appreciate it. I will do as you suggested. I am not sure if this is important but this is code is a part of a backtesting script.
      Regards,
      Jane

      Originally posted by gspiker
      Jane,

      I can't see anything wrong based on the snipet you posted. I have had no problems initializing multiple efsInternal() or efsExternal(), or combo's of the two, in a script.

      Post up a complete script (minimal case example) and I will look it over. You may even find the issue if you start trimming your script to post up a smallest case example...or at least I often find the issue when I start to creat a small script to post up.

      Garth

      Comment


      • #4
        Garth,

        I took your suggestion and duplicated one of my efsExternal() scripts but this time instead of returning the values I needed, I had it return the bar high, bar low, and bar high-0.10. The code worked perfectly again. This approach, however, gave me the idea to look whether any series were being initialized inside that efsExternal and the answer was yes. This may be the crux of my problem, but it gets me to a point I am not sure how to resolve. The situation therefore appears to be as follows:

        Main script:
        ....
        if(!bInit) {
        s1 = efsExternal("series1.efs"....); //series 1
        s2 = efsExternal("series2.efs"....); //series 2
        s3 = efsExternal("series3.efs"....); //series 3
        bInit = true;
        }
        ....

        Now if series1 in turn initalizes some series, as in say,
        if(!bInit) {
        u1 = efsExternal("series11.efs"....); //series 11
        u2 = efsExternal("series12.efs"....); //series 12
        u3 = efsExternal("series13.efs"....); //series 13
        u4 = ema(...); //MA series
        bInit = true;
        }

        and likewise for the other series; i.e. series2 and series3, how do I initialize the global variables for each sub series; i.e series11, series12, series13 and the u4 ema series from within the main script? I am lost here and any help on how to initialize the global variables for nested series would be greatly appreciated.

        BTW thank you very much for opening my eyes to this approach. It is extremely useful and insightful.
        Regards,
        Jane

        Originally posted by jg
        Thank you very much for your offer of help Garth. I truly appreciate it. I will do as you suggested. I am not sure if this is important but this is code is a part of a backtesting script.
        Regards,
        Jane

        Comment


        • #5
          Jane,

          I have done "nested" series creation, and haven't found it an issue. I'm not sure how many iterations of nesting are supported, so if in your example series 11 also calls another series, which in turn calls another...I'm not sure how many levels will work.

          But I do have cases of a series calling another series. That works fine.

          Global initialization for a called (or subsequntly called) series shouldn't be an issue as the called EFS should have initialized it own unique set of globals. You should find that even if the globals in series 1 and series 11 have the same name, it will still work correctly as each exist in it's own namespace/scope.

          Now If I were you, I would add in the real code (the one you started with that breaks) one series at a time until it breaks. That may help point you to the root cause.

          Feel free to post more as you find out more, or as you need more help.

          Garth
          Garth

          Comment


          • #6
            Hi Garth,

            Thank you very much for your response. I don't have too many levels of nesting. The main script calls four efsExternal. Each of these calls two ema series and generates three series as return values. I will do what you suggested but am not sure exactly what to do because:

            1. if I comment out all but one of the primary script efsExternal, the main script works fine.
            2. If I leave two efsExternal functional in the main script but change the output of the called series, the code again works.

            I think this has something to do with the series called by the efsExternal in the main script . Maybe the value output is being changed somewhere and this is not an initialization issue at all.

            I understand your point regarding the namespace and scope of the variables in the series. This makes perfect sense.

            I will retain two efsExternal in the main script and trace trough the scripts being called to try and isolate the problem. Thank you very much for your patience and advice.

            Regards,
            Jane

            Originally posted by gspiker
            Jane,

            I have done "nested" series creation, and haven't found it an issue. I'm not sure how many iterations of nesting are supported, so if in your example series 11 also calls another series, which in turn calls another...I'm not sure how many levels will work.

            But I do have cases of a series calling another series. That works fine.

            Global initialization for a called (or subsequntly called) series shouldn't be an issue as the called EFS should have initialized it own unique set of globals. You should find that even if the globals in series 1 and series 11 have the same name, it will still work correctly as each exist in it's own namespace/scope.

            Now If I were you, I would add in the real code (the one you started with that breaks) one series at a time until it breaks. That may help point you to the root cause.

            Feel free to post more as you find out more, or as you need more help.

            Garth

            Comment


            • #7
              Hi Garth,

              My main script calls an efsExternal which in turn calls two ema series. In addition, however, it contains the following code snippet:

              //find new trail up
              var l0 = low(0);
              if (trailUp == null) {
              //determine speed of up trend
              ........
              }

              I have traced through the code and the first thing I noticed is that the variable trailUp is not being reset to null. So the first efsExternal loads and trailUp is null and the script runs fine but when the second efsExternal is loaded, and the first efsExternal is run a second time, trailUp retains its last value instead of being reset to null. So I need to reset trailUp to null.

              Since I need to reset trailUp when the script is loaded subsequent times I inserted the following into the main function in my primary (main) script:

              if(getBarState() == BARSTATE_ALLBARS) {
              trailUp = null;
              }

              This did solve the reset of trailUp to null. I will test the code to see whether this solves the entire proble. BTW you were 100% correct about the globals associated with subsequent efsExternals reinitializing themselves correctly. I would still love to know how deeply we can nest but that is a question that perhaps one of the developers can answer. I will now test the code with this modification and let you know what happened. Thank you VERY VERY much for the guidance and help Garth. Your experience and guidance is truly appreciated.

              Best regards,
              Jane

              Comment


              • #8
                Hi Garth,

                My apologies for the delay in responding but I haven't had a chance to test the idea until now. I can now confirm that the solution to this problem is to reset all the global variables inside the scripts called by the main (primary script) - inside a conditional as follows:

                if(getBarState() == BARSTATE_ALLBARS) {
                resetVars(); // reset all global variables here
                }

                The code now works exactly as it should.
                Very many thanks for your advice and guidance.
                Regards,
                Jane

                Comment

                Working...
                X