Instead of using the Inputs dialog to add virtual trades, I decided to create a control interface into the indicator via messages embedded in global variables. The commands the indicator currently "knows" are:
GET_EQU - return the current equity
GET_VER - return the indicator version
GET_RDY - test whether all data is available and equity calculation is valid
SET_MAP - change the Moving Average period
SET_MAT - change the Moving Average type
SET_RDW - force a redraw of the indicator
SET_BUY - add a buy trade
SET_SEL - add a sell trade
SET_RST - delete all virtual trades and reset indicator
When the indicator sees a new command, it does the following actions:
- creates a new global variable to save the command
- performs the command
- deletes the command global variable
- creates a response global variable
Code: Select all
?[AAA]CMD_NAM{parameters}The saved copy is the same as the command, but is prefixed by an asterisk instead of a question mark.
Code: Select all
*[AAA]CMD_NAM{parameters}Code: Select all
![AAA]CMD_NAM{parameters}{OK}So, an example conversation to get the current equity would be:
Requester creates a global variable:
Code: Select all
?[AAA]GET_EQUCode: Select all
![AAA]GET_EQU{OK}A more complex example is the setting of a virtual trade. This requires passing the Direction, Symbol, Open Price, Lots and Open Time
The command looks like this:
Code: Select all
?[AAA]SET_BUY{EURJPY|103.33800000|1.0|1353085440}Code: Select all
int start()
{
GlobalVariableSet("?[AAA]SET_BUY{"+Symbol()+"|"+WindowPriceOnDropped()+"|1.0|"+WindowTimeOnDropped()+"}",0);
return(0);
}
I still need to add commands to get the current MA value and the current Equity-MA value. I may also add commands to delete trades, but we'll see.
This may be nothing more than idle hands coding a solution in search of a problem. It wouldn't be the first time.
George
