My latest project in learning to write algorithms is figuring out how to use limit orders. Simple enough I thought, just put the word "Limit" in front of the order line of code. When I ran a backtest, it ordered the specified quantity once every minute (Minute Resolution), until I ran out of money then gave me an insufficient funds run error.  Oops - not as simple as I thought!  Apparently, limit orders do not cancel themselves automatically when they fill.  Is that correct?

My search for examples of shared code using limit orders has left me even more confused, so I am asking for help.  Can someone please explain how to use these orders correctly?  Start with the basics and assume that I know nothing - which is not a bad assumption :(  If someone knows of some simple code somewhere that uses limit orders, a link would be appreciated.  Thank you in advance to anyone willing to help out a constant newbie!

Author