Announcement

Collapse
No announcement yet.

first X-bars open close

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

  • first X-bars open close

    Hi-
    Ive attached an existing script that I have been trying to alter to do the following:
    Instead of showing the Hi-low, it would show the first bars, say 30 minutes , open and close with the prices labeled to the right as in the existing script.
    I've tried altering the script to acomplish this but I am getting an error each time.
    Thanks for your help.
    dido
    Attached Files

  • #2
    Re: first X-bars open close

    dido
    What error message are you getting? You may want to post the script as you have modified it so that someone can guide you through understanding what is causing the error and how to fix it
    Alex


    Originally posted by dido
    Hi-
    Ive attached an existing script that I have been trying to alter to do the following:
    Instead of showing the Hi-low, it would show the first bars, say 30 minutes , open and close with the prices labeled to the right as in the existing script.
    I've tried altering the script to acomplish this but I am getting an error each time.
    Thanks for your help.
    dido

    Comment


    • #3
      Here is the script with the error I am getting Alexis.
      Thanks
      Attached Files

      Comment


      • #4
        dido
        In the screenshot enclosed below you can see the error message returned by the script which indicates that the first parameter of the setDefaultBarFgColor function in line 61 is invalid
        If you look at Line 61 of your efs you will see that the first parameter is cColorC which is also listed in the arguments of the main() function in line 52. However in the FunctionParameter in line 38 (highlighted in the screesnhot) you have assigned a different name to that parameter ie cColorL
        Once you correct this error you may also want to check if there are other instances in the code in which you have not replaced the variable or parameter names with the appropriate ones. The Formula Output window will indicate any subsequent errors as you correct them
        Alex




        Originally posted by dido
        Here is the script with the error I am getting Alexis.
        Thanks

        Comment


        • #5
          Alexis-
          I believe I made your suggested changes and I did find a few additional errors that I changed but I'm still doing something wrong because I'm getting an error still. Latest attached.
          This newbie thanks you for your help-
          Attached Files

          Comment


          • #6
            dido
            If you look at the error message in the Formula Output window it indicates that the error is in line 90 where cColorL [which is the color of the drawn line] is not defined.
            Alex




            Originally posted by dido
            Alexis-
            I believe I made your suggested changes and I did find a few additional errors that I changed but I'm still doing something wrong because I'm getting an error still. Latest attached.
            This newbie thanks you for your help-

            Comment


            • #7
              Alexis thanks that appears to be working fine in the 30min open/close time frame, however when I change the close parameters to say 60min or 135min, the close is not accurate. The chart attached is on a 15 min chart, set with a 60 minute close .efs (attached) but the chart is reflecting 1815 as the close when the 60 min close was 1831.25.
              Thanks

              function preMain() {
              setPriceStudy(true);
              setStudyTitle("First X mins OC ");
              setCursorLabelName("60m O", 0);
              setCursorLabelName("60m C", 1);
              setDefaultBarFgColor(Color.blue, 0);
              setDefaultBarFgColor(Color.blue, 1);
              setDefaultBarThickness(1, 0);
              setDefaultBarThickness(1, 1);
              setPlotType(PLOTTYPE_FLATLINES, 0);
              setPlotType(PLOTTYPE_FLATLINES, 1);

              var fp1 = new FunctionParameter("nMin", FunctionParameter.NUMBER);
              fp1.setName("Number of Minutes");
              fp1.setLowerLimit(1);
              fp1.setDefault(60);

              var fp2 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
              fp2.setName("Line Thickness");
              fp2.setLowerLimit(1);
              fp2.setDefault(1);

              var fp3 = new FunctionParameter("cColorO", FunctionParameter.COLOR);
              fp3.setName("Open Color");
              fp3.setDefault(Color.blue);

              var fp4 = new FunctionParameter("cColorC", FunctionParameter.COLOR);
              fp4.setName("Close Color");
              fp4.setDefault(Color.red);
              }

              var bEdit = true;
              var bActive = true;
              var nDayCntr = 0;

              var vStartTime = null;
              var vOpen = null;
              var vClose = null;
              var FirstBar = null;

              function main(nMin, nThickness, cColorO, cColorC) {
              if (nMin == null) nMin = 60;
              if (bEdit == true) {
              nMin = Math.round(nMin);
              setCursorLabelName(nMin + "min O", 0);
              setCursorLabelName(nMin + "min C", 1);
              setDefaultBarThickness(nThickness, 0);
              setDefaultBarThickness(nThickness, 0);
              setDefaultBarFgColor(cColorO, 0);
              setDefaultBarFgColor(cColorC, 1);
              bEdit = false;
              }

              if (getDay() != getDay(-1) || vOpen == null || vClose == null) {
              bActive = true;
              nDayCntr += 1;
              vStartTime = getValue("Time");
              vOpen = open();
              vClose = close();
              }
              FirstBar = getFirstBarIndexOfDay(vStartTime);
              var vTime = getValue("Time");

              // 3,600,000 milliseconds = 1 hour
              // 60,000 milliseconds = 1 minute
              if ((vTime - vStartTime)/60000 < nMin) {
              vOpen = Math.max(open(), vOpen);
              vClose = Math.min(close(), vClose);
              } else {
              bActive = false;
              }

              if (FirstBar != null) {
              drawLineRelative( FirstBar, vOpen, 0, vOpen, PS_SOLID, nThickness,
              cColorO, "Oline");
              drawTextRelative( 2, vOpen, vOpen.toFixed(4), cColorO, null,
              Text.VCENTER|Text.BOLD, null, 10, "Open");
              drawLineRelative( FirstBar, vClose, 0, vClose, PS_SOLID, nThickness,
              cColorC, "Cline")
              drawTextRelative( 2, vClose, vClose.toFixed(4), cColorC, null,
              Text.VCENTER|Text.BOLD, null, 10, "Close");
              }

              if (bActive == false) {
              return new Array(vOpen.toFixed(4), vClose.toFixed(4));
              }
              return null;
              }
              Attached Files

              Comment


              • #8
                dido
                While the script may not be returning the values you are expecting they are actually correct based on the logic you have in the following lines of code



                where you are assigning the highest Open within the defined period to the variable vOpen and the lowest Close of the defined period to the variable vClose (which btw if you ran this in real time during the defined period would also equate to the lowest Low of the period)
                If you want the opening and closing values of the defined period then remove line 67 and assign close(0) to the variable vClose in line 68
                Alex


                Originally posted by dido
                Alexis thanks that appears to be working fine in the 30min open/close time frame, however when I change the close parameters to say 60min or 135min, the close is not accurate. The chart attached is on a 15 min chart, set with a 60 minute close .efs (attached) but the chart is reflecting 1815 as the close when the 60 min close was 1831.25.
                Thanks

                function preMain() {
                setPriceStudy(true);
                setStudyTitle("First X mins OC ");
                setCursorLabelName("60m O", 0);
                setCursorLabelName("60m C", 1);
                setDefaultBarFgColor(Color.blue, 0);
                setDefaultBarFgColor(Color.blue, 1);
                setDefaultBarThickness(1, 0);
                setDefaultBarThickness(1, 1);
                setPlotType(PLOTTYPE_FLATLINES, 0);
                setPlotType(PLOTTYPE_FLATLINES, 1);

                var fp1 = new FunctionParameter("nMin", FunctionParameter.NUMBER);
                fp1.setName("Number of Minutes");
                fp1.setLowerLimit(1);
                fp1.setDefault(60);

                var fp2 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);
                fp2.setName("Line Thickness");
                fp2.setLowerLimit(1);
                fp2.setDefault(1);

                var fp3 = new FunctionParameter("cColorO", FunctionParameter.COLOR);
                fp3.setName("Open Color");
                fp3.setDefault(Color.blue);

                var fp4 = new FunctionParameter("cColorC", FunctionParameter.COLOR);
                fp4.setName("Close Color");
                fp4.setDefault(Color.red);
                }

                var bEdit = true;
                var bActive = true;
                var nDayCntr = 0;

                var vStartTime = null;
                var vOpen = null;
                var vClose = null;
                var FirstBar = null;

                function main(nMin, nThickness, cColorO, cColorC) {
                if (nMin == null) nMin = 60;
                if (bEdit == true) {
                nMin = Math.round(nMin);
                setCursorLabelName(nMin + "min O", 0);
                setCursorLabelName(nMin + "min C", 1);
                setDefaultBarThickness(nThickness, 0);
                setDefaultBarThickness(nThickness, 0);
                setDefaultBarFgColor(cColorO, 0);
                setDefaultBarFgColor(cColorC, 1);
                bEdit = false;
                }

                if (getDay() != getDay(-1) || vOpen == null || vClose == null) {
                bActive = true;
                nDayCntr += 1;
                vStartTime = getValue("Time");
                vOpen = open();
                vClose = close();
                }
                FirstBar = getFirstBarIndexOfDay(vStartTime);
                var vTime = getValue("Time");

                // 3,600,000 milliseconds = 1 hour
                // 60,000 milliseconds = 1 minute
                if ((vTime - vStartTime)/60000 < nMin) {
                vOpen = Math.max(open(), vOpen);
                vClose = Math.min(close(), vClose);
                } else {
                bActive = false;
                }

                if (FirstBar != null) {
                drawLineRelative( FirstBar, vOpen, 0, vOpen, PS_SOLID, nThickness,
                cColorO, "Oline");
                drawTextRelative( 2, vOpen, vOpen.toFixed(4), cColorO, null,
                Text.VCENTER|Text.BOLD, null, 10, "Open");
                drawLineRelative( FirstBar, vClose, 0, vClose, PS_SOLID, nThickness,
                cColorC, "Cline")
                drawTextRelative( 2, vClose, vClose.toFixed(4), cColorC, null,
                Text.VCENTER|Text.BOLD, null, 10, "Close");
                }

                if (bActive == false) {
                return new Array(vOpen.toFixed(4), vClose.toFixed(4));
                }
                return null;
                }

                Comment


                • #9
                  Alexis-
                  I think I made the changes as directed but the script is still not giving me a close (in real-time) that I input.
                  Here's a screencap 15 min bars with a 45min close for the lime line .
                  Also here are the changes I made to the script.
                  Attached Files

                  Comment


                  • #10
                    Alex-
                    Here's the second attachment
                    Attached Files

                    Comment


                    • #11
                      dido
                      In line 67 you are still assigning the lowest Close of the defined period ie Math.min(close(0), vClose); to the variable vClose. Replace that with close(0) as I suggested in my previous reply and the script will work as expected
                      Alex


                      Originally posted by dido
                      Alexis-
                      I think I made the changes as directed but the script is still not giving me a close (in real-time) that I input.
                      Here's a screencap 15 min bars with a 45min close for the lime line .
                      Also here are the changes I made to the script.

                      Comment


                      • #12
                        Having limited .efs script knowledge, I didn't understand what you initially meant Alex. The script is working now though.

                        Comment


                        • #13
                          dido
                          If you are unfamiliar with programming in efs then you may find it to your benefit to learn to do that as it will enable you to take full advantage of the resources offered by a programmable application such as eSignal. The best way is to start by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
                          Alex


                          Originally posted by dido
                          Having limited .efs script knowledge, I didn't understand what you initially meant Alex. The script is working now though.

                          Comment

                          Working...
                          X