I'm very new to algorithmic trading, coming from a software dev background, so I apologize in advance if I'm missing something obvious. I want to run a simulation where I don't add any additional cash other than what I started with, as that is more realistic to what I would be doing in real life. For example, I'd like to start with 1,000 and that is it, I use that to buy the initial stock and then can only use what I make from selling that stock to buy more stock. My algorithm below doesn't perform this way, however, as it keeps pumping in additional cash. I am trying to simulate a situation, just for testing, where, if the moving average of stockA goes ahead of the previous moving average of stockB, I sell all of stockB and use the money from that to buy as much of stockA as I can. Thanks for any advice.