Announcement

Collapse
No announcement yet.

time length of a bar ona Volume chart

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

  • time length of a bar ona Volume chart

    Is there a function that will tell me the duration of a bar on a Volume chart, specifically, with ComputeOnClose() set, and a bar just completed, I can get the start time. Because the local PC may not be synchronised I can't see a way of getting the end time or duration of the bar.

  • #2
    On Volume charts, there is no defined end time. You would have to poll the getInterval() feature and write code to calculate the amount of volume left to complete the bar. This value could also be converted into %% or other common types of values, but not TIME as the TIME LEFT is a complete unknown.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Hi Doji
      Thanks, but I'm not really interested in when it _will_ finish (as you seem to suggest from "volume left"), but when it _does_ finish I want to know how long it lasted, without recourse to the PC clock, and with ComputeOnClose ste.

      Although I guess I could generate the error term for the PC clock based on earlier candles, that won't be enirely accurate as it will be dependent on changing latency etc.

      Comment


      • #4
        just check the time difference between the two bars. For example, the first bar may have started at 10:17:43 and the next bar may have started at 10:41:22.

        Convert those two times into TOTAL SECONDS and you end up with

        37063 & 38482

        Subtract the later from the first and you end up with the time it took to form the previous bar in the total # of seconds = 1419.

        Now, start reverse engineering the time..

        1419/3600 = 0.394167 - in other words NO TOTAL HOURS
        1419/60 = 23.65 - a total of 23 whole minutes
        23 whole minutes = 1380 total seconds
        1419-1380 = 39 Seconds

        So the difference between the two bars is 23 minutes and 39 seconds.

        Hope this helps.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Hi doji
          Yes, now how do I do it for "a bar just completed", ie no "next bar" yet?

          Comment


          • #6
            function preMain() {
            setPriceStudy(false);
            setStudyTitle("completTime");
            setCursorLabelName("cT", 0);
            setDefaultBarStyle(PS_SOLID, 0);
            setDefaultBarFgColor(Color.red, 0);
            setDefaultBarThickness(1, 0);
            setPlotType(PLOTTYPE_LINE, 0);
            }

            function main() {
            return (rawtime(0)-rawtime(-1));
            }

            //might help

            Comment


            • #7
              Hi
              Thanks, but with ComputeOnClose set "nCandle = 0" is the bar that has just closed, not the one just starting, so we can't get the start time of the candle that is just beginning so as to measure the length of the candle that has just completed.

              Comment


              • #8
                //never mind then

                Comment


                • #9
                  Originally posted by Dave180
                  Hi doji
                  Yes, now how do I do it for "a bar just completed", ie no "next bar" yet?
                  Like this..

                  PHP Code:

                  var DailyNet 0;
                  var 
                  nLastRawTime null;
                  var 
                  BarCounter 0;
                  //============================
                  var vRTHour 0;
                  var 
                  vRTMin 0;
                  var 
                  vRTSec 0;
                  var 
                  vHour 0;
                  var 
                  vMin 0;
                  var 
                  vSec 0;
                  var 
                  vDay 0;
                  var 
                  vMonth 0
                  var 
                  vDOW 0;
                  var 
                  nTime 0;
                  var 
                  nBarSecTime 0;


                  function 
                  main() {


                     var 
                  vTime = new Date();
                     
                  vRTHour vTime.getHours();
                     
                  vRTMin vTime.getMinutes();
                     
                  vRTSec vTime.getSeconds();
                  //---------------------------------------------------
                  //  Get Time Variables 
                    
                  vTime getValue("Time"0);
                    
                  vHour vTime.getHours();
                    
                  vMin vTime.getMinutes();
                    
                  vSec vTime.getSeconds();
                    
                  vDay vTime.getDate();
                    
                  vMonth vTime.getMonth() +1
                    
                  vDOW vTime.getDay();
                    var 
                  vYear vTime.getYear();
                    var 
                  nTimeMin = (vHour*60)+vMin;
                    
                  nTime = (vHour*100)+vMin;
                    
                  vRTTimeMin = (vRTHour*60)+vRTMin;
                    
                  nRTTimeMin = (vRTHour*100)+vRTMin;
                    
                  nRTTime = (vRTHour*3600)+(vRTMin*60)+vRTSec;
                  //==============================
                    
                  var nBarSecTime = (vHour*3600)+(vMin*60)+vSec;
                  //==============================
                    
                  var vtDate vMonth+"/"+vDay+"/"+(vYear+1900);
                    var 
                  BarTime = (vHour*100)+vMin;
                    var 
                  BarDate vMonth+"-"+vDay;
                    

                     if ((
                  getValue("rawtime"0) != nLastRawTime) ) {
                  ////   New Bar Just Formed
                       
                  nLastRawTime getValue("rawtime"0);
                       
                  BarCounter += 1;


                       var 
                  vSecondTimeFromLastBar = (fMakeTotalSeconds(getValue("time"0)) - fMakeTotalSeconds(getValue("time", -1)) );

                       }  
                  //  end of new bar.

                  }  // end of main

                  funciton fMakeTotalSeconds(t__Time) {

                    var 
                  vtHour t__Time.getHours();
                    var 
                  vtMin t__Time.getMinutes();
                    var 
                  vtSec t__Time.getSeconds();

                     return ( (
                  vtHour *3600)+(vtMin *60)+vtSec );

                  This code should operate as an example of how to use the TOTAL SECONDS between bars to generate the TOTAL TIME between bars (which may be easier to store in total seconds eventually).
                  Brad Matheny
                  eSignal Solution Provider since 2000

                  Comment


                  • #10
                    by the way, you'll have to give up on using setComputeOnClose(true) if you want to use my solution. I've found the way I look for new bars allows be to build almost any script I want for people.

                    If you're used to having your script operate with SCOC, then you might have to change the logic to reflect "one bar earlier" for all your triggers/alerts.

                    For example, with SCOC, your triggers might look like

                    if ( (close(0) > open(0)) && (high(0) > high(-1)) && (low(0) > low(-1)) ) {
                    .. do something
                    }

                    whereas with my solution, everything in this statement has to reference one bar earlier because we're only running this portion of the code "when a new bar forms and the last bar finishes"... like this

                    if ( (close(-1) > open(-1)) && (high(-1) > high(-2)) && (low(-1) > low(-2)) ) {
                    .. do something
                    }
                    Brad Matheny
                    eSignal Solution Provider since 2000

                    Comment


                    • #11
                      you'll have to give up on using setComputeOnClose(true)
                      Unfortunately it is exactly this requirement that makes the problem exist. Without that need I don't think there is a problem at all as you wait for NEWBAR and use whatever candle time functions with nCandle = 0 and -1 to get the just starting and completed candles and obtain the starting times of both.

                      Anyone else got any suggestions please, or is there no way to do this?

                      Comment


                      • #12
                        You can do it the same way I explained in my example WITH SCOC enabled. The difference is instead of checking the TIME of bar 0 and bar -1 for the difference in total time, you would have to use the system's RT clock and compare that to the TIME of BAR 0 (the bar that just completed). This will allow you to compare the RT Computer Time with the BAR 0 time to determine the length (in total seconds) for that bar.

                        So you can use SCOC with this, you just have to change how it addresses the two times to represent REAL VALUES.
                        Brad Matheny
                        eSignal Solution Provider since 2000

                        Comment


                        • #13
                          Thanks, but as per below
                          Although I guess I could generate the error term for the PC clock based on earlier candles, that won't be enirely accurate as it will be dependent on changing latency etc
                          I'd like to avoid the latency complication.

                          Comment


                          • #14
                            Originally posted by Dave180
                            Thanks, but as per below
                            I'd like to avoid the latency complication.
                            well then you're stuck unless you are willing to work within the constraints of esignal. Good luck.
                            Brad Matheny
                            eSignal Solution Provider since 2000

                            Comment


                            • #15
                              So it would seem, but I was surprised to find that an obvious solution did not exist, hence the question here.

                              As for
                              willing to work within the constraints of esignal
                              I find it odd that having posted on the main eSignal forum link that I had a cause and fix for at least some of the crashes which accompany 10 I have not had eSignal contact me, in fact even having mentioned it to one of their support guys when they phoned about the ongoing ES tick data problems I've not heard a word!

                              Seems they almost want us to "work within the constraints".

                              Comment

                              Working...
                              X