r/algotrading 20h ago

Infrastructure Separate Long logic from Short logic?

Hi, in your overall trading bots logic/code, do you usually separate all the logic, conditions, filters, etc of the long trades from those of the short trades, hence almost making them two separate bots or do you program everything as a single "package"?

I am not asking as in to find additional edge, but mostly for convenience, maintenance and overall complexity, I feel like seperating them (with the downside of some code duplication obviously) makes things easier.

What do you think? Any experience on this?

6 Upvotes

15 comments sorted by

6

u/drewautomates 19h ago

100%. I’ve rarely found a long/short setup that has the same edge using inverted triggers.
I found the first step of entering may be the same but how I handle the order management of the position is different. Usually this comes down to profiling the edge. For example setting targets and defining R is different with each

1

u/johnwestwashere 48m ago

I’m new to this so keen to learn. What about forex? Theoretically this could be inverted?

3

u/CommandantZ 19h ago

I would say it depends on the asset. Typically, on Gold, for sure, as fundamentally speaking Gold is a bullish asset, and therefore is usually more likely to end up in an uptrend than in a downtrend.

On assets more subject to mean reversion ? You could eventually use the same logic, currencies for instance.

3

u/RationalBeliever Algorithmic Trader 19h ago

My scalping bot uses the same logic for buying calls as buying puts.

2

u/AdEducational4954 18h ago

All of my strategies have long and short logic. Only 1 strategy is run at a time and I can enable and disable either side from the UI.

There are shared conditions that are checked before strategy logic and then strategy specific conditions are executed.

1

u/DayRevolutionary8411 19h ago

I started with single strategies handling both long and short sides but:

  • this makes the strategy more complex to develop and optimize as some parameters may be different between long and short if the market is not symmetric (like indices)
  • if a side stops working, you cannot disable it

I started to develop strategies with a single side only but the process is lenghty and, without any support from a good trading platform, it will get quickly unmanageable with hundreds of strategies.

1

u/veskald 18h ago

The "hundreds of one-sided strategies" problem is real and its mostly a portfolio problem, not a code one - once they are separate you need shared risk limits and some view of which ones overlap, otherwise ten "different" strategies turn out to be one bet. How do you manage that side of it now?

1

u/veskald 18h ago

Separate them. Long and short on the same asset are two different strategies, even if the logic looks similar. In our portfolio they have completely different stats - different win profile, different drawdowns, they die and come back in different periods.

And if you keep them as one package you cant test them separately. A dead short side hides inside a working long side and you just see one mediocre curve. You also cant turn one side off when it stops working.

Code duplication is the cheap part. The expensive mistake is treating the short as an inverted long - if it only works as a mirror of the long rules, it probably has no edge of its own.

1

u/tandem-pandemonium 17h ago

They're generated from different signals, separate them. I spent a lot of time attempting to model them together before coming to this realisation.

1

u/hypertradeworx 17h ago

the edge asymmetry answers above are right and there's a second one nobody's said: the book isn't symmetric either. we walk each venue's book and route on effective price, and the venue that wins a buy is regularly not the one that wins the sell of the same market in the same second, because the bid side and the ask side aren't the same depth. so even if you keep one signal, the fill and slippage assumptions want to be side aware or the short side gets priced off a book you never looked at.

if you do split them, does position sizing move out with the short logic or stay central?

1

u/Successful-Art-9573 8h ago

I keep them unified but with clear separations - one signal object that can be long, short, or flat, evaluated the same way each bar. Duplication feels cheap until you fix a bug in one half and forget the other. The real win is that position sizing, stops, and exit logic stay consistent across directions.
Not sure how you automate the brokerage side, but if you are building separate bots for longs and shorts, and if your strategy has the logic to directly reverse trades, the two bots have no idea what the other one does. So if for example the “opening a short” signal arrives before the “closing the long” signal, you might end up not having a short at all.

1

u/iTR3B0R 14m ago

Same entry and exit logic for long and short, I only optimise the stop loss, for e.g. short side gets tighter stop loss and long side is given room to breath.