First you'll need a variable, say time, to keep track of the current time period. This is really only needed because the first column of the output is the time period.

Your crucial decision is which variables to maintain to keep track of the stock's current trend. You might choose two integer variables, say up and down, that keep track of the current up-down pattern. For example, up = 2 represents two consecutive increases. (Alternatively, you could do this with a single integer variable, say trend, that represents an up trend if its value is positive, and a down trend if its value is negative.)

Finally, in order to update your trend variable(s), you'll probably want a helper variable to store the stock price in the previous period, say oldprice. By comparing the values of price and oldprice, you can determine whether the stock went up, down, or stayed the same.