Processing TDash Commands

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.

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.

To make this work requires that buttons are organized as follows:

  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.
  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.
  3. Since all buttons respond to mouse movement and button clicks, buttons can have four possible possible action states:
      Hover: the cursor hovers over the button
      LeftClick: the left button is clicked while the cursor is over the button
      LeftDown: the left button is held down while the cursor is over the button (Dragging)
      LeftRelease: The left button is released while over the button

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.

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:

    Marker,Buy // cursor hovers over the button
    ~Marker,Buy // left-click on the button is detected
    ~~Marker,Buy // the left mouse button is down on the button (dragging)
    ~~~Marker,Buy // the left mouse button is released while over the button

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().

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.

Below is a simple Switch(0 to decode the “Marker Buy” command used in the previous post:

TDashAction =  VarGetText"TDashAction" );

switch ( TDashAction )

case "Marker,Buy":
    // perform tasks in response to hovering over the Marker
    _TRACE"TDashAction: " TDashAction );

case "~Marker,Buy":
    // Perform action in response to a left click on the Marker
    _TRACE"TDashAction: " TDashAction );

case "~~Marker,Buy":
    // React to dragging the marker
    _TRACE"TDashAction: " TDashAction );

case "~~~Marker,Buy":
    // Perform action in response to releasing the mouse button
    _TRACE"TDashAction: " TDashAction );

Comments are closed.