This is my attempt on a trailing stop in a dynamic stock universe with multiple stocks. I could not find one and needed it for an algo, so I wrote this and thought maybe some of you great minds out there could tell me if it's not good enough or ideas for improvement etc.
The idea is that it looks at past price data of a stock in the period from we entered the position until now and uses either min or max price to determine the stop, depending on if we are short or long. Super simple.
I wanted to write it in such a way that I could reuse it, so maybe you can too.
Its not written to be concise and beautiful, but easy to read and understand (you tell me).
Some things to note:
- Stop is checked once a day, you could easily tweak this.
- The "strategy" is buying SPY each week and holding until the stop is hit. Its not a good strategy, and not the point :)
- I only used one stock in the example for clarity, and to better visually present what is going on.
Alright, first post, all feedback is appreciated!