Logic Problem: Draw line, and change color / stop drawing when hit

 

Hola, I have some trouble finding the correct Logic.

With this indicator I want to get a candle body that is X amount bigger than the previous (Works so far) and draw a line at the open price (also works).
Now if the price crosses any of the lines, i would like to change its color and stop it from drawing once it's hit.

This last part is where most of my trouble sits. Right now it's obviously changing colors, but not the way I want.
I am lost finding the right logic. i.e where and how to check and save if it has been hit.

Any help is greatly apreciated.

Here is the code:

#property indicator_chart_window
#property indicator_buffers         2
#property indicator_color1          Green
#property indicator_color2          Red

extern bool    DrawArrows           = true;
extern int     TimeFrame            = 0;
extern double  CandleFactor         = 1.8 ; // Min Candle Factor
extern double  CandleMinPip         = 20 ; // Min Pips to show Candle (in pts)
extern int     CountBars            = 24;
extern color   Linecolor            = Blue;
extern color   LinecolorHit         = Red;
extern int     Width                = 0;
extern int     ShiftLineRightBars   = 6 ;

double Up[], Down[], EntryPriceArray[], OpenPriceArray[];
double close2, open2, close1, open1, pips1, pips2, EntryPrice, OpenPrice;
string can2, can1, label, period;
int i;
//+------------------------------------------------------------------+

int init()
  {
   SetIndexBuffer(0,Up);
   SetIndexBuffer(1,Down);
   
   if(DrawArrows){SetIndexStyle(0,DRAW_ARROW);}else{SetIndexStyle(0,DRAW_NONE);}
   if(DrawArrows){SetIndexStyle(1,DRAW_ARROW);}else{SetIndexStyle(1,DRAW_NONE);}
    
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);
   
   CandleMinPip = CandleMinPip*Point;
   
   if (Period() == 1){period = "M1"; Width = 1; ShiftLineRightBars = ShiftLineRightBars + 5;}
   if (Period() == 5){period = "M5"; Width = 2; ShiftLineRightBars = ShiftLineRightBars + 3;}
   if (Period() == 15){period = "M15"; Width = 2; ShiftLineRightBars = ShiftLineRightBars + 2;}
   if (Period() == 30){period = "M30"; Width = 3;}
   if (Period() == 60){period = "H1"; Width = 3;}
   if (Period() == 240){period = "H4"; Width = 4;}
   if (Period() == 1440){period = "D1"; Width = 5;}
   
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  { if (CountBars == 0) {CountBars=Bars;}
    for( i = 0; i < CountBars; i++) {
    ObjectDelete("Line_"+period+"_"+Time[i+1]);
  }
  
   return(0);
  }
//+------------------------------------------------------------------+
int start() {
   if (CountBars == 0) {CountBars=Bars;}
   for( i = 0; i < CountBars; i++){
   
      close1=iClose(NULL,TimeFrame,i+1);
      close2=iClose(NULL,TimeFrame,i+2);
      open1=iOpen(NULL,TimeFrame,i+1);
      open2=iOpen(NULL,TimeFrame,i+2);
      
      pips1 = (MathAbs(open1-close1));
      pips2 = (MathAbs(open2-close2));
      
            if ( pips1 > CandleMinPip){
            
             if ( pips1 > pips2*CandleFactor){
             
             int CandleTime = Time[i+1];                  // Get the Candle time of Candle i+1
             // int CandleTimeClose = CandleTime+(Period()*60*ShiftLineRightBars);
              int CandleTimeClose = Time[0];
             label = "Line_"+period+"_"+Time[i+1];
             
                if (open1-close1 < 0){                   // Candle 1 is Bullish
                Up[i+1]=iLow(NULL,TimeFrame,i+1);
                EntryPrice = iHigh(NULL,TimeFrame,i+1);
                
                }
                
                if (open1-close1 > 0){                   // Candle 1 is Bearish
                Down[i+1]=iHigh(NULL,TimeFrame,i+1);
                EntryPrice = iLow(NULL,TimeFrame,i+1);
           
                }
                
                OpenPrice = iOpen(NULL,TimeFrame,i+1);  // Open Price of BiggerCandle
                
                
                ObjectCreate(label, OBJ_TREND, 0, CandleTime, OpenPrice, CandleTimeClose, OpenPrice, 0, 0);
            ObjectSet(label, OBJPROP_RAY, 0);
            ObjectSet(label, OBJPROP_COLOR, Linecolor);
            ObjectSet(label, OBJPROP_WIDTH, Width);
            ObjectSet(label, OBJPROP_STYLE, 0);
            
             if (open1-close1 > 0 &&  Bid > OpenPrice) {   // If Bid crosses/is above the OpenPrice, Change Line Color and Change CandleTimeClose
             ObjectSet(label, OBJPROP_COLOR, LinecolorHit);
             CandleTimeClose = TimeCurrent();
             ObjectSet(label, OBJPROP_TIME2, CandleTimeClose);
             }
             
                 if (open1-close1 < 0 &&  Bid < OpenPrice) {   // If Bid crosses/is below the OpenPrice, Change Line Color and Change CandleTimeClose
                 ObjectSet(label, OBJPROP_COLOR, LinecolorHit);
                 CandleTimeClose = TimeCurrent();
             ObjectSet(label, OBJPROP_TIME2, CandleTimeClose);
                 
                 }
            
                
        } // End CandleFactor  

       } // End CandleMinPip
   
   
   } // End CountBars

                
                
   return(0);
}