Download MetaTrader 5

[Help] - indicator problem

To add comments, please log in or register
Write your articles using our editor. It is convenient!
Indra Lukmana
2602
Indra Lukmana 2014.12.12 13:19 

Please help,,

I have an indicator coded by my own, that marks the candle with the red or lime color for the starting point to draw automated fibonacci level,

the problem is, when I close the MT4 terminal and then re-open it , the candle becomes screwed like below: 

 

I'm using indicator buffer to draw the candle as below

int start()
   {
   WindowRedraw();
   //NTGS_ candle med
   SetIndexBuffer(0,CandleOpen);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexLabel(0,"CandleOpen");
   //NTGS_ candle high
   SetIndexBuffer(1,CandleClose);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexLabel(1,"CandleClose");
   //NTGS_ candle med
   SetIndexBuffer(2,ShadowLow);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexLabel(2,"ShadowLow");
   //NTGS_ candle high
   SetIndexBuffer(3,ShadowHigh);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexLabel(3,"ShadowHigh");

   if(Bars<=3) return(0);
   int counted_bars = IndicatorCounted();
   if(counted_bars<0) return(-1);

   int pos;
   int limit=Bars-2;
   int DN, DN2;
   string namaHari;

   //fixed at specific candle regardless different server time.
   int BeginH=0,BeginM=0;
   datetime fixHour=TimeHour(TimeLocal())-TimeHour(TimeCurrent());
   
      switch(MathAbs(fixHour))
         {
.....
         default : BeginH=20; break;
         }
   BeginMinutes=60*BeginH+BeginM;

   if(counted_bars>2) limit=Bars-counted_bars-1;
   pos=limit;

   while(pos>=0)
      {
      DN=DayNumber(pos);
      DN2=DayNumber(pos+1);
      if(DN!=DN2 && DN!=5)
         {
         if(Open[pos]-Close[pos]>0)
            {
            //candle acuan
            CandleClose[pos]=Open[pos]; //candle body open
            CandleOpen[pos]=Close[pos];//candle body close
            ShadowHigh[pos]=High[pos]; //candle tail
            ShadowLow[pos]=Low[pos];//candle tail
            }
         if(Open[pos]-Close[pos]<0)
            {
            CandleClose[pos]=Open[pos]; //candle body open
            CandleOpen[pos]=Close[pos];//candle body close
            ShadowHigh[pos]=Low[pos]; //candle tail
            ShadowLow[pos]=High[pos];//candle tail
            }
         }
      pos--;

      }
 
   }

 

Problem 

 

the indicator should be like below image, but  whenever I re-open my MT4, it becomes screwed.

the correct one:

 

 

please help ,

thank you 

Indra Lukmana
2602
Indra Lukmana 2014.12.13 11:53  

Sorry for posting a new thread

 

already solved :)

 

   //candle count
   if(Bars<=3) return(0);
   int counted_bars = IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) {counted_bars--;} //fixed code

 

hopefully helping the other coders :D 

To add comments, please log in or register