Announcement

Collapse
No announcement yet.

Time of day for Hi and low

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

  • Time of day for Hi and low

    Is there a way to write an EFS that would tell me at what time was the high was made then same thing for the low

    I have EFS that draws the H and L but would like to had the time when it happened

    Then I could connect that to a DDE I think I found how to do that part

    Any help would be appreciated

    Thanks

  • #2
    richbois
    One way you can do that is as follows (this example is for the Low)
    Create two global variables called (for example) xLow and xTimeLow and set them initially to null.
    Then in the main function create a condition that checks for the first instance of a new day - in which case you set the initial values for xLow and xTimeLow - else you store the lower of the values of xLow or of the current Low



    Once you have done that all you need to do is evaluate when the current low is equal to your xLow variable and record the time of that event storing it in the variable xTimeLow.



    xTimeLow at this point will represent the last time at which the Low was the lowest value in the day
    Use the same logic to determine the time for the High of the day.
    Another method (albeit less efficient IMHO) would be to loop back through all the bars of the day and find the most recent one that has a Low that matches the Low of the daily bar.
    Alex


    Originally posted by richbois
    Is there a way to write an EFS that would tell me at what time was the high was made then same thing for the low

    I have EFS that draws the H and L but would like to had the time when it happened

    Then I could connect that to a DDE I think I found how to do that part

    Any help would be appreciated

    Thanks

    Comment


    • #3
      small problem

      Thank you Alexis

      I made the EFS like you said

      the lines draw properly on the chart for the high and the low

      however I cant get the text for the Time

      Could you tell me what is wrong

      function preMain() {
      setPriceStudy(true);
      setStudyTitle("Hi Lo");
      }

      var vHigh = null;
      var vTimeHigh = null;
      var vLow = null;
      var vTimeLow = null;

      function main() {
      var vInt = getInterval();
      if (vInt != "15" ) return;

      if (getBarState() == BARSTATE_NEWBAR && day(0) !=day(-1)) {

      vHigh = high(0);
      vTimeHigh = (hour(0)*100)+minute(0);
      vLow = low(0);
      vTimeLow = (hour(0)*100)+minute(0);
      }else{
      vHigh = Math.max(vHigh,high(0));
      vLow = Math.min(vLow,low(0));
      }

      if(high(0) ==vHigh) vTimeHigh = (hour(0)*100)+minute(0);
      if(low(0) ==vLow) vTimeLow = (hour(0)*100)+minute(0);

      drawLineRelative(-26, vHigh, 0, vHigh, PS_SOLID, 2, Color.lime, "High");
      drawLineRelative(-26, vLow, 0, vLow, PS_SOLID, 2, Color.red, "Low");
      drawTextRelative(0, vHigh, vTimeHigh, Color.black, Color.lime, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "High" );
      drawTextRelative(0, vLow, vTimeLow, Color.black, Color.red, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Low" );


      return ;

      }

      Comment


      • #4
        Re: small problem

        richbois
        You need to run a null check on the variables vTimeHigh and vTimeLow prior to using them in the drawTextRelative() function
        Alex


        Originally posted by richbois
        Thank you Alexis

        I made the EFS like you said

        the lines draw properly on the chart for the high and the low

        however I cant get the text for the Time

        Could you tell me what is wrong

        function preMain() {
        setPriceStudy(true);
        setStudyTitle("Hi Lo");
        }

        var vHigh = null;
        var vTimeHigh = null;
        var vLow = null;
        var vTimeLow = null;

        function main() {
        var vInt = getInterval();
        if (vInt != "15" ) return;

        if (getBarState() == BARSTATE_NEWBAR && day(0) !=day(-1)) {

        vHigh = high(0);
        vTimeHigh = (hour(0)*100)+minute(0);
        vLow = low(0);
        vTimeLow = (hour(0)*100)+minute(0);
        }else{
        vHigh = Math.max(vHigh,high(0));
        vLow = Math.min(vLow,low(0));
        }

        if(high(0) ==vHigh) vTimeHigh = (hour(0)*100)+minute(0);
        if(low(0) ==vLow) vTimeLow = (hour(0)*100)+minute(0);

        drawLineRelative(-26, vHigh, 0, vHigh, PS_SOLID, 2, Color.lime, "High");
        drawLineRelative(-26, vLow, 0, vLow, PS_SOLID, 2, Color.red, "Low");
        drawTextRelative(0, vHigh, vTimeHigh, Color.black, Color.lime, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "High" );
        drawTextRelative(0, vLow, vTimeLow, Color.black, Color.red, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Low" );


        return ;

        }

        Comment


        • #5
          Thank you

          Thank you Alexis for your help

          it is all working now and I even got the DDE to work

          you made my day

          Richard

          Comment


          • #6
            Richard
            You are most welcome. Glad to hear I was of help
            Alex


            Originally posted by richbois
            Thank you Alexis for your help

            it is all working now and I even got the DDE to work

            you made my day

            Richard

            Comment


            • #7
              one more problem

              I have the efs running + DDE however the DDE on excel is intermitent

              some times it updates some times not and it changes every time

              i understand today the CDN markets were closed and maybe because of no activities it didnt trigger the DDE

              I included my excel, template to save you from building one and the EFS

              please let me know if i did something wrong

              Thank you in advance

              Comment


              • #8
                Re: one more problem

                Originally posted by richbois
                I have the efs running + DDE however the DDE on excel is intermitent

                some times it updates some times not and it changes every time

                i understand today the CDN markets were closed and maybe because of no activities it didnt trigger the DDE

                I included my excel, template to save you from building one and the EFS

                please let me know if i did something wrong

                Thank you in advance
                Attached Files

                Comment


                • #9
                  Re: one more problem

                  Originally posted by richbois
                  I have the efs running + DDE however the DDE on excel is intermitent

                  some times it updates some times not and it changes every time

                  i understand today the CDN markets were closed and maybe because of no activities it didnt trigger the DDE

                  I included my excel, template to save you from building one and the EFS

                  please let me know if i did something wrong

                  Thank you in advance
                  oops cant include excel
                  Attached Files

                  Comment


                  • #10
                    Re: one more problem

                    Richard
                    Declare the variables ddeTH and ddeTL as global variables and set them initially to null
                    Then replace the following two lines of code in your efs (lines 54 and 55)(
                    var ddeTH = new DDEOutput( "TH" + sName );
                    var ddeTL = new DDEOutput( "TL" + sName );

                    with the following
                    if(ddeTH==null) ddeTH = new DDEOutput( "TH" + sName );
                    if(ddeTL==null) ddeTL = new DDEOutput( "TL" + sName );

                    Once you make these changes the script should be working fine
                    Alex


                    Originally posted by richbois
                    I have the efs running + DDE however the DDE on excel is intermitent

                    some times it updates some times not and it changes every time

                    i understand today the CDN markets were closed and maybe because of no activities it didnt trigger the DDE

                    I included my excel, template to save you from building one and the EFS

                    please let me know if i did something wrong

                    Thank you in advance

                    Comment


                    • #11
                      similar problem

                      Hi Alexis

                      I dont know if I cam impose one more time.

                      It is in the same vein as last time but now I need to get the time but going back in time and not as we go.

                      The reason is that some instruments trade 24 hrs a day and dont all start at the same time.

                      At this point this EFS does tell me the OHLC but it is not perfect for the open and I would need the time of the High and Low

                      It would be great to know how many bars is in that day then all could be done right.

                      Thank you in advance for your help

                      var sName = null;
                      var ddeO = null;
                      var ddeH = null;
                      var ddeL = null;
                      var ddeC = null;

                      function preMain() {
                      setPriceStudy(true);
                      setStudyTitle("Previous OHLC for TTT test");
                      setShowCursorLabel(false);

                      var fp = new Array(3);
                      fp[0] = new FunctionParameter("nHr", FunctionParameter.STRING);
                      fp[1] = new FunctionParameter("nMin", FunctionParameter.STRING);
                      fp[2] = new FunctionParameter("nSec", FunctionParameter.STRING);

                      for (j = 0; j < 3; ++j) {
                      for (i = 0; i < 60; ++i) {
                      var num = i+"";
                      if (i < 10) num = "0"+i;
                      if (i < 24 && j == 0) {
                      fp[j].addOption(num);
                      } else {
                      fp[j].addOption(num);
                      }
                      }
                      }

                      fp[0].setName("Set Hour");
                      fp[1].setName("Set Minute");
                      fp[2].setName("Set Second");

                      fp[0].setDefault("13");
                      fp[1].setDefault("15");
                      fp[2].setDefault("00");

                      }

                      var vHr = null;
                      var vMin = null;
                      var vSec = null;
                      var newDay = true;
                      var dayCntr = 0;
                      var vOpen = null;
                      var vClose = null;
                      var vHigh = null;
                      var vLow = null;

                      var BarCntr = 0;
                      var bartotal = 0;
                      var vLastArray = null;

                      function main(nHr, nMin, nSec) {
                      var nState = getBarState();
                      var vInt = getInterval();
                      if (vInt >= "30" ) return;

                      if (nState == BARSTATE_NEWBAR) {
                      if (newDay == false && getDay() != getDay(-1) && getDay(-1) != null) newDay = true;
                      if (newDay == true) {
                      var barHr = getHour()+"";
                      if (barHr != null && barHr < 10) barHr = "0"+barHr;
                      var barMin = getMinute()+"";
                      if (barMin != null && barMin < 10) barMin = "0"+barMin;
                      var barSec = getSecond()+"";
                      if (barSec != null && barSec < 10) barSec = "0"+barSec;
                      if(barHr >= nHr && barMin >= (nMin -vInt) && barSec >= nSec) {
                      drawLineRelative(0,0,0,99999,PS_DOT, 1, Color.blue, "NewDay"+dayCntr);
                      drawShapeRelative(0, 5, Shape.DIAMOND, null, Color.blue, Shape.RELATIVETOBOTTOM, "NewDay"+dayCntr);

                      if (getBarState() == BARSTATE_NEWBAR)
                      if ( barHr = nHr && barMin >= (nMin -vInt) && barSec) vClose = close(0),
                      BarCntr +=1;
                      vOpen = open((-1380/vInt))
                      vHigh = high(0);
                      vLow = low(0);
                      for (i = 0; i < (1380/vInt) ; ++i) {
                      vHigh = Math.max(high(-i), vHigh);
                      vLow = Math.min(low(-i), vLow);


                      drawLineRelative(((-1380/vInt)), vOpen, 0, vOpen, PS_SOLID, 2, Color.blue, "Open");
                      //drawTextRelative(-32, vOpen, vOpen, Color.white, Color.blue, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Open" );
                      drawLineRelative(((-1380/vInt)), vHigh, (0), vHigh, PS_SOLID, 2, Color.lime, "High");
                      //drawTextRelative(-3, vHigh, vHigh, Color.black, Color.lime, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "High" );
                      drawLineRelative(((-1380/vInt)), vLow, (0), vLow, PS_SOLID, 2, Color.red, "Low");
                      //drawTextRelative(-13, vLow, vLow, Color.black, Color.red, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Low" );
                      drawLineRelative(((-1380/vInt)), vClose, (0), vClose, PS_SOLID, 2, Color.black, "Close");
                      //drawTextRelative(-13, vClose, vClose, Color.white, Color.black, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Close" );

                      var sName = getSymbol() ;
                      sName = sName.replace("$", ""); // remove $ from string
                      sName = sName.replace("#", ""); // remove # from string
                      sName = sName.replace("-","");
                      sName = sName.replace(".","");
                      sName = sName.replace(" ", "") // replace space with underscore
                      sName = sName.replace("=", "") // replace space with underscore
                      //debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
                      if(ddeO == null) ddeO = new DDEOutput( "O" + sName );
                      if(ddeH == null) ddeH = new DDEOutput( "H" + sName );
                      if(ddeL == null) ddeL = new DDEOutput( "L" + sName );
                      if(ddeC == null) ddeC = new DDEOutput( "C" + sName );
                      O = vOpen;
                      if(O != null) ddeO.set(O);
                      H = vHigh;
                      if(H != null) ddeH.set(H);
                      L = vLow;
                      if(L != null) ddeL.set(L);
                      C = vClose;
                      if(C != null) ddeC.set(C);

                      dayCntr += 1;
                      newDay = false;

                      }
                      }
                      }

                      return ;
                      }
                      }

                      Comment


                      • #12
                        Re: similar problem

                        Richard
                        A simple way to accomplish what you are trying to do is to create a condition that checks for the first bar at (or after) a specific time (for example 15:30 CT for the CME equity index futures) and record the bar count value at that time.
                        To do this you would first need to declare two global variables, one a simple boolean and the other to store the value of the bar count when the condition evaluates to true.
                        PHP Code:
                        var myFlag false;
                        var 
                        myBarCount 0
                        In main you then need to reset myFlag to false at every new day.
                        PHP Code:
                        if(getBarState()==BARSTATE_NEWBAR && day(0)!=day(-1)) myFlag false
                        At this point you can write your condition
                        PHP Code:
                        if(!myFlag && (hour(0)*100)+minute(0)>=1530) {
                            
                        myBarCount getCurrentBarCount();
                            
                        myFlag true;//this prevents the condition from being evaluated any further for that day

                        From this you can at any time determine the index of the first bar of the session or how many bar have elapsed since then in the following ways
                        PHP Code:
                        var myFirstBarOfSession myBarCount getCurrentBarCount();
                        var 
                        myBarsInSession getCurrentBarCount()-myBarCount 
                        That should provide you with the information you are looking for
                        Alex


                        Originally posted by richbois
                        Hi Alexis

                        I dont know if I cam impose one more time.

                        It is in the same vein as last time but now I need to get the time but going back in time and not as we go.

                        The reason is that some instruments trade 24 hrs a day and dont all start at the same time.

                        At this point this EFS does tell me the OHLC but it is not perfect for the open and I would need the time of the High and Low

                        It would be great to know how many bars is in that day then all could be done right.

                        Thank you in advance for your help

                        var sName = null;
                        var ddeO = null;
                        var ddeH = null;
                        var ddeL = null;
                        var ddeC = null;

                        function preMain() {
                        setPriceStudy(true);
                        setStudyTitle("Previous OHLC for TTT test");
                        setShowCursorLabel(false);

                        var fp = new Array(3);
                        fp[0] = new FunctionParameter("nHr", FunctionParameter.STRING);
                        fp[1] = new FunctionParameter("nMin", FunctionParameter.STRING);
                        fp[2] = new FunctionParameter("nSec", FunctionParameter.STRING);

                        for (j = 0; j < 3; ++j) {
                        for (i = 0; i < 60; ++i) {
                        var num = i+"";
                        if (i < 10) num = "0"+i;
                        if (i < 24 && j == 0) {
                        fp[j].addOption(num);
                        } else {
                        fp[j].addOption(num);
                        }
                        }
                        }

                        fp[0].setName("Set Hour");
                        fp[1].setName("Set Minute");
                        fp[2].setName("Set Second");

                        fp[0].setDefault("13");
                        fp[1].setDefault("15");
                        fp[2].setDefault("00");

                        }

                        var vHr = null;
                        var vMin = null;
                        var vSec = null;
                        var newDay = true;
                        var dayCntr = 0;
                        var vOpen = null;
                        var vClose = null;
                        var vHigh = null;
                        var vLow = null;

                        var BarCntr = 0;
                        var bartotal = 0;
                        var vLastArray = null;

                        function main(nHr, nMin, nSec) {
                        var nState = getBarState();
                        var vInt = getInterval();
                        if (vInt >= "30" ) return;

                        if (nState == BARSTATE_NEWBAR) {
                        if (newDay == false && getDay() != getDay(-1) && getDay(-1) != null) newDay = true;
                        if (newDay == true) {
                        var barHr = getHour()+"";
                        if (barHr != null && barHr < 10) barHr = "0"+barHr;
                        var barMin = getMinute()+"";
                        if (barMin != null && barMin < 10) barMin = "0"+barMin;
                        var barSec = getSecond()+"";
                        if (barSec != null && barSec < 10) barSec = "0"+barSec;
                        if(barHr >= nHr && barMin >= (nMin -vInt) && barSec >= nSec) {
                        drawLineRelative(0,0,0,99999,PS_DOT, 1, Color.blue, "NewDay"+dayCntr);
                        drawShapeRelative(0, 5, Shape.DIAMOND, null, Color.blue, Shape.RELATIVETOBOTTOM, "NewDay"+dayCntr);

                        if (getBarState() == BARSTATE_NEWBAR)
                        if ( barHr = nHr && barMin >= (nMin -vInt) && barSec) vClose = close(0),
                        BarCntr +=1;
                        vOpen = open((-1380/vInt))
                        vHigh = high(0);
                        vLow = low(0);
                        for (i = 0; i < (1380/vInt) ; ++i) {
                        vHigh = Math.max(high(-i), vHigh);
                        vLow = Math.min(low(-i), vLow);


                        drawLineRelative(((-1380/vInt)), vOpen, 0, vOpen, PS_SOLID, 2, Color.blue, "Open");
                        //drawTextRelative(-32, vOpen, vOpen, Color.white, Color.blue, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Open" );
                        drawLineRelative(((-1380/vInt)), vHigh, (0), vHigh, PS_SOLID, 2, Color.lime, "High");
                        //drawTextRelative(-3, vHigh, vHigh, Color.black, Color.lime, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "High" );
                        drawLineRelative(((-1380/vInt)), vLow, (0), vLow, PS_SOLID, 2, Color.red, "Low");
                        //drawTextRelative(-13, vLow, vLow, Color.black, Color.red, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Low" );
                        drawLineRelative(((-1380/vInt)), vClose, (0), vClose, PS_SOLID, 2, Color.black, "Close");
                        //drawTextRelative(-13, vClose, vClose, Color.white, Color.black, Text.FRAME | Text.ONTOP | Text.BOLD, null, 9, "Close" );

                        var sName = getSymbol() ;
                        sName = sName.replace("$", ""); // remove $ from string
                        sName = sName.replace("#", ""); // remove # from string
                        sName = sName.replace("-","");
                        sName = sName.replace(".","");
                        sName = sName.replace(" ", "") // replace space with underscore
                        sName = sName.replace("=", "") // replace space with underscore
                        //debugPrintln("DDE Link for Excel =eSignal|EFS!"+sName);
                        if(ddeO == null) ddeO = new DDEOutput( "O" + sName );
                        if(ddeH == null) ddeH = new DDEOutput( "H" + sName );
                        if(ddeL == null) ddeL = new DDEOutput( "L" + sName );
                        if(ddeC == null) ddeC = new DDEOutput( "C" + sName );
                        O = vOpen;
                        if(O != null) ddeO.set(O);
                        H = vHigh;
                        if(H != null) ddeH.set(H);
                        L = vLow;
                        if(L != null) ddeL.set(L);
                        C = vClose;
                        if(C != null) ddeC.set(C);

                        dayCntr += 1;
                        newDay = false;

                        }
                        }
                        }

                        return ;
                        }
                        }

                        Comment


                        • #13
                          Hi Alex

                          First I would like to thank you for all the help you have given me in the past, as I noticed I forgot to thank you the last time.

                          I have been working on this EFS for a week and got it to do a good part of what I want it to do.

                          However I am having an issue with getting it to give me the time of high and low, even an index reference would work as all I want to know is which was done 1st. The rest I can get excel to figure it out.

                          Please look at this when you have time and maybe point me one more time in the right direction

                          Thanks
                          Attached Files

                          Comment


                          • #14
                            Richard
                            Continuing from my previous example once you have determined how many bars there are in the session (ie myBarsInSession) you can use a for loop to calculate the High and the Low of the session and the times at which they occurred as shown in the enclosed image
                            If you just want the bar index at which the High and Low occurred replace (hour(-i)*100)+minute(-i) shown in the example with -i eg
                            if(high(-i)==nHigh) nTimeH = -i;
                            Alex




                            Originally posted by richbois
                            Hi Alex

                            First I would like to thank you for all the help you have given me in the past, as I noticed I forgot to thank you the last time.

                            I have been working on this EFS for a week and got it to do a good part of what I want it to do.

                            However I am having an issue with getting it to give me the time of high and low, even an index reference would work as all I want to know is which was done 1st. The rest I can get excel to figure it out.

                            Please look at this when you have time and maybe point me one more time in the right direction

                            Thanks

                            Comment


                            • #15
                              Thank you Alex for all your help and great work

                              I got it working now

                              Richard

                              Comment

                              Working...
                              X