Recently I got a quite unusual job: Here’s an extremely profitable strategy for the TradeStation platform. It’s a bit large – about 3000 lines of EasyLanguage code. Please replicate that monster in C++ so that it runs on the Zorro platform, but still produces the same trades as on TS. While you’re at it, fix any bugs that you encounter in the EasyLanguage code. You have 2 weeks. Good luck.
The strategy in question is arguably the largest trading script ever written. At least it’s the largest I’ve ever seen. The system was created by a famous trader, and is said to produce ‘stellar returns’ for his customers. It had to be now migrated to Zorro. It’s not a single strategy, but a combination of multiple algorithms, similar to Zorro’s Z12 system. However unlike Z12, it is not divided into separate algos that trade simultaneously. Rather, its many indicators, filters, entry and exit conditions can be combined with each other in multiple ways. With the right combinations, you got the ultimate strategy. What are these magic combinations? I don’t know, but if you buy the system, you can maybe find out.
It turned out that coding the system in C++ was the easiest part of the job. The code was large, but well structured and not very complex. Using C++ reduced the code size by 50% and increased the speed by about 2000%. I suppose some of its functions are now also more reliable. The challenging part was not the code conversion, but exactly replicating the trade behavior of TS. And that is the main topic of this article.
When you convert an EasyLanguage script to a different platform, you’ll face the problem that TS opens positions – or not – in a way you might not always expect. The usual command for entering a long position with an entry limit looks like this:
TS: Buy N Contracts Next Bar at MyEntry Limit; Zorro: enterLong(N,-MyEntry);
Zorro would then just enter a pending trade at the given limit. But what TS does depends on the context. This is only partially documented, so I had to find out by experiment. Here are the rules by which TS appears to trade and fill positions (unless ‘pyramiding’ is enabled):
- If another buy or sell command was given within the current bar, the new command is ignored.
- If a position in the same direction was already open, the command is ignored.
- If a position in the opposite direction was already open, the command is executed and closes the opposite position when filled.
- If a position in the same direction is currently pending, and if no other buy or sell short command was already given within the current bar, the entry limit of the pending position is set to the current entry limit.
- If no position is open and no other buy or sell short command was given within the current bar, the command is executed.
- If several pending positions hit their entry limits within the current bar, only the first one is filled.
- If a position is filled, the fill price is the given entry limit with no slippage, but 1 point penalty.
Similar rules apply for closing a position.
For replicating the TS behavior, you first need to set up Zorro’s trading parameters in this way:
void emulateTS()
{
setf(TradeMode,TR_EXTEND); // update pending trades
MaxLong = MaxShort = 1; // only 1 open position
Hedge = 1; // close opposite positions
Fill = 3; // next bar, optimistic mode
Penalty = 1*PIP; // 1 point
Slippage = 0; // don’t simulate slippage
Interest = 0; // don’t calculate margin interest
}
When the entry limit is hit, you must check whether it’s the first hit of the current bar or not. If not, don’t enter. You need a trade management function for this:
#define LastEntryBar AssetInt[0]
int manage() // fill only the first pending position at any bar
{
if(TradeIsEntry) {
if (Bar == LastEntryBar)
return 1; // don’t open it
LastEntryBar = Bar;
}
return 16; // open it or wait for next entry
}
TS adjusts the entry limits and stops of open positions only if no other buy/sell command was given before on the same bar:
#define LastBarLong AssetInt[1];
void buyNextBar(var Limit)
{
if(Bar != LastBarLong) { // first command of the bar?
setf(TradeMode,TR_ANYLIMIT|TR_ANYSTOP); // adjust limit/stop
LastBarLong = Bar;
} else // don’t adjust
resf(TradeMode,TR_ANYLIMIT|TR_ANYSTOP);
enterLong(Lots,-Limit);
}
#define LastBarShort AssetInt[2];
void sellShortNextBar(var Limit)
{
if(Bar != LastBarShort) { // first command of the bar?
setf(TradeMode,TR_ANYLIMIT|TR_ANYSTOP); // adjust limit/stop
LastBarShort = Bar;
} else // don’t adjust
resf(TradeMode,TR_ANYLIMIT|TR_ANYSTOP);
enterShort(Lots,-Limit);
}
I do not recommend using this code for other purposes than for emulating TradeStation. But the monster strategy with this trading code opened exactly the same positions at exactly the same time and entry price as the original system on TS. Only exceptions were a few differences by rounding or by fixing bugs of the original code.
By the way, here are some code lines to replicate some often-used TradeStation parameters in C/C++:
int MarketPosition = sign(NumOpenLong-NumOpenShort); var PriceScale = 100; // always 100 for stocks and futures var MinMove = PIP * PriceScale; // Stock: 0.01 * 100, Emini: 0.25 * 100 var PointValue = LotAmount / PriceScale; // Stock: 0.01, Emini: 0.50 var BigPointValue = LotAmount; var EntryPrice = 0; for(current_trades) if(TradeIsOpen) EntryPrice = TradeFill;
I hope this helps anyone who happens to get the task of replicating a large TradeStation system on a different platform. Good luck!
`This is only partially documented, so I had to find out by experiment.` – my brain starts aching
You nailed it with the “new methods” angle – the real hack isn’t finding one magic indicator, it’s having the right tool for each market regime. I spent two years chasing the perfect EA before realizing no single bot survives all conditions, and my drawdown was brutal because of it. That’s why I switched to Ratio X Toolbox for MT5, which gives me specialized bots for trending, ranging, and gold markets instead of forcing one strategy everywhere. Machine learning and statistical analysis only work if you’re matching them to the actual market phase you’re in.
” … What are these magic combinations? I don’t know, but if you buy the system, you can maybe find out.”
Where can I get a description of the system & pricing?
AFAIK the new Zorro version of the mentioned system will become available in the next time. The previous TradeStation version is long available – for description and price, google for ‘Ranger trading system’.
interesting is possible to see the big code? 😀
Sure, when you buy it. 😉