How to equalize iterations for skipped Sunday bars?

Back to topics list To post a new topic, please log in or register
avatar
22
Alexnice 2015.12.08 23:42
 

Hi guys,

Basically the indicator gathers data over the last x bars (given as length).

If the indicator is used on D1 it is supposed to ignore Sunday bars, hence the if-clause.

I don't want to just skip the Sunday with continue but also still look back exactly x bars. So I add to length with length++.

Butt the length++ - line leads to weird results and finally after half way through to an array out of range Error.

   for(int i=limit; i>=0; i--)
   {   
      //Look back x bars (=length)
      for(int y=0; y<length; y++)
      {
         //If using D1 ignore Sunday bar
         if((Period()==PERIOD_D1) && TimeDayOfWeek((Time[i+y]))==0)
         {
            length++;
            continue;
         }
                  
         //Some calcualtions on Bar i+y
         //...
         //...

      }
      Buffer_0[i] = result;
   }
avatar
Moderator
3427
GumRai 2015.12.09 00:42 #
 

If length is a global, static or extern variable, you will be increasing it every time a Sunday is found. If so, you will need to use an intermediate variable.

   for(int i=limit; i>=0; i--)
     {
      int temporary_length=length;
      //Look back x bars (=length)
      for(int y=0; y<temporary_length; y++)
        {
         //If using D1 ignore Sunday bar
         if((Period()==PERIOD_D1) && TimeDayOfWeek((Time[i+y]))==0)
           {
            temporary_length++;
            continue;
           }

         //Some calcualtions on Bar i+y
         //...
         //...

        }
      Buffer_0[i]=result;
     }

 should help you to solve your problem

avatar
22
Alexnice 2015.12.09 00:47 #
 

GumRai:

should help you to solve your problem

Yes, indeed. Thank you!
avatar
Moderator
3427
GumRai 2015.12.09 01:00 #
 
Alexnice:
Yes, indeed. Thank you!

That's good.

This type of problem often comes up with externs.

In my opinion it is good to get into the habit of using input instead of extern. input is a constant and if you try to change its value in the code, the compiler will tell you. 

Back to topics list  

To add comments, please log in or register