Announcement

Collapse
No announcement yet.

Bar Count from first bar of day

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

  • Bar Count from first bar of day

    I'm trying to count the first 60 bars of the trading day from the opening bar, but can't find what will tell me where the first bar of the day starts to begin my counter. Does anyone know how to ID the day's first bar? I'm using a 150 tick bar chart for the Russell 2000.

    Thanks

  • #2
    werosen
    Create a global variable called for example vCounter and set it to 1. Then in main add the code shown below which will return the bar count from the first bar of the day.
    Alex

    PHP Code:
    if(getDay(0)!=getDay(-1)&&getBarState()==BARSTATE_NEWBAR){
            
    vCounter 1;//this resets the counter on the first bar of the day 
        
    }
        else if(
    getBarState()==BARSTATE_NEWBAR){
            
    vCounter++;//this increases the counter by 1 at every bar
        

    Comment


    • #3
      Great

      Thanks Alex

      Comment


      • #4
        Can Count without an efs?

        Hi Alex,
        I was quite interested in the question Werosen posed & in your response. However, I can't figure out how to just see the bars counted consecutively each day as they unfold, without any efs against which to plot the count. Can that be done? Thanks.
        Diane

        Comment


        • #5
          Diane
          You need an efs to do that. However you don't necessarily need to plot the count. You could return it as a string which an efs does not plot but will display in the Cursor Window. To convert vCounter to a string use return vCounter+""; as the return statement and set the efs as a price study
          Alex

          Comment


          • #6
            Alex,
            So basically I can take any efs, say a simple MA, or whatever, & add the info you gave Werosen , and I would be able to see a number count as each bar appears. The numbers would start with 1 at the first bar of the day. Am I at least in the ball park on this? Thanks
            Diane

            Comment


            • #7
              Diane
              That is correct. Remember to add a setCursorLabelName("name",series) statement in preMain and to add vCounter+"" in the return statement
              In the image below you can see the result after having modified basicMA(s).efs which is in the EFS2 Basic folder. Note that the cursor is on the first bar of the day and the label in the Cursor Window displays 1
              Alex

              Comment


              • #8
                Thanks, Alex. I'll get right to this. However, I notice that the numbers do not show up on the chart next to the bars, which is what I want to see. Are there any additional steps to accomplish that?
                Diane

                Comment


                • #9
                  Diane
                  In that case you need to write them on the chart using drawTextRelative() or its simplified version drawText()
                  Alex

                  Comment


                  • #10
                    Thanks, again, so much, Alex. I'll get started right away. You are a treasure. I appreciate your time & patience.
                    Diane

                    Comment

                    Working...
                    X