Hi all,
First post. This is a mangled version of Dan's martingale example. I added a run loss limit and the ability to easily change the bet size function of the number of down steps. One can still discover what a disaster a pure martingale is by setting the down step limit to a large number.
This algorithm has two parameters: the price step percentage at which to adjust it's position, and the down step loss limit. It is always long and increases position on down step losses according to the bet size. When the down step limit is exceeded, the position is reset to a single long position. When an up step is exceeded, all positions except the single long are closed. If only the single long, then the last trade price is moved up a step without trading, so the single long follows prices up.
This will run in Zipline if the comment blocks around the code at the top and bottom are removed. Or else just delete them if you are not using Zipline.
best regards,
Bob Schmidt