Indicator Drawing troubles

 

Hey guys another question, I am trying to figure out the indicator side of programing. Having a few problems.

First Trouble is one of the indicator buffers doesn't draw properly. A problem with buffer 3&4 which I basically want to make a Highest and lowest channel out of the first buffer...

Here is the relevant code..

#property indicator_separate_window
#property indicator_buffers 4

#property indicator_color1 LightSeaGreen
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue

#property  indicator_width1 8
#property  indicator_width2 1
#property  indicator_width3 1
#property  indicator_style3 1
#property  indicator_width4 1
#property  indicator_style4 1

//---- input parameters
extern int peroid = 20;

//---- buffers
double line[];
double line2[];
double line3[];
double line4[];


int init()
  {
   

  IndicatorBuffers(4);

//---- indicator lines
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, line);
   
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, line2);
   
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, line3);
   
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, line4);

   
//---- name for DataWindow and indicator subwindow label
   string short_name;
   short_name="Indicator Daz";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   return(0);
  }



int start()
  {
   int    i, counted_bars = IndicatorCounted();
    
   
//---- initial zero
   if(counted_bars < 1)
     {
       for(i = 1; i <= peroid; i++) 
           line[Bars-i] = 0.0;
           line2[Bars-i] = 0.0;
           line3[Bars-i] = 0.0;
           line4[Bars-i] = 0.0;
     } 
 
     
//---- last counted bar will be recounted
   int limit = Bars - counted_bars;
   if(counted_bars > 0) 
       limit++;
      
//---- buffer value calcs
   for(i = 0; i < limit; i++)
      {                                                     // start buffer for loop
      
       line[i] = pipsmoved(1,i);                               // formula for price pressure
       line2[i] = (Close[i] - Open[i])/point();                // open close line
       
       
       if(line[ArrayMaximum(line, peroid, i)] > 0)
         { line3[i] = (line[ArrayMaximum(line, peroid, i)]); }        //channel top
         else line3[i] = 0;
       
       if(line[ArrayMinimum(line, peroid, i)] < 0)
         {line4[i] = (line[ArrayMinimum(line, peroid, i)]);  }      //channel bottom
         else line4[i] = 0;
         
         //---- Arrow Signals -----
   
            if(line[i]>line3[i])                            //break of chan high
               {
                  string objectname = "Arrow " + i;
                  Comment(objectname);
                  ObjectCreate(objectname, OBJ_ARROW, 0, Time[i], Low[i] );
                  ObjectSet(objectname , OBJPROP_ARROWCODE, 241) ;
               }
      }                                                     // end buffer for loop
      

   return(0);
  }


Second is the object placement. That doesn't seem to work very well. Any tips on what I have done wrong there would be appreciated.

Here is a shot of what it looks like when I first load it...



Then after it is loaded and I press compile while its still loaded it looks like this. Which is actually what it should look like...


Help lol - Dale

 
 for(i = 0; i < limit; i++)
      {                                                     // start buffer for loop
       line[i] = pipsmoved(1,i);                               // formula for price pressure
       line2[i] = (Close[i] - Open[i])/point();                // open close line
       if(line[ArrayMaximum(line, peroid, i)] > 0)

On the first run you've filled in just line[0] only. So what is the value of ArrayMaximum(line, peroid, 0) BOGUS.

  1. You should count down.
  2. No need to initialize arrays to zero.
  3. Don't use arrays that have not been initialized.
    SetIndexDrawBegin(2, peroid);
    SetIndexDrawBegin(3, peroid);
    :
    int limit = Bars -1 - counted_bars;
    for(i = limit; i >= 0; i--){
        line[i] = pipsmoved(1,i);                         
        line2[i] = (Close[i] - Open[i])/point(); 
    }
    if (counted_bars < peroid) limit = Bars - 1 - peroid;
    for(i = limit; i >= 0; i--){
        line3[i] = (line[ArrayMaximum(line, peroid, i)]); 
        line4[i] = (line[ArrayMinimum(line, peroid, i)]);
    }
  4. Why are you creating a million objects. That should be just another buffer. See Fractals - MQL4 Code Base


 

Thanks WHRoeder, I would have never figured that out myself. My newbieness must frustrate you lol .

You're right about the objects, I will have to switch that over to the indexstyle.

Thanks again Man.

Reason: