Login Page - Create Account

Support Board

Date/Time: Mon, 22 Jan 2018 10:37:21 +0000

Offering To The Community: Trade Status Report (starting point for external trade program ctrl)

Support Request:
[2016-12-07 05:57:08]
bjohnson777 (Brett Johnson) - Posts: 204
Trade: Status Report. This program writes out a TSV file (Tabbed Separated Values, similar to CSV but with tabs that are easier to parse) to Sierra Chart's Data directory logging any changes to found trades in a human readable and computer parsable format.

This program is a primitive step (and I stress primitive) towards using Sierra Chart to control/trigger external trade programs for trade services that do not support Sierra Chart. The external trade program will need to watch this program's log file in real time to follow Sierra Chart's trading. Another program will need to be written for this interface, so this program is only half of what you would need.

This program is NOT suitable for high speed trading. At best it may take several seconds for the external trade program to parse the log and act if it is local on the same computer. At worst it may take a few minutes for a trade to execute if remote controlling a web browser that has to log into a site, parse numerous web pages, and then execute the trade (like for a private bank IRA brokerage account).

TSV single line format: (commas should be replaced by tabs)
Symbol, Open Trade Date, Close Trade Date, Trade Status, Entry Order Type, Exit Order Type, Trade Type, Volume, Average Entry Price, Average Exit Price
Symbol: Sierra Chart's internal version of the trade symbol
Open Trade Date: format is YYYY-MM-DD HH:MM.SS
Close Trade Date: same format as Open Trade Date. If the trade is still open, this will be '0'.
Trade Status: this will be 'open' or 'closed'.
Entry Order Type: this will be something like 'Limit', 'Market', or 'Trailing Stop' (Sierra Chart internally defined). If not found or unknown, the value will be 'x'.
Exit Order Type: Similar to Entry Order Type adding that an 'x' will be here if the order is still open. It is not practical to add something like an open trailing stop here as that would require more data slots than a TSV format would easily allow for (both monitoring and constant updating, forcing the external trade program to constantly update).
Trade Type: this will be 'long' or 'short'.
Volume: always a positive number.
Average Entry Price
Average Exit Price: If the trade is still open, this will be '0.0'.

This program cannot keep track of trades after program exit. Upon program re-entry, this program will write out a new line showing the order as 'open' if the order is still open. If the order exited sometime in between, this program may not know about it and nothing may be reported. To help prevent that, extra lines will be printed about the current open or last trade. Your external interface program will need to be aware of that and process the extra lines accordingly. Use Symbol, Open Trade Date, Trade Type, Volume, and Average Entry Price to identify a single order in your external trade program.

This program currently has no external input to converse with the external trade program (it's not an API). A chart study has no way of 'resetting' a Sierra Chart order from an external source. This would require deep program access to Sierra Chart which a chart study does not have.

This program will not keep track of complicated trades very well. Stick with a simple one trade per symbol, or you'll lose track and quickly create undesirable situations.

This program can be run on several charts with trades at the same time. Just be warned that there is the potential that they may all try to write to the default log file at the same time. The write function has been written in an attempt to minimize gibberish (status lines interleaved on top of each other) output, but it may not always succeed under every circumstance. If you have hundreds of trades open that could all exit at the same time, you might want to change the file names and update your external trade program to follow accordingly (or at least test it out to make sure there isn't gibberish output in the log). So far, Sierra Chart testing has shown that chart studies are single threaded and will not write over each other in the log file. This may change in the future, though.

Reminder: You will need to keep track of trade settlement times and account balances in your external program.

Warning: Price data received by Sierra Chart and price data received by the external trade program could (and probably will) be different. With centralized exchanges (like for most stock markets), the difference probably won't be much, if any (maybe a little extra slippage). With decentralized exchanges (like for Forex), the price difference can be dramatic. Some other chart programs deliberately manipulate the spread (usually for built-in commissions, but sometimes abusive depending on the broker) in such a way that there will never be a price data match. Note that what looks like a winning trade in Sierra Chart could be a losing trade in the external trade program. Extra safeties would need to be programmed on both sides to help avoid this (something like my Multi-Function Trailing Stop). This greatly increases the amount of needed code and maintenance. There are ways of getting external price data into Sierra Chart, but this also massively increases the amount of needed code beyond what a chart study can handle. A third program in the middle would likely be needed (a true bridge instead of a pair of loosely coupled chart studies).

Some users may want to use this program to log their own trades. This isn't the primary purpose of this program, but TSV data can be imported into a spreadsheet. The main problems with this idea are duplicated status lines and missed trade exits by this program. Remember that it's just a chart study in a very limited execution environment.

Regular compiles moved to "Brett Johnson's Standard Tool Kit" DLL.
attachmentTrade_StatusReport.cpp - Attached On 2016-12-07 05:56:08 UTC - Size: 22.21 KB - 62 views
attachmentTrade_StatusReport.dll - Attached On 2016-12-07 05:56:13 UTC - Size: 30.5 KB - 25 views

To post a message in this thread, you need to login with your Sierra Chart account:


Login Page - Create Account