{"id":2530,"date":"2011-03-09T00:37:14","date_gmt":"2011-03-09T00:37:14","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/?p=2530"},"modified":"2011-04-08T11:05:22","modified_gmt":"2011-04-08T11:05:22","slug":"processing-tdash-commands","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2011\/03\/09\/processing-tdash-commands\/","title":{"rendered":"Processing TDash Commands"},"content":{"rendered":"

If you watched the small video in earlier post on Order Markers you may have noticed that whenever the mouse cursor hovered over, or a mouse button was clicked while over an Order Marker, the “TDashAction” variable shown at the right top of the video changed. This is a unique variable that is solely responsible for communicating TDash Action to the Auto-Trading module. This method allows TDash to be linked to your current trade automation module. This post explains how this works. <\/p>\n

Because the cursor can only be in one location at a time, all TDash commands are exclusive. Hence we do not need to assign individual names to each parameter, instead we can use a single string variable to tell us the name of the button and action performed. Compared to using traditional Param()s, where each Param() assigns a value to a unique variable, this eliminates about 50-100 variable names, and allows us to use a single Switch() command to process the commands. It also makes code easier to read, modify, and maintain.<\/p>\n

To make this work requires that buttons are organized as follows:<\/p>\n

    \n
  1. Buttons are assigned to uniquely named groups like “Markers”, “Menus”, “Trading”, “Setup”, “Account”, “Status”, etc. For example, the Order Markers covered in the previous post would fall in the “Marker” group, the forthcoming QBar controls will fall in the “QBar” group, etc. <\/li>\n

    <\/p>\n

  2. All buttons must have an upper “Header”, and may have an optional lower “Label”. The visible header and label is unique to the group it belongs to. A typical example would be a Buy @ LMT button, “Buy” would be the Header, and “LMT” would be the lower Label. In this case the lower label may take on different values, such as “MKT”, “STP”, and “STPLMT”. Header-only buttons are typically used for trigger functions which have no changing state to display, for example “Reset” or “Abort” buttons.<\/li>\n

    <\/p>\n

  3. Since all buttons respond to mouse movement and button clicks, buttons can have four possible possible action states:\n
      \nHover: the cursor hovers over the button
      \nLeftClick: the left button is clicked while the cursor is over the button
      \nLeftDown: the left button is held down while the cursor is over the button (Dragging)
      \nLeftRelease: The left button is released while over the button\n<\/ol>\n<\/ol>\n

      These four action states are encoded by prefixing a “~” for a Leftclick, “~~” for a LeftDown condition, and “~~~” for the LeftRelease. Concatenating the action prefix, group name, visible header string, and visible Label string into a csv string provides us with a “TDashAction” string that uniquely defines the button and its transient states. Because for multi-state buttons the lower label describes the state of the button, this string also tells us the state of the button. For additional clarity we can also change the button-color to indicate its state.<\/p>\n

      For example, dragging the Buy Order Marker shown in the previous post would, over consecutive executions, generate the following sequence of changes in the TDashAction variable:<\/p>\n

        \nMarker,Buy \/\/ cursor hovers over the button
        \n~Marker,Buy \/\/ left-click on the button is detected
        \n~~Marker,Buy \/\/ the left mouse button is down on the button (dragging)
        \n~~~Marker,Buy \/\/ the left mouse button is released while over the button\n<\/ol>\n

        This type of encoding is used for all TDash buttons and controls. While this method may be a little esoteric it makes reading the code very easy, and allows us to add controls without having to dream up a new set of variable names. We just look at the displayed TDashAction string and we know the name for the action to be decoded in our Switch(). <\/p>\n

        This method makes decoding TDash action using a switch() simple and easy to debug. Note that in most cases not all possible states need a case statement. A major advantage of using a Switch() statement is that one can, at any time, easily add and\/or remove buttons. <\/p>\n

        Below is a simple Switch(0 to decode the “Marker Buy” command used in the previous post:<\/p>\n

        TDashAction <\/span>=  <\/span>VarGetText<\/span>( <\/span>"TDashAction" <\/span>);\r\rswitch ( <\/span>TDashAction <\/span>)\r{\r\rcase <\/span>"Marker,Buy"<\/span>:\r    <\/span>\/\/ perform tasks in response to hovering over the Marker\r    <\/span>_TRACE<\/span>( <\/span>"TDashAction: " <\/span>+ <\/span>TDashAction <\/span>);\r    break;\r\rcase <\/span>"~Marker,Buy"<\/span>:\r    <\/span>\/\/ Perform action in response to a left click on the Marker\r    <\/span>_TRACE<\/span>( <\/span>"TDashAction: " <\/span>+ <\/span>TDashAction <\/span>);\r    break;\r\rcase <\/span>"~~Marker,Buy"<\/span>:\r    <\/span>\/\/ React to dragging the marker\r    <\/span>_TRACE<\/span>( <\/span>"TDashAction: " <\/span>+ <\/span>TDashAction <\/span>);\r    break;\r\rcase <\/span>"~~~Marker,Buy"<\/span>:\r    <\/span>\/\/ Perform action in response to releasing the mouse button\r    <\/span>_TRACE<\/span>( <\/span>"TDashAction: " <\/span>+ <\/span>TDashAction <\/span>);\r    break;\r}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

        If you watched the small video in earlier post on Order Markers you may have noticed that whenever the mouse cursor hovered over, or a mouse button was clicked while over an Order Marker, the “TDashAction” variable shown at the right top of the video changed. This is a unique variable that is solely responsible […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[141],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/2530"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=2530"}],"version-history":[{"count":85,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/2530\/revisions"}],"predecessor-version":[{"id":2772,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/2530\/revisions\/2772"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=2530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=2530"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=2530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}