Trendline switching in row

 
void ProcessTrendlineAlert()
{

   ushort u_sep = StringGetCharacter(";",0);
   string strTrendlineArray[];

   int iTrendlineTotal=StringSplit(strTrendLineName,u_sep,strTrendlineArray);
   int i=0;
   string strCurrentTrendline="";

   if (iTrendlineTotal<=0) return;

   for (i=0;i<iTrendlineTotal;i++)
      {
         strCurrentTrendline = StringSubstr(strTrendlineArray[i],1);

         if (StringSubstr(strTrendlineArray[i],0,1)=="1" ||
strCurrentTrendline=="")
            continue;

         if (StringSubstr(strTrendlineArray[i],0,1)=="0") {
            double dTrendlineCurrentPrice =
ObjectGetValueByShift(strCurrentTrendline,0);

            
/// UPWARD BREAKOUT
           
 if (dTrendlineCurrentPrice<iClose(Symbol(),Period(),0)+iPd*Point &&
                  dTrendlineCurrentPrice>dLastPrice+iPd*Point)
               {
//deactivates upper trendline
StringReplace(strTrendLineName,"0"+strCurrentTrendline,"1"+strCurrentTrendline); i=i+1; // using next array to adjust opposite trendline strCurrentTrendline = StringSubstr(strTrendlineArray[i],1);
//activates lower trendline. 1) It gets deactivated by lower break out. 2) It gets activated again once upper trendline breakout
StringReplace(strTrendLineName,"1"+strCurrentTrendline,"0"+strCurrentTrendline);
// turning array back
i=i-1; 
strCurrentTrendline = StringSubstr(strTrendlineArray[i],1);
                   
/// UPPER ALERT
if (AlertPopup) Alert(strCurrentTrendline," Breakout
- UP ", 
Symbol(),"_",PeriodToString(Period()),"
",DoubleToStr(iClose(Symbol(),Period(),0),Digits));
 }           
 /// DOWNWARD BREAKOUT
            if (dTrendlineCurrentPrice>iClose(Symbol(),Period(),0)-iPd*Point &&
                  dTrendlineCurrentPrice<dLastPrice-iPd*Point)
               {

StringReplace(strTrendLineName,"0"+strCurrentTrendline,"1"+strCurrentTrendline); //deactivates lower trendline
// using next array to grab opposite trendline
i=i+1; strCurrentTrendline = StringSubstr(strTrendlineArray[i],1);
//ACTIVATES UPPER trendline. 1) It gets deactivated by UPPER breakout. 2) It gets activated again once LOWER trendline breakout
StringReplace(strTrendLineName,"1"+strCurrentTrendline,"0"+strCurrentTrendline);
 // switching array back
i=i-1; strCurrentTrendline = StringSubstr(strTrendlineArray[i],1);
 }
////// LOWER ALERT
                  if (AlertPopup) Alert(strCurrentTrendline," Breakout
- DOWN ", Symbol(),"_",PeriodToString(Period()),"
",DoubleToStr(iClose(Symbol(),Period(),0),Digits));

             } } }}
 
arjani111:
Two trendlines exist: Upper and lower
When trendlines gets hit, then these deactivates in Row.
So one of them gets hit, the other activates and so on...

The upper trendline deactivation / activation is working properly.

The lower trendline does not deactive once trendline gets hit.
What is wrong ? 
 
arjani111: What is wrong ? 
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
 
William Roeder:
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
I expected my coding issue is common and easily noticed by more experienced users who seen this many times. As it is not then your advice helps a lot. Use mt4, mt5 debugger or install more advanced tool  ?
Reason: