someone can help me?how do i check new bar?

 
this is my code.igot some problam when the "new tickets"and"close"Condition was set up in the same time.

will look line this photo.
now,I want add a new code to set . every bars were only trade once in the same bar.
i try many method like timefram , int bars or Bars,but it's not work.
so please give me a hand.  thanks alot
extern double Lots = 1.00;
extern int Periodma = 36 ;
extern int trailing = 100;
extern int StopLoss = 400;
extern int TrailingStop = 500;
extern int Dev = 2;
extern int Tick = 0;
double profit = 0;
extern int Periodma1 = 124 ;
int bars;

/////--------------------------------------------------------
//------------計算新K棒-------------------------------------------------
int Init()
  {
//---
   bars = Bars;
//---
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
  int    cnt,ticket,total;
   if(Bars<100)
     {
      Print("bars less than 100");
      return;
     }
 

1) It not enough code!

2) If you are learning to code you should use an example for here and change it - it's faster and you'll face less errors!