ObjectCreate on Indicator problem

Back to topics list To post a new topic, please log in or register
avatar
52
renzbub 2016.02.04 21:04
 

Why is it that when I place my Indicator onto a chart it only shows the objects on current day. But when I run it on tester it displays all previous days?


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   {
//---  
   int bars = rates_total - 1; 
   if(prev_calculated > 0) bars = rates_total - prev_calculated; 

   for(int i = bars; i >= 0; i--)  // -- Counts down from last bar on chart EG 99th
  {
  
   int weekday = DayOfWeek();
   int shift = 0; 
   if(weekday == 1) shift = 2; 
   if(weekday != 1) shift = 1;
      
   double ycloseBuffer = iClose(_Symbol,PERIOD_D1,shift); 
   double yhighBuffer = iHigh(_Symbol,PERIOD_D1,shift); 
   double ylowBuffer = iLow(_Symbol,PERIOD_D1,shift); 

   datetime timeStart = CreateDateTime(0,0);  
   datetime timeEnd = CreateDateTime(23,0);

   string ob_yc = "ycloseline "+TimeToStr(timeStart);    
   string ob_yh = "yhighline "+TimeToStr(timeStart);   
   string ob_yl = "ylowline "+TimeToStr(timeStart); 

   ObjectCreate(ob_yc,OBJ_TREND,0,timeStart,ycloseBuffer,timeEnd,ycloseBuffer); 
   ObjectCreate(ob_yh,OBJ_TREND,0,timeStart,yhighBuffer,timeEnd,yhighBuffer); 
   ObjectCreate(ob_yl,OBJ_TREND,0,timeStart,ylowBuffer,timeEnd,ylowBuffer);    

   ObjectSet(ob_yc,OBJPROP_STYLE,STYLE_DASH); 
   ObjectSet(ob_yh,OBJPROP_STYLE,STYLE_DASH);  
   ObjectSet(ob_yl,OBJPROP_STYLE,STYLE_DASH); 
   
   ObjectSet(ob_yc,OBJPROP_RAY,false);  
   ObjectSet(ob_yh,OBJPROP_RAY,false);  
   ObjectSet(ob_yl,OBJPROP_RAY,false);         
  }    
     
//--- return value of prev_calculated for next call
   return(rates_total);
   }

 

avatar
Moderator
3404
GumRai 2016.02.04 22:13 #
 

I doubt that your code will draw previous lines whether in tester or not. It may paint the lines as the tester is running.

We don't know what the function CreateDateTime does, but as it doesn't have any index passed to it, I can only guess that it uses TimeCurrent() or Time[0] or something like that. This means that when the indicator is first attached to a chart, it will create the same times for every run through the loop. So it will try to create new objects with the same names, and that will fail

Back to topics list  

To add comments, please log in or register