Stocks Lesson 20

This is a post about trend trading. Trend trading can be so much better than regular stock investing in that there is a potential to make money when the stock goes up or down. The issue is figuring out the logic for what to do when a stock changes direction. This lesson is about a trading strategy that looks at the n-period gain or loss for a given stock. The hypothesis is that profit can be made by going long when the sum of the n-period gains/losses is positive and going short when the sum of the n-period gains/losses are negative. There are many ways to trend trade. This is an exploration of one of them.

Variables:
$pos: can be long or short for a long position or a short position. In trend trading you can only be long or short.
$shrt: the last price paid for a short position.
$long: the last price paid for a short position.

$pct: defined as the average of the n-period moves. For example, for a 3 period move could be the sum of the gains/losses of the last 3 periods. The formula might look like ($c[$i]-$c[$i-1])/$c[$i-1]*100 + ($c[$i]-$c[$i-2])/$c[$i-2]*100 + ($c[$i]-$c[$i-3])/$c[$i-3]*100 where $c is the closing price and $i is the counter for the price array of the closing price. Another way might be to use the formula in this format: ($c[$i]-$c[$i-1])/$c[$i-1]*100 + ($c[$i-1]-$c[$i-2])/$c[$i-2]*100 + ($c[$i-2]-$c[$i-3])/$c[$i-3]*100. These two variations would give different results.

If you are long the following events can occur:
The open, high, and low can all be above the n-period moving average. If so, there would be no adjustments as the close would have to be above or at the low of the day.