The CopyBuffer of this custom Indicator, doesn't seem to get it right. Why?

 

Hi,


Im using a custom indicator, it seems to be correct, it displays correctly, but, when using it in the EA, results are not as expected.


for example, I've said to the indicator to open an order, when the value of the indicator is smaller than 0, after this equal to 100 and after this smaller than 100, but it's not doing what I've asked.


Why?



as you see in the image, the order opens, when it has had a constant 100 over the last 3 periods.

How could I say to the indicator to do this in those time periods?

   double array_st[];
   ArraySetAsSeries(array_st,true);
   int start_pos_st=0,count_st=4;
   if(!iGetArrayST(handle_iTII,0,start_pos_st,count_st,array_st))
      return;
bool iGetArrayST(const int handleST,const int bufferST,const int start_posST,
                 const int countST,double &arr_bufferST[])
  {
   bool resultST=true;
   if(!ArrayIsDynamic(arr_bufferST))
     {
      //if(InpPrintLog)
      PrintFormat("ERROR! EA: %s, FUNCTION: %s, this a no dynamic array!",__FILE__,__FUNCTION__);
      return(false);
     }
   ArrayFree(arr_bufferST);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copiedST=CopyBuffer(handleST,bufferST,start_posST,countST,arr_bufferST);
   if(copiedST!=countST)
     {
      //--- if the copying fails, tell the error code
      //if(InpPrintLog)
      PrintFormat("ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d",
                  __FILE__,__FUNCTION__,countST,copiedST,GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }
   return(resultST);
  }
if(Orden=="Buy" && ( array_st[3]<100 && array_st[2]==100  && array_st[1]<100