a signal timer, it doesnt work, please help

 
Welcome,
I'm trying to write a signal timer and it's not working
The thing is that, the trend indicator sets a value in the buffer that is different from zero when an asterisk appears on the screen. Then the buffer is reset to zero until the next asterisk appears (that's why static bolean)

I wrote a code which is supposed to shorten the signal duration to 10 bars. The idea is to enter only at the beginning of the trend.

I do not know where the mistake is, but the robot enters only when the star appears. Please give me a hint.

int typeTrade()


  {
  
  datetime time_flag_rise;
  static bool trend;

  if( iCustom(NULL, 0,"trend-indicator",7,1) !=0)   {trend=true; time_flag_rise = TimeLocal();};     // buffer 7 - buy
  if( iCustom(NULL, 0,"trend_indicator",8,1) !=0)   {trend=false;time_flag_rise = TimeLocal();};     // buffer 8 - sell
  
  if(trend)
  if(time_flag_rise+(10*15*60)>TimeLocal())
   
  return 1;   // signal to BUY
  
  
  if(!trend)
  if(time_flag_rise+(10*15*60)>TimeLocal())
  
  return 2;    //signal to SELL

  return 0;


  }