Mar
28

Formula 301 – #6 Automatic Brokerage Position Management

Here is a very interesting indicator that can be used to monitor your brokerage position and place protective orders for you, no matter you are a discretionary trader or a mechanical trader.

Brokerage Information Functions

There are 2 functions in the indicator formula language that talk to the currently connected brokerage service to obtain the latest information about your open positions.

BrokerPosSize returns the current position size, including direction (positive for long, negative for short) of the symbol that the primary series your indicator is linked to.

BrokerPosAvgEntry returns the unit cost per each contract or share you hold in the account, at the moment.

For example, you are trading the stock MSFT. If BrokerPosSize returns 1000, then it means the current connected brokerage interface thinks that you are holding 1000 shares of MSFT. On the other hand, if it returns -1000, it means that you are shorting 1000 shares at the moment.

Advance Order Placement Functions

Advance Order Placement Functions are order functions that do not restrict your long or short intention. They are orders that simply route what you wanted to do, to the brokerage interface (or the trading system).

Comparing to the basic order placement functions, using the advance order placement functions can create more complex trading strategies, but easily lead to design errors in the systems that can be very hard to identify or corrected. It is recommended that when you are prototyping your trading systems, use the basic order functions whenever possible, and switch to use advance order placement functions if and only if you cannot express your idea clearly otherwise.

BuyAtMarketTIF places an order to buy the primary series symbol, with no restriction nor adjustment based on your current position.

SellAtMarketTIF places an order to sell the primary series symbol , with no restriction nor adjustment based on the current position.

otfGoodTilCancel is a predefined constant that NeoTicker can recognize when used in the Advance Order Placement functions. By placing an order with Time In Force set to Good Til Cancel, the order will be able to stay in the brokerage system until you issue an instruction to cancel the order.

The Example Indicator – Brokerage Position Monitor

I will not spend time discussing the details of the indicator coding in here because it is very straightforward. The only interesting technique in the indicator is how I use a local variable detecting whether the indicator is now updating in real-time.

Once you have installed the indicator from this article, you can apply it to a chart to see how it works.

I choose to apply the indicator onto a 15-second chart of Emini S&P.

An important part of using this indicator properly is setting the indicator options correctly.

Here is the parameter setup,

tips20060326 indsetup1

I will discuss in more details about how this indicator works, thus we will skip the parameter explanation for now.

Then, the system setup,

tips20060326 indsetup2

Notice that the Single Entry Per Direction option and the Close Position EOD option must be disabled.

Make sure you fill in the correct value for the Price Multiple and Min Tick Size.

Then, we set the indicator to connect to the order interface,

tips20060326 indsetup3

Make sure the indicator obtain its fill back from the order server.

Finally, the system synchronization settings should be disabled because the indicator does not really synchronize its position with the brokerage account,

tips20060326 indsetup4

How It Works

In real-time, this indicator will do 3 things for you automatically.

1. If your current brokerage position on the tracked symbol has exceeded the limit you have imposed in the indicator, the indicator will automatically place an order to reduce your current exposure. For example, if your preset limit is 5 contracts, then if you changed your position to long 7 contracts, then indicator will automatically place an order to sell 2 contracts at the market, for you.

2. If your current brokerage position combined losses has exceeded your predefined limit in the indicator, it will close out your open position completely.

3. When you have established a profitable position, the indicator will force you to take profit if the trailing condition is violated. I have chosen to use a very basic setup as the trailing stop, 20 period highest high for short side, and 20 period lowest low for the long side.

Each rule mentioned above can be customized by the respective parameter.

Here is a chart of the indicator in action,

tips20060326 chart

The 2 orders you see in the chart are placed by the indicator, take a look at the Account Manager to see how it works together with the manual orders I have placed.

tips20060326 account manager

Special Consideration Among Brokerage Connections

Not all brokerage interface can provide complete position information.

The Trade Simulator within NeoTicker can provide full position information which includes the current position size and the average entry price.

For brokerages that cannot return the full position information, the indicator presented here has to be modified to accommodate the missing data. For example, if your brokerage cannot provide the average entry price of your current position, then you need to remove the stop loss orders and trailing stop orders.

Another important consideration is the response speed of your brokerage. If it takes more than 5 seconds to obtain the latest brokerage position information from your brokerage after an order is placed, then, practically, you cannot implement any trading systems that depends on accurate fill information from the brokerage in under 5 seconds. Thus the indicator I have presented here is probably useful for most brokerages when applied onto a data series with resolution at or higher than 2 to 3 seconds per bar.

Room For Modifications

The trailing stop implemented in the indicator may not be the type of trailing stop you like to use. You can modify the indicator and test it out using the Simulation Server.

You can also add target orders to take out partial position, I will leave that to you as an exercise.

Complete Indicator

Brokerage Position Monitor.

Summary

The ability to obtain directly from the order interface the updated position information is very useful. It fills the gap between an indicator’s expectation of your position and the actual situation. You can utilize this information in many different ways. What I have shown here is just a starting point for further studies.

(Lawrence – Warning! If you intended to use this indicator with a live brokerage account, then test it with the trade simulator first to understand exactly how it works. Use the indicator at your own risk.)

Discuss this article

One Comment on “Formula 301 – #6 Automatic Brokerage Position Management”

  1. IroquoisFX Says:

    Hi,
    thanks for this, this actually helps me a lot towards my own management system. However, I was wondering how to use it in Forex (which I trade mainly), since the ratio between order sizes and P/L is like 100. When I apply this onto a forex chart, it propels the red line to 100K, and the green PL line remains at the bottom ; I guess it’s not the expected behavior. I tried to modify the order sizes but apparently couldn’t figure it out.

Leave a Comment

Blog Developed
By ContentRobot