Announcement

Collapse
No announcement yet.

Up/Down Bar Counter

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

  • Up/Down Bar Counter

    Is there an efs that counts up bars vs down bars that starts counting with the first (9:30 EST) bar of the day?

    If not, could someone kindly code it?

  • #2
    Himalaya
    The enclosed efs should do what you requested.
    It is set to compute only on the close of a bar so the current bar will show no counts in the Cursor Window
    Alex

    PHP Code:
    function preMain(){

    setPriceStudy(true);
    setStudyTitle("UP-DN Bar Counter");
    setCursorLabelName("UP bars",0);
    setCursorLabelName("DN bars",1);
    setDefaultBarFgColor(Color.blue,0);
    setDefaultBarFgColor(Color.red,1);
    setComputeOnClose();

    }

    var 
    vCntrUP 0;
    var 
    vCntrDN 0;

    function 
    main(){

    if((
    getHour()*100)+getMinute()==930){
        
    vCntrUP=0;
        
    vCntrDN=0;
    }

    if(
    close(0)>open(0)){
        
    vCntrUP ++
    }
    if(
    close(0)<open(0)){
        
    vCntrDN ++
    }


    return new Array (
    vCntrUP+"",vCntrDN+"");

    Comment


    • #3
      hi Alex,

      I saw that you have close(0) & open(0) in your code. I 'd like to know why you have those 0's instead of close() & open()

      trying to learn,

      TIA

      Comment


      • #4
        Thanks Alex

        Excellent as always!

        Comment


        • #5
          Himalaya
          My pleasure as always

          plucky
          It doesn't actually make a difference if close() or close(0) are used in this instance (same for open, high, low, etc). However in efs2 (which is in alpha testing at this time - no release date) it is better to explicitly reference the bar since close() by itself actually gains more functionality and may lead to unintended side effects when assigning it to a variable.

          Alex

          Comment


          • #6
            Am I missing something here? Is this a standalone efs or is this a function for another efs? Nothing shows up on the screen in realtime.

            Comment


            • #7
              plumber
              It is a standalone efs. It will not plot anything on the chart but will write in the Cursor Window the number of Up and Down bars since 9:30 (no numbers are shown for the current ie last bar)
              Alex

              Comment


              • #8
                I see, thanks. Now I have another question, I'm trying to get it to plot by histogram and looks like I just butchered the code instead. What am I missing?
                Attached Files

                Comment


                • #9
                  plumber
                  As I wanted to display the values only in the Cursor Window and not in the chart I converted the returned values to strings which a chart does not plot. In line 36 of the image you posted you will see that in the return new Array() statement there is a +"" added to each element which converts it to a string.
                  Replace that line with the following and you will get a plot
                  return new Array (vCntrUP,vCntrDN);
                  Alex

                  Comment


                  • #10
                    Originally posted by ACM View Post
                    Himalaya
                    The enclosed efs should do what you requested.
                    It is set to compute only on the close of a bar so the current bar will show no counts in the Cursor Window
                    Alex

                    PHP Code:
                    function preMain(){

                    setPriceStudy(true);
                    setStudyTitle("UP-DN Bar Counter");
                    setCursorLabelName("UP bars",0);
                    setCursorLabelName("DN bars",1);
                    setDefaultBarFgColor(Color.blue,0);
                    setDefaultBarFgColor(Color.red,1);
                    setComputeOnClose();

                    }

                    var 
                    vCntrUP 0;
                    var 
                    vCntrDN 0;

                    function 
                    main(){

                    if((
                    getHour()*100)+getMinute()==930){
                    vCntrUP=0;
                    vCntrDN=0;
                    }

                    if(
                    close(0)>open(0)){
                    vCntrUP ++
                    }
                    if(
                    close(0)<open(0)){
                    vCntrDN ++
                    }


                    return new Array (
                    vCntrUP+"",vCntrDN+"");

                    Thank you ACM for this help.
                    Can this code work on eSignal V.12 too? I'm asking because you wrote it in 2004.
                    And this code is going to show all previous Up/Down bars at a specific time on Cursor Window?

                    Best Regards

                    Comment

                    Working...
                    X