From what I see it's because you adjust the HoldTrend back to 0 in the beginning of each main() call (i.e. HoldTrend = 0;). Why would you do that?