Compiling Question

 

I have several indicators, that I have to keep compiling, to keep the items displayed on the chart current.  Below is some code to show what I mean.  When the platform is launched or when the indicator is added to the chart, there is no problems.  When period "0" becomes period "1", the lines stop drawing, until I recompile the code.  Is there a command or routine that I need to use to get the lines to keep drawing, even when the period changes?


Thanks, again!

//+------------------------------------------------------------------+
//|                                                   Daily High.mq4 |
//|                                                               me |
//|                                                                  |
//+------------------------------------------------------------------+


#property indicator_chart_window

extern int Hour_Num = 0;
extern int Minute_Num = 0;

    int h = 0;
    
    
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
int ObjectCount = ObjectsTotal();
   for (int i=ObjectCount-1; i>=0; i--)
   {
      if(StringFind(ObjectName(i),"5mg_Line") != -1)
      {
         ObjectDelete(ObjectName(i));
      }  
   } 
     
 
    
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
   {

    datetime BeginTime, EndTime;
    int Counted_bars=IndicatorCounted();                                                            
    int i=Bars-Counted_bars-1;                                                                      
                                                                                                  
    while(i>=0)                                                                                        
    {    
     if(TimeHour(Time[i]) == Hour_Num && TimeMinute(Time[i]) == Minute_Num)
    
    { h=h+1;
                                                                                              
    double v5H=iHigh(NULL, PERIOD_M5,h);                                                              
                                                                                                    
    if(i > 0)  //   && t > 1
    { 
    BeginTime = iTime( NULL, PERIOD_M5, h );                                                       
    EndTime   = BeginTime + 300;                                                               
    }
    

     
    ObjectDelete("5mg_Line"+h);  
    ObjectCreate("5mg_Line"+h, OBJ_TREND, 0, BeginTime, v5H, EndTime, v5H );                           
    ObjectSet("5mg_Line"+h, OBJPROP_COLOR, Red);
    ObjectSet("5mg_Line"+h, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet("5mg_Line"+h, OBJPROP_WIDTH, 2);
    ObjectSet("5mg_Line"+h, OBJPROP_RAY, False);  
    
    }
    i--;  
    ObjectSet("5mg_Line"+h,OBJ_TREND,EndTime);
    
 
    ChartRedraw(ChartID());

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




 
Yellowbeard1781:

I have several indicators, that I have to keep compiling, to keep the items displayed on the chart current.  Below is some code to show what I mean.  When the platform is launched or when the indicator is added to the chart, there is no problems.  When period "0" becomes period "1", the lines stop drawing, until I recompile the code.  Is there a command or routine that I need to use to get the lines to keep drawing, even when the period changes?


Thanks, again!

This line uses "EndTime", which is only updated when "TimeHour(Time[i]) == Hour_Num && TimeMinute(Time[i]) == Minute_Num":

ObjectSet("5mg_Line"+h,OBJ_TREND,EndTime);

So you'll have to modify your time checks to get EndTime modified.

Also, consider changing your i to:

    int i = MathMin(Bars-1,Bars-Counted_bars); // i will range from 0 to Bars-1.

Otherwise your "if (i>0)" condition will not execute beyond the first run.