My script need 3 times to execute the entire code !!!

 

Hello,
This script clean and change the look of chart built by the MT Tester (button "Open chart" in Tester Window)
I need to "drag and drop" my script 3 times to get what it do.
- At the first "drag and drop", it remove all arrows StopLoss and TakeProfit.
- At the second "drag and drop", it remove all arrows Open/Close trade.
- At the third "drag and drop", it change the color/style or trend lines.

Strange, isn't?
Did you catch any mistake/bugs in my script?
Why does it need 3 "drag and drop" to execute the entire code?
Thanks

int FormOB,TotalOB;
double PriceO,PriceC;   //OPEN & CLOSED Price
string CurrFile="CleanC",NameOB;//OBJECT name
color LineC,LBad=0x9999FF,SBad=0xFF9999,Bad=0xAD9D60;
//---------------------------------------------------
int start(){
 TotalOB=ObjectsTotal();
 for(int i=0;i<TotalOB;i++){
  NameOB=ObjectName(i);
  if(NameOB!=""){
   FormOB=ObjectType(NameOB);
   if(FormOB==OBJ_ARROW){ObjectDelete(NameOB);}  //Remove All ARROWS
   if(FormOB==OBJ_TREND){
    ObjectSet(NameOB,OBJPROP_STYLE,STYLE_SOLID);//Trade Line STYLE
    PriceO=ObjectGet(NameOB,OBJPROP_PRICE1);
    PriceC=ObjectGet(NameOB,OBJPROP_PRICE2);
    LineC=ObjectGet(NameOB,OBJPROP_COLOR);
    if((PriceC-PriceO)<0 && LineC==Blue){ObjectSet(NameOB,OBJPROP_COLOR,Bad);} //Bad LONG  TRADE
    if(0<(PriceC-PriceO) && LineC==Red ){ObjectSet(NameOB,OBJPROP_COLOR,Bad);} //Bad SHORT TRADE
   }
  }
 }
 return(0);
}

I use MT 4.0.211 and ME 4.0.209.

 

change

for(int i=0;i<TotalOB;i++){

to

for( int i = TotalOB-1; i >= 0; i--){

Always start at top of list and work down when deleting objects and trades.

Reason: