Announcement

Collapse
No announcement yet.

time elapse between 2 ticks bars

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

  • time elapse between 2 ticks bars

    hello,
    I use ticks bars and I would like to create an indicator which will indicate the time elapse between 2 consecutives bars (delta time with second unit).
    Someone can help me ?
    thank you.

  • #2
    Jeanmark
    The attached script shows one way you can calculate the difference in time between bars and return that value to the Cursor Window. Brief explanation is in the script
    Alex

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("TimeDiff");
        
    setCursorLabelName("Time Diff");
    }
    function 
    main() {

    //Calculate the difference in time and return minutes.seconds (seconds in decimals)
    var rawdiff = ((getValue("rawtime",0)-getValue("rawtime",-1))/60).toFixed(2);
    //Find at what position is the dot for decimal separation
    var rawdiff.indexOf(".",0);
    //Multiply the 2 digits following the dot by 60 and round the results to convert decimals into 60ths
    var Math.round(rawdiff.substr(x+1,2)*.60);
    //Find the integer. This defines the minutes
    var parseInt(rawdiff);
    //Concatenate the integer (ie the minutes) with the : and the seconds.
    var timediff z+":"+y;

    return 
    timediff//Because this is a string it returns only to Cursor Window
    }

    //Notes: To show Hrs:Mins once the difference is greater than 60 minutes 
    //requires further calculations similar to the above applied to variable z 

    Comment


    • #3
      It's Working !!!
      Thank you for your help,
      But ...
      how to plot in second the difference
      thank you.

      Comment


      • #4
        Jeanmark
        Change setPriceStudy(true) to setPriceStudy(false) and then replace var timediff = z+":"+y; with var timediff = getValue("rawtime",0)-getValue("rawtime",-1);
        That should plot the difference expressed in raw seconds
        Alex

        Comment


        • #5
          great .... its working !!!
          thank you alex

          Comment


          • #6
            Jeanmark
            You are most welcome.
            FWIW here is another way of writing the formula posted in my first reply
            Alex

            PHP Code:
            function preMain() {
                
            setPriceStudy(true);
                
            setStudyTitle("TimeDiff");
                
            setCursorLabelName("Time Diff");
            }
            function 
            main() {

            var 
            rawdiffS = (getValue("rawtime",0)-getValue("rawtime",-1)) % 60;
            var 
            rawdiffM parseInt((getValue("rawtime",0)-getValue("rawtime",-1))/60);
            var 
            timediff rawdiffM+":"+rawdiffS;

            return 
            timediff;

            Comment

            Working...
            X