Myst, Nice pictures! They are worth 1000 words each!
As you mentioned that this X_DEV example was not optimised it would be easy(I presume) to force the buys and the sells to the lower and upper limits. I suppose Pragmatico has done that to get the 411 million!
The idea for optimising your scheme had been discussed at lenght and I do not follow all the fine points but I would assume that it would not be too difficult to build a pattern recognition subroutine that will notice that the tops and bottoms are all the time unchanged and would force the buys and the sells to the $ 4 and $10 limits, and would sell all the stock at the top and disburse all the cash at the bottom.
It goes without saying that it might not be wise to disburse all the cash in an actual investment, but that is a money management issue and not for an algorithm to decide. A case in point would be to decide that it would be justified to disburse all the cash at the dip, plus borrow a bunch of extra money if the stock dives deeper. No mechanical system will ever get to that point!
I have been thinking about making a pattern recognition subroutine….thinking Fortran thoughts….. but I am not smart enough to build one myself in Excel, or in any other lagguage, so the idea is still incubating. The details of the programming such a subroutine are simply beyond me.
Lots of luck!
Conrad