Signal Generation and Trade Execution – Separate?

Here’s another great question from a new list member, Chip, about how to set up the code for automating his trading strategy. (Name used with permission)


Chip:

I’ve always kind of known discretionary wasn’t for me…been at this unsuccessfully for a long time. Had previously used Python to do some analysis work, but your stuff really inspired me to revisit a backtest for an idea I had. Changing the approach to adding columns was a game-changer for finding the edge in the idea (I think). It’s taken weeks to get it to a usable place, but I started trading it a few days ago. Not fully automated yet, it’s just spitting out the signals, but I’m excited about seeing how it works and figuring out how to automate the orders.

Is it best practice to have the alert script place the orders? Or, do you create a separate script to read the alert output and then place the orders?


Dave:

The signal generation and acting on it are two different things.  In this case, I like having them separate.

That makes it way easier to test things, and you’ll have separate code files for each function.

The computer science term for this idea is separation of concerns.

And it’s not something you simply learn in school, it’s a practical way to design your code structure that makes your life way easier.

One thing I ALWAYS include in either script is plenty of parameters to control the behavior without actually modifying the code.

One of them in particular is a --pretend mode (sometimes called --dry-run).

In that mode, it takes all the steps except actually doing anything – it simply reports what it WOULD do if it weren’t in pretend mode.

I can’t tell you how many times a scenario comes up where pretend mode comes in handy!

Trying to cobble that together when you need it is trickier than it seems, so I do this right from the beginning when I create almost any script or code.

Thanks for the question, Chip, and welcome to the list!

-Dave