{"id":411,"date":"2007-06-24T14:59:04","date_gmt":"2007-06-24T14:59:04","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/06\/24\/a-real-time-message-fifo\/"},"modified":"2007-10-17T23:13:54","modified_gmt":"2007-10-17T23:13:54","slug":"a-real-time-message-fifo","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/06\/24\/a-real-time-message-fifo\/","title":{"rendered":"A Real-Time Message FIFO"},"content":{"rendered":"
Real-time messages often appear on your screen only for the duration of a single chart-refresh interval and disappear before you have time to read them. The FIFO (First In First Out) n-line display presented here captures and scrolls messages in the chart Title so that they are easier to read. Logging messages to DebugView or the Interpretation window would require opening additional windows. Using the Title instead displays the messages right on the chart and is more space-efficient.<\/p>\n
A typical application would be to display real-time system status, such as order status, TWS error messages, partial fills, account balance, profits, etc.<\/p>\n
Since the chart Title does not support formatting, it is advisable to use a mono-spaced font, such as Lucida Console, and pad spaces to create columns. The integer part of the NumToStr() formatting parameter sets the overall length of the returned string and can be used to format columns. If you prefer more font and color options, you can use Gfx functions to display the messages.<\/p>\n
To prevent Title wrapping, you can truncate messages using the StrLeft() function. This works well for TWS error messages that can be long but carry the important info at the left of the error message. The demo below uses a simple PadString() function to space short messages in columns.<\/p>\n
The AddToFIFOTitle() function is called whenever you want to add a message to the table. Its first argument is the name of the static variable that contains the table, the second argument is the message you want to add to the table, and the third is the maximum number of lines in the table. Setting the third argument to zero clears the table.<\/p>\n
To keep things simple, the code below uses Param functions to simulate real-time messages; in a real system, these messages would be generated by real-time events. To test the code, click any of the numbered Event Messages<\/em> in the Parameter window.<\/p>\n <\/a><\/p>\n The Title produced should look like this:<\/p>\n