How to Process Orders In Your Strategies
There's 2 general approaches to handling orders when using software. The one most are familiar with is called "normal order flow" here but the more advanced and flexible approach is called "signal order flow" in TickZOOM.
Normal Order Flow
Normal order flow means that your strategy code directly handles all the complexity of submitting orders, canceling them, getting errors like rejects, and tracking all of that. Worst of all, all the benefits of signal order flow below get entirely eliminated by using normal order flow. So far, all traders who learn about signal order flow prefer it to normal order flow.
NOTE: Direct access to the normal order flow will be available after complete integration with TradeLink. However, when you enable this feature, it will disable many of the benefits below.
Signal Order Flow
Until now, signal order flow was only used by the automated traders who build their own custom trading platforms and often get accused of being "more secret than the CIA".
Signal means that your strategy simply provides a value for the number of positions you want at any given moment (per tick).
The back end execution server then converts that signal which is either long (>0), short (<0) or flat (=0) into orders simply by comparing to your current positions plus your open orders total.
If those differ, it will cancel or add orders as needed to bring your positions to the signal level.
Signal order processing massively simplifies the automated order flow and other advantages.
Limit, Stops and Other Orders
At the same time, your strategy can still use limit order, stops and other more advanced exits which all get processed synthetically without actually sending those orders to the broker. Instead, they get converted to a signal by updating for every tick.
Limit Entry Order Example
To handle a limit order using signal order processing, inside the ProcessTick( Tick tick) event, you simply put code like this:
if( tick.Ask <= longEntry) {
Signal.GoLong();
}
if( tick.Bid >= shortEntry) {
Signal.GoShort();
}
The nice thing about this is that if you want to "cancel/replace" this before it gets filled, all you do is modify the value of your variable "longEntry" or "shortEntry".
Entry Only Versus Reversals
the entry order example above will switch to a long position whether the position is currently short or flat.
If you would like to prevent reversals of existing positions:
if( Signal.IsFlat && tick.Ask <= longEntry) {
Signal.GoLong();
}
if( Signal.IsFlat && tick.Bid >= shortEntry) {
Signal.GoShort();
}
You can use Signal.IsShort or Signal.IsLong to control the entries even further.
NOTE: In the near future there will by an EntryCommon class (similar to ExitCommon described below) which simplifies the usage of limits and stops for entry and even adds bracket orders and other such.
PERFORMANCE TIP: It's best to limit the logic you perform in the ProcessTick() method. Instead perform calculations on IntervalOpen or IntervalClose events, if possible, that set your longEntry or longExit variables.
How to Add to Current Positions
If you want to add to an existing position, you use the Signal.Positions property like so:
Signal.GoLong( Signal.Positions + 3);
Signal.Positions needs to be renamed to PositionSize because it gives the size of your current position. So it's a positive number even if your position is short. In fact, it simply returns the absolute value of the signal itself.
Of if you want to get fancy, just use the Signal.Signal directly.
Signal.Signal is the signal that all of this controls.
So Signal.Signal = 2; // Set the current position size to long 2.
Or Signal.Signal = -3; // Set the current position size to short 3.
Or if your current Signal.Signal is 5 and you code:
Signal.Signal += 10;
Then your current position will be short 5.
Stop Loss and Profit Target Exits
Using signal order processing, exits like profit target and stop loss are implemented in the ExitCommon class and available inside strategies via the Exits property.
So anywhere in your strategy you can set or change your ProfitTarget or StopLoss:
Exits.ProfitTarget = 123; Exits.StopLoss = 332;
These exits work naturally like OCO in that they only operate when you have a position on.
Normally, you set these at a fixed value inside your Initialize() event method. Then they work every time you have position on whether long or short.
Still, you can modify them at any time during the strategy based on changing market condition and they keep the new setting until you change them.
Portfolio of Strategies on the Same Symbol
Signal order flow makes it possible to trade a portfolio of 2 or more strategies on the same symbol with overlapping trading.
The Portfolio class in TickZoomCommon simply sums the signals from each strategy. So if one is long 2 and the other is short 1 then the resulting signal will be long 1. That allows each strategy to operate independently without interfering with the others.
You configure which strategies run in parallel inside your Model Loader. The CustomPlugin comes with a ModelLoaderExample.cs class.
Other techniques for combining them are also valid like summing with a limit on the total size of any position.
Resetting After Disconnect
Signal order flow makes it resetting very simple indeed to any disconnect. That's because it continuously compares the strategy signal to actual positions and open orders and then readjusts so they stay synchronized.
Back End Processing of Signal Order Flow
Conversion of the signal to orders can be done via 2 techniques, one is via simple market orders, then other is to use limit orders to insure better fills is less liquid markets.
For limit orders, the back end logic is more sophisticated because it must cancel replace as needed until the limits get filled.
Since limit order are generally not necessary due to the high amount of liquidity, TickZOOM doesn't support this yet, however this has been added to the enhancement list.
Emergency Stop for Signal Order Flow
TickZOOM will be adding the feature of a configurable emergency stop for signal order flow that actually does get registered with the broker. You strategy will be able to change dynamically how far this stop sits from the current price and how often it gets canceled and replaced as a number of seconds.
