exclude sunday makes some trouble

To add comments, please log in or register
Thierry Ramaniraka
537
Thierry Ramaniraka  
Hi again there,
I am working on a classic indicator to show the days range.

But when i try to make it with no sunday, it  logicly doesn't work anymore like it should.
And i don't know how to fix it.

Here are the screenshots 
Normal
with sunday

And without sunday
with no sunday

I tried this
//+------------------------------------------------------------------+
                                                          
//+------------------------------------------------------------------+

extern int       Days_To_Process=10;
extern color     Days_Color = C'242,242,242';
extern color     Days_HighLow_Color = Silver;

//

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- ObjectDelete

//----
   int i;

   for (i=0;i<Bars;i++)
    {
    
    ObjectDelete("Days_Rect"+DoubleToStr(i,0));
    ObjectDelete("Days_Rect_Line"+DoubleToStr(i,0));
    } 
//----
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
  
   int i;

   for (i=0;i<Bars;i++)
    {
    
    ObjectDelete("Days_Rect"+DoubleToStr(i,0));
    ObjectDelete("Days_Rect_Line"+DoubleToStr(i,0));
    }  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   datetime  This_Day_End = iTime(NULL,PERIOD_D1,0) + 86399;
  
   // NO SUNDAY
   datetime Yest_Day_Sunday=iTime(Symbol(),PERIOD_D1,(DayOfWeek() == 0));
                                     
   int noSunday = 1;
   
   if (Yest_Day_Sunday)
   {   
   while (DayOfWeek() == 1)
      {      
        noSunday = 2;
       break;
      }
   }
   // NO SUNDAY end
 
  // DAYS
   /**/
   datetime Yest_Day_Start=iTime(Symbol(),PERIOD_D1,noSunday);
   
   double Days_Yest_High = iHigh(NULL,PERIOD_D1,noSunday);
   double Days_Yest_Low = iLow(NULL,PERIOD_D1,noSunday);
   
   
   int counted_Days=IndicatorCounted(),
       limit_Days,
       id=0;
   
   if(counted_Days>0)
      counted_Days--;
   
   limit_Days=Bars-counted_Days;
   
   if(limit_Days>Days_To_Process)
      limit_Days=Days_To_Process;

   while (id<limit_Days)
   {  /*         
      datetime Days_Start = iTime(NULL,PERIOD_D1,id+1);
      datetime Days_End = iTime(NULL,PERIOD_D1,id);
      
      double Days_High = iHigh(NULL,PERIOD_D1,id+1);
      double Days_Low = iLow(NULL,PERIOD_D1,id+1);
      double Days_Open = iOpen(NULL,PERIOD_D1,id+1);
      double Days_Close = iClose(NULL,PERIOD_D1,id+1);
      double Days_High_Prev = iHigh(NULL,PERIOD_D1,id+2);
      double Days_Low_Prev = iLow(NULL,PERIOD_D1,id+2);
      double Days_Open_Prev = iOpen(NULL,PERIOD_D1,id+2);
      double Days_Close_Prev = iClose(NULL,PERIOD_D1,id+2);
      */
      datetime Days_Start = iTime(NULL,PERIOD_D1,id+noSunday);
      datetime Days_End = iTime(NULL,PERIOD_D1,id);
      
      double Days_High = iHigh(NULL,PERIOD_D1,id+noSunday);
      double Days_Low = iLow(NULL,PERIOD_D1,id+noSunday);
      double Days_Open = iOpen(NULL,PERIOD_D1,id+noSunday);
      double Days_Close = iClose(NULL,PERIOD_D1,id+noSunday);
      double Days_High_Prev = iHigh(NULL,PERIOD_D1,id+1+noSunday);
      double Days_Low_Prev = iLow(NULL,PERIOD_D1,id+1+noSunday);
      double Days_Open_Prev = iOpen(NULL,PERIOD_D1,id+1+noSunday);
      double Days_Close_Prev = iClose(NULL,PERIOD_D1,id+1+noSunday);
      
      if (Days_Start>0)
       {
       if(DayOfWeek()==0 || DayOfWeek()==6) return(0);
           
        ObjectCreate("Days_Rect"+DoubleToStr(id,0),OBJ_RECTANGLE, 0, Days_Start, Days_High, Days_End, Days_Low);
           ObjectSet("Days_Rect"+DoubleToStr(id,0),OBJPROP_COLOR,Days_Color); 
           ObjectSet("Days_Rect"+DoubleToStr(id,0),OBJPROP_BACK,true);   
           
        ObjectCreate("Days_Rect_Line"+DoubleToStr(id,0),OBJ_RECTANGLE, 0, Days_Start, Days_High, Days_End, Days_Low);
           ObjectSet("Days_Rect_Line"+DoubleToStr(id,0),OBJPROP_COLOR,Days_HighLow_Color); 
           ObjectSet("Days_Rect_Line"+DoubleToStr(id,0),OBJPROP_BACK,false);   
       }            
     id++;  
   }

//----
   return(0);
  }
//+------------------------------------------------------------------+

void DeleteObjects()
 {
   int i;

   for (i=0;i<Bars;i++)
    {
    
    ObjectDelete("Days_Rect"+DoubleToStr(i,0));
    ObjectDelete("Days_Rect_Line"+DoubleToStr(i,0));
    } 
 }
And in attached file, the mql code.

Really need help please.
Regards.

EDIT : Is there a way to generaly exclude the sunday data calculation ?
Files:
To add comments, please log in or register