Very strange problem

 

Hi

 i ve got the following code of a custom indicator. What s doing is plotting the Close of the current bar timeframe as an indicator on a separate window for the first 180 bars only.

The problem is that for some reason - cant figure out - there is an image of the buffer after a while like the image bellow.  That happens in any timeframe.

 


here is the full code:

#include <stderror.mqh>
#include <stdlib.mqh>
#include <logfile.mq4>


#property indicator_level1 0
#property indicator_separate_window
#property indicator_color1 White


// --- parameters
extern int history=180;

bool isHistoryLoading;

double Buf_0[];

string build="testground 02";
int lastperiod=0;


int init()
  {
//---- indicators
isHistoryLoading=true;

   SetIndexStyle(0,DRAW_LINE,DRAW_SECTION,2);
   SetIndexBuffer(0,Buf_0);
   SetIndexLabel (0,build);   
   IndicatorShortName(build);
   SetLevelValue (0, 0.0000);       // The horizontal line level is set   



   log_open(build+".log");
   log("++----------------------++");
   
   return(0);
  }

int deinit()
  {
      
  log_close();
   return(0);
  }


int start()
{
   
 datetime dt,mdt,dt1,dt2,tdt,brm_dt,dtTemp; 
   double C, O, H, L;
   int  i, j, k, candles, counted_bars,per,shift,total_1M_Bars,minBars;
  int found,tries;  


   if (isHistoryLoading){
      dt=iTime(Symbol(),PERIOD_M1,0); if (dt == 0){   log("dt==0");  
                                                       return;}
      isHistoryLoading = false;
       counted_bars = 0;
   }
   else  counted_bars = IndicatorCounted();
         
   
   if (candles<0) return (0);   
         candles=Bars-counted_bars-1;                     // Index of the first uncounted

     if (candles>history-1)                             // If too many bars ..
        {
            candles=history-1;                         // ..calculate specified amount
         }
     
                                                       
    i=1;     


    while  (i<=candles) 
    {
            C = Close[i];
            
            Buf_0[i]=C;
            i++;
       
      } 

  return(0);
}

 I suspect it has to do with the limit i set as a history in the candles or something... but cant really get it. Its a really strange bug!

Any help? 

 
  1.   SetIndexStyle(0,DRAW_LINE,DRAW_SECTION,2);
    2nd parameter is a DRAW 3rd parameter is a STYLE
  2. #property indicator_buffers 1 // Missing prop. is my guess.
    #property indicator_level1 0
    #property indicator_separate_window
    #property indicator_color1 White
 
athanfx:

Hi

 i ve got the following code of a custom indicator. What s doing is plotting the Close of the current bar timeframe as an indicator on a separate window for the first 180 bars only.

The problem is that for some reason - cant figure out - there is an image of the buffer after a while like the image bellow.  That happens in any timeframe.

 


here is the full code:

 I suspect it has to do with the limit i set as a history in the candles or something... but cant really get it. Its a really strange bug!

Any help? 


Do you know indicator  Hello World   made by Heelflip.   Topic where you can find it.....

 

https://forum.mql4.com/44209#532950   See how you make it right

 
WHRoeder:
  1. 2nd parameter is a DRAW 3rd parameter is a STYLE



thanks.

i made both of the changes but the problem is still there.

 SetIndexStyle(0,DRAW_LINE,0,1,indicator_color1);

WHat i ve discovered is that when i first load the indicator it shows fine till i scroll back to the very very end of the chart (using page Down key). Then when i scroll back to the beginning it shows the problem.
As more times i scroll back to the very very end of the chart the more times this error repeats.


 
athanfx:


thanks.

i made both of the changes but the problem is still there.

 SetIndexStyle(0,DRAW_LINE,0,1,indicator_color1);

WHat i ve discovered is that when i first load the indicator it shows fine till i scroll back to the very very end of the chart (using page Down key). Then when i scroll back to the beginning it shows the problem.
As more times i scroll back to the very very end of the chart the more times this error repeats.


Yes I have had this before,  I think it is downloading new data when you scroll back,  change timeframe and back and that will sort the display issue . . .  I never satisfactorily fixed my issue.  https://www.mql5.com/en/forum/135231
 
RaptorUK:
Yes I have had this before,  I think it is downloading new data when you scroll back,  change timeframe and back and that will sort the display issue . . .  I never satisfactorily fixed my issue.  https://www.mql5.com/en/forum/135231

That makes sense. The buffers have increased in size, indicatorCounted is now zero,  but you are not updating the buffer(s) completely, so you see some old values.
if (candles>history-1)                             // If too many bars ..
        {
            candles=history-1;   
ArrayInitialize(Buf_0, EMPTY_VALUE); // Clear old values on history update.
 
RaptorUK:
Yes I have had this before,  I think it is downloading new data when you scroll back,  change timeframe and back and that will sort the display issue . . .  I never satisfactorily fixed my issue.  https://www.mql5.com/en/forum/135231


thanks. at least i know that changing TF fixes the problem. 
 
athanfx:

thanks. at least i know that changing TF fixes the problem. 
I wouldn't call it a fix,  more of a work-around.
Reason: