Stategy control panels
Strategy parameters are normally set up with the sliders or simply by editing the script. For executable strategies that do not come with source code, or for complex strategies with multiple parameters and options, a strategy specific control panel can be created by script or from a spreadsheet template. The panel is a rectangular grid of multi-purpose cells. Every cell can display text, numbers, and a color, and can serve as a numeric or text input field or as a push, toggle, radio, or spin button. With this concept, even complex control functions for commercial strategies can be realized in a simple way. Such a control panel does not look particularly pretty, but it's functional:
The following functions can be used for defining and handling a control panel (Zorro S or executable strategies only):
panel (int rows, int columns, int color, int size)
Opens an empty control panel with the given number of rows and columns, background color, and horizontal cell size in pixels. If a control panel was already open, it is replaced by the new one. The panel is opened next to the Zorro window, and can be freely moved by dragging it with the mouse. Use size = 0 for removing the panel.
panel (string filename, int color, int size)
Opens a control panel with the structure and content from a .csv spreadsheet file. Every cell of the panel is set up from the corresponding spreadsheet cell. The cells in the file are separated with ; or , delimiters (delimiters must not appear in cell content). Every row must end with a new line character. The following characters in the cell content have a special meaning: !... - cell is a button; #... - cell can be edited; @ - merge the cell with the next not-empty cell to the left. The default colors are grey for text cells, red for numbers, yellow for editable cells, and blue for buttons; they can be changed with the ColorPanel variables. The panel above is generated from the following file:
Leverage,@,400,,, ,Algo 1,Algo 1,Algo 3
Lot size,@,100,,Max Allowed Loss %,@,#5,#20,#25
Commission,@,1.2,,First Step Volume+,@,#1,#5,#20
Long Trades,@,34,,Volume Max,@,#10,#20,#50
Average Profit,@,4.01,,Max Stop Distance,@,,,#300
Average Spread,@,10.2,,!Open New,,@,,
Average slippage,@,1.4,,!Hide Candles,,@,,
Average Trade Cost,@,15.34,,!Show Statistics,,@,,
panelSet (int row, int col, string text, int color, int style, int type)
Set properties or update content of an individual cell.
row - row number, starting with 0.
column number, starting with 0.
text - content to appear in the cell, or 0 for not changing the content. Numbers can be converted to text with strf.
color - background color of the cell, or 0 for not changing the color.
style - 1 normal cell, 2 red highlighted text, 3 greyed-out text, 4 right-aligned, 8 left-aligned, 12 centered, 0 for not changing the style.
type - 1 normal cell, 2 editable cell, 4 button, 0 for not changing the type.
panelGet (int row, int col): string
Returns a temporary string with the current content of the cell. Numbers can be converted from the returned string with sscanf, atof, or atoi.
panelSave (string filename)
Saves the panel content in .csv format to the given file.
panelLoad (string filename)
Loads the panel content in .csv format from the given file. Only editable or button cells are affected.
click(int row, int col)
User-supplied function that is triggered by mouse click either on a button cell with the given row and col numbers, or on the [Result] button with row at -1. Dependent on the desired behavior of the button, the function can then change the cell color or content through panelSet.
- Control panels can only be created with Zorro S, but can be included in executable strategies (.x files) and then also be used with the free Zorro version.
- Even without a panel, a click on the [Result] button can trigger the click function.
- Text on the panel caption bar can be displayed with the print(TO_PANEL,...) function.
- If the number of rows or columns exceed the screen size, scrollbars are added to the panel.
- The panel stays open after the end of the strategy unless it is explicitely removed either with panel(0,0,0,0), or by clicking [Edit], or by selecting a new script. As long as it is open, it can still be edited and can even trigger functions when clicked on. For preventing that functions are triggered when the script is not running, check the RUNNING flag. For keeping the previous panel content when the strategy is restarted, call panel() or panelLoad() only when both the INITRUN and the CHANGED flags are set.
Example: (see also Source\Download.c)
function click(int row,int col)
string Text = panelGet(row,col);
if(Text == "Buy") // toggle button between "Buy" and "Sell"
else if(Text == "Sell")
else if(Text == "Close All") // push button
else if(Text == "Cancel") // back to last saved state
sliders, user supplied functions
► latest version online