ind looks like its behaving but isn't

 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
double price[];
int B,N,inc=0;
int init(){
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,White);SetIndexBuffer(0,price);
   return(0);
   }
int start(){  
      if(price[0]!=Close[0]){
         if(B<Bars){B=Bars;ArrayResize(price,0);for(N=inc;N>=0;N--){price[N]=EMPTY_VALUE;}inc=1;}else{inc++;}
         ArrayResize(price,inc);
         for(N=inc;N>=0;N--){Comment(ArraySize(price));
            price[N+1]=price[N];
            if(N==0){price[N]=Close[0];}
            }
         
         }
      return(0);
      }

this indicator is suppose to show tick of current bar in separate window. on new bar the indicator is to delete/clear itself and start to draw the tick of the new bar.

The problem is that it is not accessible via iCustom() function and I think I have an idea as to why after around a week of testing and playing around with it. To me it looks as though the array is not storing correctly as the array size seems to only increase by 1 on a new bar yet it appears to paint on the chart fine!

I feel i have read all i can find here i dont understand why my indicator behaves this way... can anyone spot my mistake?

 
compile to see the indicator in action and to see it comment on the chart.
 
  1. MT4 is sizing the array because of:
    SetIndexBuffer(0,price);

    and you're also doing it. Confusion.

    Leave the buffer alone and just put in the values.



  2. if(price[0]!=Close[0])
    will always be true.

int start(){  
    static datetime Time0;  static int nTicks;
    if (Time0 != Time[0]){  Time0 = Time[0]; nTicks=0;   ArrayInitialize(price, EMPTY_VALUE); }
    for(int iShift=nTicks; iShift>0; iShift--) price[iShift] = price[iShift-1];
    price[0] = Bid;
    if (nTicks < Bars) nTicks++;
    Comment(nTicks);
    return(0);
}
 

WHRoeder:

if(price[0]!=Close[0])
  1. will always be true.

That's not always the case, my broker quite often sends a change in ask price with no change in bid price particularly in at night ( ie. 10pm GMT) and as MT4 bases it's charts on bid prices it would lead to unneeded values.
 

Thanks guys you got my brain working!

the tick indicator works!

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
double price[],draw[];
int B,N,inc=0;
int init(){return(0);}
int start(){
      IndicatorBuffers(1);
      SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,White);
      SetIndexBuffer(0,draw);
      if(price[0]!=Close[0]){
         if(B<Bars){B=Bars;ArrayInitialize(price,EMPTY_VALUE);ArrayInitialize(draw,EMPTY_VALUE);inc=0;}else{inc++;}
         ArraySetAsSeries(price,true);
         ArrayResize(price,inc);
         for(N=inc-2;N>=0;N--){
            price[N+1]=price[N];
            if(N==0){price[N]=Close[0];}
            if(N!=inc-2){draw[N]=price[N];}
            }
         }
      return(0);
      }

PS: MBTrader is my broker and they seem to give me price[0]==Close[0] on every other tick without fail (always) and later on at night many ticks are the same! this maybe due to them being an ECN broker getting there data from many brokers.

Now all i have to do is test it on iCustom!!