First post to the forums and Im looking for some assistance coding an automated order management routine. I might end up paying an expert to do the coding (PM me if youre interested) but before sending out the brief I wanted to check the methods and welcome any feedback or suggestions you may have. The logic is basic trading 101 and in the interest of paying it forward, Id be happy to put the final code here.
To start off, Im not tied to using the tradestation platform, and Id be prepared to switch to another broker / platform if its more stable for these strategies. For example this trader () reporting to make 100 pips a day explained he got more stable results relaying signals from tradestation to NT7 (through the dll interface) and on to Gain / IB but for now Im using TS (9.1). IQbroker might be worth a shot too again, feedback would be welcome.
So, on to the coding to start off, I have a string of price action conditions (separated by OR) for long and short entries which have been generated by this ().
The default parameters for this particular set of conditions are very straightforward: use a daily chart, set stop and target of 150pips and when a condition is met, open the position at the start of the next bar (ie as its a daily chart, the open on the next day).
But the performance would be significantly improved with some dynamic exit strategies (moving stops, multi stage exits) and position sizing (compounding returns). The long/short conditions could also be improved using some oscillators and multi time-frame verifications of a signal but given the length of this brief, Ill address those later.
Heres the proposed workflow:
On condition long triggered:
1. If on the open, the market has gapped up/down by more than 100 pips (calculated by the difference between the close of last bar (which generated the signal) and the open(?)), ignore signal.
2. Else, do the following:
3. If there is an existing short condition active, close short position at the open (so the system is either long, short or out, no hedging).]
4. then open long position
5. If there is an existing long position active, add to position at open of next bar but no more than 300,000 contracts at any time (note portfolio compounding rules will impact # of contracts).
6. Set stop on all 300,000 contracts to 150 pips below market price (note all stops and limits are variables so they can be tested and optimized for the particular instrument in use)
7. Take profit 1 @ 50 pips above market price
8. Take profit 2 @ 100 pips above market price
9. Take profit 3 @ 300 pips above market price
10. On TP1 hit, sell 100,000 contracts, move stops on remaining contracts to breakeven.
11. On TP2 hit, sell 100,000 contracts, move stops on remaining contracts to TP1 position and trail behind market price at a distance (use PSAR ( to calculate the trailing stop distance?) or TP3 hit.
On condition short triggered:
Same behaviour as a long position if on the open, the market has gapped up/down by more than 100 pips ignore signal etc.
If a second long/short signal follows which matches the direction of the previous signal:
Add to position to a maximum of 15% of account in play at any one time (# of contracts defined by the portfolio management and compounding rules set out below).
The new position follows the same rules as before (stops at 150pips below market on the open, TP1,2,3 etc.)
Compounding & Portfolio management
Amend # of contracts based on available purchasing power in the account.
For each new signal a max 5% of the account should be used when open any new position, On multiple signal confirmations, no more than 15% of the total account should be in play at any one time. The workflow above assumes 300,000 contracts represents 5% of the account, but in the event there arent enough funds in the account to open 3 legs, open just one and set the target to TP2, moving stops to breakeven if TP1 reached (this exit behaviour should be tested and optimised).