"Can you write one version of code for backtesting and live?"
By Dave Mabe
Here's a question from Ivan M. (name used with permission).
Ivan M:
Is it possible to write code for the strategy and run exactly the same code on a live account (to minimize risk of errors)?
Dave:
Yes, this is absolutely possible and highly recommended.
A very good programmer gave me a valuable lesson early in my career:
If you find yourself cutting and pasting code, you're doing something wrong.
The next time you feel the urge to copy and paste in your code, think about how you can do it differently.
Can you create a library that gets shared across several projects?
It's a little more work in the immediate term, but the payoff later is substantial.
This is the fundamental reason I use the term "library" for the backtest columns in MabeKit.
While it might not seem like a huge pain to copy and paste code for a single trading strategy, this process gets exponentially harder as you add more strategies.
And the same goes for backtesting and live trading code.
Most platforms make this possible.
Your instincts are correct here, Ivan. Thanks for the question and for sharing with the group.
-Dave
P.S. Amibroker users: are you trying to use ChatGPT to create a backtest only to discover how bad the LLMs are at coding Amibroker's language? You're not alone! You need my Amibroker AFL Course. It comes with a demo strategy that serves as the perfect starting point for any strategy you want to create.