How to refersh an indicator only when a period has just finished ?

 
Sorry if this question is basic but I'm newbie. All source code I saw seems to refresh indicator for every tick, whereas I want to do so only when a period is just finished so how to do so ?
Reason: