Announcement

Collapse
No announcement yet.

Error message on EFS

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

  • Error message on EFS

    Hallo

    I wrote an EFS which gives an error message when I run it.

    I get an error saying: line23: high() can only be called in main

    I have no idea what this means, I used another EFS that I have done with different timeframe and different MACD settings. The other EFS is running.

    I include the EFS for any advice, please run it on a short timeframe like 15min.

    Any help will be appreciated.

    Regards

    Kobus
    Attached Files

  • #2
    Hi Kobus,

    I ran this without an issue. What version of eSignal are you running?

    Please place this line in your efs (on line 22) and run it again with the formula output window open.

    PHP Code:
    debugPrintln ("22: Goffset = "+Goffset+" high(0)= "+high(0)+" high(-1)= "+high(-1)+" high(-2)= "+high(-2)+" low(0)= "+low(0)+" low(-1)= "+low(-1)+" low(-2)= "+low(-2)); 
    If you are still getting the error, please post the excerpt from this file:


    "C:\Program Files\eSignal\formulaoutput.log"

    Comment


    • #3
      Hallo Steve

      I get the same message only difference is now it refers to line 22: high() can only be called in main.

      I have version 7.91(Build 732)

      Regards

      Kobus

      Comment


      • #4
        Kobus,

        There were several errors with your script which were resulting in the error message being confusing. Here is a corrected copy of your efs with the different declarations
        in their proper places.

        PHP Code:
        var vMACD
        var 
        vSIG;
        var 
        vLastAlert = -1;
        var 
        Goffset 0;
        var 
        bInit false;

        function 
        preMain() {
         
        setPriceStudy(true);
         
        setStudyTitle("Macd240GBP");
         
        setComputeOnClose(true)
        }

        function 
        main() {
         if(!
        bInit){
          
        vMACD macd(2444,inv(480));
          
        vSIG macdSignal(2444,inv(480));
          
        bInit true;
         }

         
        Goffset = (Math.max(high(0),high(-1),high(-2))-Math.min(low(0),low(-1), low(-2)))/10;

         if (
        vMACD.getValue(0) < vSIG.getValue(0)) onAction1();
         else if (
        vMACD.getValue(0) > vSIG.getValue(0)) onAction2();
         return 
        null;
        }

        function 
        onAction1() {
          if (
        vLastAlert != 1drawShapeRelative(0high(0)+GoffsetShape.DOWNARROW""Color.RGB(0,0,200), Shape.TOP);
          
        vLastAlert 1;
        }

        function 
        onAction2() {
          if (
        vLastAlert != 2drawShapeRelative(0low(0)-GoffsetShape.UPARROW""Color.RGB(0,0,200), Shape.BOTTOM);
          
        vLastAlert 2;

        The biggest mistake you had was with the functions being declared within the main() function. This, I believe, was confusing the compiler.

        Functions should always be declared outside the main function.

        As far as it working when I first loaded and ran the efs, I can only guess. When I reloaded eSignal, I was able to duplicate your error.

        Comment


        • #5
          Hallo Steve

          Thank you very much, now it works perfectly. It really help if some one with more know how help us to get the coding sorted out.

          Can I ask a few more questions:
          1) What does bInit stands for and do?

          2) The other EFS scripts that were working, were not updating all the time as I would have thought the instruction -setComputeOnClose(true)

          should do. Was this problem related to the wrong coding? If not what could cause it? I realized this problem when I refresh the indicator and saw that the arrows changed position.

          3) Is there a way I can get the Arrows to print bigger?

          Once again thank you very much for your help, it is much appreciated.

          Regards

          Kobus

          Comment


          • #6
            Ki Kobus,

            You are most welcome. As to your questions:

            Originally posted by FX989231


            1) What does bInit stands for and do?

            2) The other EFS scripts that were working, were not updating all the time as I would have thought the instruction -setComputeOnClose(true)

            should do. Was this problem related to the wrong coding? If not what could cause it? I realized this problem when I refresh the indicator and saw that the arrows changed position.

            3) Is there a way I can get the Arrows to print bigger?

            1. The variable bInit is a global variable used as a flag to track the initial declaration of your variables. If you pull up any of the EFS2 custom studies on your PC, or the MACD example in the Knowledgebase, you will see it being used. By using this, it ensures you are not repeatably declaring your study declarations. I believe Alex, Chris and Jason all use this method, this is because querying of a global boolean variable is the most efficient means of accomplishing a query like this.

            2. There are several issues at work here. First, it is likely that your assessment is correct, the problems with the code were likely causing problems. Secondly, I believe the setComputeOnClose(true) declaration only works on your chart interval. It does not work on the interval you are using for your macd calculations. These are evaluated every new bar for your chart, not necessarily every new bar of your external interval. Try the efs and see if it performs satisfactorily.

            3. I added a section to your code which will make the arrows bigger. You may adjust the size by changing the font size, which I have set to 15. This is an alternate method of creating arrows. Other shapes are available as well, from the wingding font group. To find additional information on this technique, use the forum search feature to search for wingding* and set the user name to Alexis C. Montenegro. I also modified your Goffset calculation to only calculate a value when required.


            PHP Code:
            var vMACD
            var 
            vSIG;
            var 
            vLastAlert = -1;
            var 
            bInit false;

            function 
            preMain() {
             
            setPriceStudy(true);
             
            setStudyTitle("Macd240GBP");
             
            setComputeOnClose(true);
            }

            function 
            main() {
             if(!
            bInit){
              
            vMACD macd(2444,inv(480));
              
            vSIG macdSignal(2444,inv(480));
              
            bInit true;
             }

             if (
            vMACD.getValue(0) < vSIG.getValue(0)) onAction1();
             else if (
            vMACD.getValue(0) > vSIG.getValue(0)) onAction2();
             return 
            null;
            }

            function 
            onAction1() {
              if (
            vLastAlert != 1) {
              var 
            Goffset = (Math.max(high(0),high(-1),high(-2))-Math.min(low(0),low(-1), low(-2)))/3;
              var 
            gHiMath.max(high(0),high(-1),high(-2));
              
            //drawShapeRelative(0, high(0)+Goffset, Shape.DOWNARROW, "", Color.RGB(0,0,200), Shape.TOP);
              
            drawTextRelative(0,gHi+Goffset,"ê",Color.red,null,Text.BOTTOM|Text.CENTER|Text.BOLD,"Wingdings",15,"Dn"getCurrentBarCount());
              
            vLastAlert 1;
             }
            }

            function 
            onAction2() {
              if (
            vLastAlert != 2){
              var 
            Goffset = (Math.max(high(0),high(-1),high(-2))-Math.min(low(0),low(-1), low(-2)))/3;
              var 
            gLo Math.min(low(0),low(-1), low(-2));
              
            //drawShapeRelative(0, low(0)-Goffset, Shape.UPARROW, "", Color.RGB(0,0,200), Shape.BOTTOM);
              
            drawTextRelative(0,gLo-Goffset,"é",Color.green,null,Text.TOP|Text.CENTER|Text.BOLD,"Wingdings",15,"Up"getCurrentBarCount());
              
            vLastAlert 2;
             }

            Comment


            • #7
              Steve

              Thank you very much for the insight and detailed explanations. It really helps.

              The EFS as adjusted by you is great, I have been trying for ages to get the arrows bigger on my other EFS's, thank you very much.

              Have a great day

              Regards

              Comment


              • #8
                Hi Kobus,

                Nice to hear this helped out, thanks as well for the note.

                Comment

                Working...
                X