Announcement

Collapse
No announcement yet.

Counting Number of Trading Days in a Month

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

  • Counting Number of Trading Days in a Month

    Hello

    I'm trying to count the number of trading days in a month in any intraday interval

    Here is what I came up with and I THINK it's working

    var nCount = 1;
    var vTemp2 = 0;


    for(var i = 0; i < 30; i++) {
    vTemp = day(-i, inv("D") );
    if (vTemp < vTemp2) {
    nCount++;
    } else {
    tDays = nCount;
    nCount = 1;
    }
    vTemp2 = vTemp;
    }

    tDays is the number of trading days, I have a feeling there is a BETTER way of doing this.

    Thank you

    Ketoma

  • #2
    Re: Counting Number of Trading Days in a Month

    Ketoma
    Another way of doing what you are trying to accomplish is to create a separate function which you run in the context of the daily interval by calling it using efsInternal() and passing to it [as the last parameter] the daily interval through the inv() function (see the EFS KnowledgeBase for the description and syntax of the functions and also search the forums for examples).
    In this function you would set your counter (in the example below nCount which needs to be a global variable) to 1 at the beginning of each month and increment it by 1 on each new bar eg
    if(getBarState()==BARSTATE_NEWBAR){
    if(month(0)!=month(-1)) nCount = 1; else nCount++;
    }

    Then in the function you would return nCount which represents the current count of the daily bars in the month
    Alex


    Originally posted by ketoma21
    Hello

    I'm trying to count the number of trading days in a month in any intraday interval

    Here is what I came up with and I THINK it's working

    var nCount = 1;
    var vTemp2 = 0;


    for(var i = 0; i < 30; i++) {
    vTemp = day(-i, inv("D") );
    if (vTemp < vTemp2) {
    nCount++;
    } else {
    tDays = nCount;
    nCount = 1;
    }
    vTemp2 = vTemp;
    }

    tDays is the number of trading days, I have a feeling there is a BETTER way of doing this.

    Thank you

    Ketoma

    Comment


    • #3
      Thank you very much Alexis

      I think your way is a better way I will give it a try

      Thank you again

      Ketoma

      Comment


      • #4
        Ketoma
        You are most welcome
        Alex


        Originally posted by ketoma21
        Thank you very much Alexis

        I think your way is a better way I will give it a try

        Thank you again

        Ketoma

        Comment

        Working...
        X