Problem with Indicator painting current bar

 

I seem to have this problem sometimes when doing mult colored line plots: the current bar paints to zero or EMPTY_VALUE...

I came across it once a few weeks back, and in that situation moved the code from a library to the indicator code and it worked fine.

This time I want to leave it in the library, and figure out what the problem is. Anyone else have this problem and found out what caused it?

In trying to fix it last time, my first assumption was that it didnt know which buffer to draw for the current bar, so it was drawing them all to the bottom of the graph, so

since I was basing the decision on the close of the bar, maybe just not process the current bar. All that did was move this issue one bar to the left lol

Any help/insight would be appreciated, as this is becoming a thorn in my side ;o)




 
Posting some codes of the indicator would provide additional info for someone to help you. Use the SRC button above when posting codes or attach the indicator file works as well.
 
ubzen:
Posting some codes of the indicator would provide additional info for someone to help you. Use the SRC button above when posting codes or attach the indicator file works as well.

My apologies, guess it would help. My original thought was since the problem didn't seem to occur UNLESS the code was in a library, posting the code wouldn't help much.

But to recap, the code works fine it seems, in a separate window, but not in the chart window. It works fine if the routine is in the indicator code, but not when called from a library.

I've tried changing the bar processing order in two ways: reversing it, and taking out the current bar from the processing loop. I may need to reverify all of this though.

void _QuadClrLine(double plot[], double compVal[],double& up[],double& dn[], double& high[], 
                double& low[],double lvlTop[],double lvlMid[], double lvlBottom[],
               int endIndex, bool trueToPlot)
{  //given four color buffers, compares values to the three levels, plots a line
   //buffers are extreme high, up, down, and extreme low. 
   //NOTE: trueToPlot will keep the line solid, regardless of level crossings
   //NOTE: use False value for fixed levels to change color right on the level.
   
   double levelTop,
            levelMid,
            levelBottom;
   
   for(int x=endIndex;x>0;x--)
   {
   // There will be 4 scenario's:
   // 1) above all three levels
   // 2) above mid but below upper level
   // 3) below mid but above lower level
   // 4) below all 3 levels
      
      //first check level arrays to make sure their position has not changed.
      
      levelTop=MathMax(MathMax(lvlMid[x],lvlTop[x]),lvlBottom[x]);
      levelTop=lvlTop[x];
      levelBottom=MathMin(MathMin(lvlMid[x],lvlTop[x]),lvlBottom[x]);
      levelBottom=lvlBottom[x];
      levelMid=_GetMid(lvlMid[x],lvlTop[x],lvlBottom[x]);
      levelMid=lvlMid[x];
      
      if (compVal[x]>=levelTop)
      {  //begin scenario 1 - in HIGH zone
      high[x]=plot[x];
      low[x]=EMPTY_VALUE;
      up[x]=EMPTY_VALUE;
      dn[x]=EMPTY_VALUE;
      //where was the last one?
         if (up[x+1]!=EMPTY_VALUE)
         { // crossed from up zone into high
            if(trueToPlot)up[x+1]=plot[x+1]; else up[x+1]=levelTop;
            if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelTop;
         }
         if (dn[x+1]!=EMPTY_VALUE)
         { //crossed to high from down zone
             if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelTop;
             if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelTop;
         }
         if (low[x+1]!=EMPTY_VALUE)
         { //crossed to high from low zone
             if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelTop;
             if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelTop;
         }
         //clear other buffers
         
      }//end scenario 1
   ///////////////------------///////////////   
    if (compVal[x]<levelTop&&compVal[x]>levelMid)
      {  //begin scenario 2 - in UP zone
      up[x]=plot[x];
      //clear other buffers
      low[x]=EMPTY_VALUE;
      high[x]=EMPTY_VALUE;
      dn[x]=EMPTY_VALUE;
      //where was the last one?
         if (high[x+1]!=EMPTY_VALUE)
         { // crossed from high zone into up
            if(trueToPlot)up[x+1]=plot[x+1]; else up[x+1]=levelTop;
            if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelTop;
            
         }
         if (dn[x+1]!=EMPTY_VALUE)
         { //crossed to up from down zone
             if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelMid;
             if(trueToPlot)up[x+1]=plot[x+1]; else up[x+1]=levelMid;
         }
         if (low[x+1]!=EMPTY_VALUE)
         { //crossed to up from low zone
             if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelMid;
             if(trueToPlot)up[x+1]=plot[x+1]; else up[x+1]=levelMid;
         }
        
      }//end scenario 2  
   ////////////// ................/////////////
   if (compVal[x]<levelMid&&compVal[x]>levelBottom)
      {  //begin scenario 3 - in Down zone
      dn[x]=plot[x];
      low[x]=EMPTY_VALUE;
      high[x]=EMPTY_VALUE;
      up[x]=EMPTY_VALUE;
      //where was the last one?
         if (high[x+1]!=EMPTY_VALUE)
         { // crossed from high zone into up
            if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelMid;
            if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelMid;
         }
         if (up[x+1]!=EMPTY_VALUE)
         { //crossed to up from down zone
             if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelMid;
         }
         if (low[x+1]!=EMPTY_VALUE)
         { //crossed to up from low zone
             if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelBottom;
            if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelBottom;
         }
                  
      }//end scenario 3  
///////////////////------------------////////////////
  if (compVal[x]<levelBottom)
      {  //begin scenario 4 - in Low zone
      low[x]=plot[x];
      dn[x]=EMPTY_VALUE;
      high[x]=EMPTY_VALUE;
      up[x]=EMPTY_VALUE;
      //where was the last one?
         if (high[x+1]!=EMPTY_VALUE)
         { // crossed from high zone into low
            if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelBottom;
            if(trueToPlot)high[x+1]=plot[x+1]; else high[x+1]=levelBottom;
         }
         if (up[x+1]!=EMPTY_VALUE)
         { //crossed to low from up zone
             if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelBottom;
            if(trueToPlot)up[x+1]=plot[x+1]; else up[x+1]=levelBottom;
         }
         if (dn[x+1]!=EMPTY_VALUE)
         { //crossed to up from low zone
             if(trueToPlot)low[x+1]=plot[x+1]; else low[x+1]=levelBottom;
            if(trueToPlot)dn[x+1]=plot[x+1]; else dn[x+1]=levelBottom;
         }
                  
      }//end scenario 4 
   } //end for
}//end function