Announcement

Collapse
No announcement yet.

Counting the number of seconds elapsed in a bar

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

  • Counting the number of seconds elapsed in a bar

    Hello,
    I am trying to count the number of seconds elapsed in a bar, in PLAYBACK mode with 5 min timeframe.

    However, the number of seconds returned is always 0. Can anyone help ?


  • #2
    Hi sivermotion,

    What you posted appears to be normal. The time gets updated at the beginning of the bar, so the time will only update every 5 minutes. Meanwhile, you are outputting the time every tick based on bartime.


    Originally posted by silvermotion
    Hello,
    I am trying to count the number of seconds elapsed in a bar, in PLAYBACK mode with 5 min timeframe.

    However, the number of seconds returned is always 0. Can anyone help ?


    Here is a code snippet that will work in Playback, I have is set to 3 Seconds. Also be very careful with using debugPrintln. Without clearing the window periodically, the accumulated output is an increasing burden on resources and will really slow things down.


    Hope this helps.



    PHP Code:
    /*************************************************
    By Steve Hare © November 2008 
    Demonstration EFS showing how to count seconds in tick playback
    by obtain the hours, minutes and seconds of a different interval and use it in the primary efs 
    in a conditional

    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.  
    *************************************************/

    function preMain(){
     
    //~ setPriceStudy(false);
     
    setPriceStudy(true);
     
    setStudyTitle("seconds in Playback");
     
    setShowCursorLabel(false);
     
    setShowTitleParameters(false);
    }

    var 
    lastSec,sec3,min3,hour3,time3,bInit;
     
    function 
    main(){ 
     if(!
    bInit){ // !undefined evaluates to true 
      
    var t3="3S"// using 3 seconds
      
    sec3=second(inv(t3));
      
    min3=minute(inv(t3));
      
    hour3=hour(inv(t3));
      
    time3=hour3.getValue(0)+":"+min3.getValue(0)+":"+sec3.getValue(0);
      
    debugPrintln("29: time = "+time3);
      
    bInit=true;
     }
     
     var 
    tmpSec=sec3.getValue(0);
     if(
    tmpSec!=lastSec){ // will be true every  3 seconds
      
    time3=hour3.getValue(0)+":"+min3.getValue(0)+":"+sec3.getValue(0);
      
    debugPrintln("36: time = "+time3); 
      
    lastSec=tmpSec;
     }

    Comment

    Working...
    X