alarm at last candle

 

Hi experts

i have a custom indicator with alert part 

every time i change time frame it's getting alert in previous candle 

how can i set to just alert if it happened in the recent candle??

thanks

 
code it that way
Reason: