Button Rotate

A ButtonRotate function is like a ParamToggle() but with multiple states. The ButtonRotate function returns the label displayed on the button, and selects the next label each time you click the button. In the example below the ButtonRotate is used to select the next action, which can be Buy, Sell, Short, Cover, Cash, or Reverse. The end result of using this function is similar to using the ParamList() however it is much quicker to use. When the action is selected the order can be transmitted using the Transmit ButtonTrigger().The function returns the displayed label; sometimes the label can be used directly in PlaceOrder(), at other times you may have to use an if() comparison to know which action to perform. For debugging purposes the Title shows the returned values:

rotatebutton.png

The ButtonRotate() is listed below for discussion. There is no need to copy this because it is included in the Include file at the end of this post.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function ButtonRotate( LabelStr, BackColorStr, TextColorStr )
{
    global ColNumber, RowNumber, ColName, ColExpanded;
 
    if ( ColExpanded )
    {
        ColName = VarGetText( "ColName" );
        RowNumber = Nz( kStaticVarGet( "RowNumber" + ColName ) ) + 1;
        kStaticVarSet( "RowNumber" + ColName, RowNumber );
        Rotate = GetButtonClick( ColNumber, RowNumber );
        if ( Rotate OR IsNull( StaticVarGet("RotateInit"+ ColName + RowNumber ) ) )
        {
            RotateIndex = Nz( kStaticVarGet( "RotateIndex" + ColName + RowNumber ) );
            if ( StrExtract( LabelStr, RotateIndex + 1) != "" ) RotateIndex++;
            else RotateIndex = 0;
            kStaticVarSet( "RotateIndex" + ColName + RowNumber, RotateIndex );
 
            Label = StrExtract( LabelStr, RotateIndex );
 
            if ( StrExtract( BackColorStr, RotateIndex ) == "" ) BackColor = StrToNum( StrExtract( BackColorStr, 0 ) );
            else BackColor = StrToNum( StrExtract( BackColorStr, RotateIndex ) );
 
            if ( StrExtract( TextColorStr, RotateIndex ) == "" ) TextColor = StrToNum( StrExtract( TextColorStr, 0 ) );
            else TextColor = 	StrToNum( StrExtract( TextColorStr, RotateIndex ) );
 
            kStaticVarSetText( "Label" + ColName + RowNumber, Label );
            kStaticVarSet( "TextColor" + ColName + RowNumber, TextColor );
            kStaticVarSet( "BackColor" + ColName + RowNumber, BackColor );
				StaticVarSet("RotateInit"+ ColName + RowNumber, True);
        }
    }
    Label 	= kStaticVarGetText( "Label" + ColName + RowNumber);
    return Label;
}

Referring to the above code you’ll see the usual ColExpanded variable that determines whether this button will be displayed. A RotateInit var is used to detect whether the button has been initialized, i.e., whether is was assigned colors and text. Each time the function is called the RotateIndex incremented. This index is used to extract the proper label and color from the csv encoded options in the string argument for the function.

The code below demonstrates how the ButtonRotate is used. Note that for brevity I used digits to indicate colors. You can also use constants like ColorRed, ColorBlue, etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <ControlPanelInclude-004.afl>
 
global ColNumber;
RequestTimedRefresh(1);
ButtonHeight			= Param("Button Height",20,5,200,1); 
ButtonWidth 			= Param("Button Width",120,5,200,1); 
PanelYoffset 			= Param("Button Row Offset (px)",10,0,Status("pxheight"),1); 
PanelXoffset			= Param("Button Column Offset (px)",10,0,Status("pxwidth"),1); 
FontRatio   			= Param("Font: ButtonHeight ratio",2,1,20,0.1);
DoubleClickInterval	= Param("Double Click Max. Interval",330,1,1000,1);
 
ButtonColumnBegin( "1" );
ButtonHeader( "HEADER", colorBlue, colorBlue,colorWhite);
ButtonText( "TRADING ENABLED", colorYellow, colorBlue);
 
Action=ButtonRotate( "BUY,SELL,SHORT,COVER,CASH,REVERSE", "6,5,1,3,2,4", "2,3,4,5,6,1" );
Transmit = ButtonTrigger( "TRANSMIT", colorBrightGreen, colorRed, colorBlack);
ButtonColumnEnd( );
 
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch( ClickCoordinates )
	{
	case 101:
	// Perform Button task 101 here
	break;
	case 102:
	// Perform Button task 102 here
	break;
	// etc.
	}
 
Plot(C,"",1,128);
 
Title = "\n"+
"Button Coordinates: "+ClickCoordinates+"\n"+
"Action: "+Action+"\n"+
"Transmit: "+Transmit;

As always, here follows the revised Include file with the ButtonRotate() included.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// ControlPanelInclude-004.afl
procedure kStaticVarSet( SName, SValue ) 		
	{
	ChartID = GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSet(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGet( SName ) 					
	{ 
	ChartID 	= GetChartID();
	Var = StaticVarGet(Sname+ChartID);
	return Var;
	}
 
procedure kStaticVarSetText( SName, SValue ) 	
	{ 
	ChartID 	= GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSetText(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGetText( SName ) 				
	{ 
	ChartID = GetChartID();
	return StaticVarGetText(Sname+ChartID); 
	}
 
function NewColumn()
	{
	VarSet("ColNumber", 0);
	}
 
function GetButtonClick( ColNumber, RowNumber )
	{
	global PanelYoffset, PanelXoffset, ButtonHeight, ButtonWidth;
	LButtonDown = GetCursorMouseButtons() == 9;
	Click = False;
	if( LButtonDown )
		{
		ULButtonX 	= PanelXoffset + (ColNumber-1) * ButtonWidth;
		LRButtonX	= ULButtonX + ButtonWidth;
		ULButtonY 	= (RowNumber -1) * ButtonHeight + PanelYoffset;
		LRButtonY	= ULButtonY + ButtonHeight;
		MouseCoord 	= Nz(StaticVarGet("ClickCoordinates"));
		if( MouseCoord == 0 AND LButtonDown )
			{
			MousePx = GetCursorXPosition( 1 );
			MousePy = GetCursorYPosition( 1 );
			if( MousePx > ULButtonX AND MousePx < LRButtonX AND MousePy > ULButtonY AND MousePy < LRButtonY )
				{
				StaticVarSet("ClickCoordinates",ColNumber*100+RowNumber);
				Click = 1;
				}
			}
		}
	return Click;
	}
 
function ButtonColumnBegin( ColName ) 
	{
	global FontRatio, ColName, ColNumber, ButtonHeight, ButtonWidth, PanelXoffset, PanelYoffset, Colname;
	ColNumber = VarGet("ColNumber");
	if( IsEmpty( ColNumber ) ) 
		{
		VarSet("ColNumber",1);
		StaticVarSet("ClickCoordinates",0);
		}
	else VarSet("ColNumber", ++ColNumber);
	ColName = ColName+GetChartID();
	kStaticVarSet("RowNumber"+ColName, 0);
	VarSetText("ColName",ColName);
	GfxSetOverlayMode( 0 );
	GfxSelectFont( "Tahoma", ButtonHeight/FontRatio, 800 ); 
	GfxSelectPen( colorBlack ); 
	GfxSetBkMode( 1 );
	}
 
function ButtonHeader( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColExpanded, Colname;
	RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
	kStaticVarSet("RowNumber"+ColName, RowNumber);
	SingleClick = GetButtonClick( ColNumber, RowNumber );
	BackColor = backColor1;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( SingleClick ) 
		{
		BackColor = backColor2; 
		ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
		if( ColExpanded ) kStaticVarSet(ColName+"ColExpanded", False);
		else kStaticVarSet(ColName+"ColExpanded", True);
		}
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	kStaticVarSetText("Label"+ColName+RowNumber, Label);
	kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
	kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
	}
 
function ButtonText( Label, backColor, TextColor)
	{
	global ColNumber, RowNumber, Colname;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( ColExpanded )
		{
		ColName = VarGetText("ColName");
		RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
		kStaticVarSet("RowNumber"+ColName, RowNumber);
		kStaticVarSetText("Label"+ColName+RowNumber, Label);
		kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
		kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
		}
	}
 
function ButtonTrigger( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColName;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( ColExpanded )
		{
		ColName = VarGetText("ColName");
		RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
		kStaticVarSet("RowNumber"+ColName, RowNumber);
		Trigger = GetButtonClick( ColNumber, RowNumber );
		if( Trigger ) BackColor = backColor2; else BackColor = backColor1;
		kStaticVarSetText("Label"+ColName+RowNumber, Label);
		kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
		kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
		}
	else Trigger = 0;
	return Trigger;
	}
 
function ButtonRotate( LabelStr, BackColorStr, TextColorStr )
{
    global ColNumber, RowNumber, ColName, ColExpanded;
 
    if ( ColExpanded )
    {
        ColName = VarGetText( "ColName" );
        RowNumber = Nz( kStaticVarGet( "RowNumber" + ColName ) ) + 1;
        kStaticVarSet( "RowNumber" + ColName, RowNumber );
        Rotate = GetButtonClick( ColNumber, RowNumber );
        if ( Rotate OR IsNull( StaticVarGet("RotateInit"+ ColName + RowNumber ) ) )
        {
            RotateIndex = Nz( kStaticVarGet( "RotateIndex" + ColName + RowNumber ) );
            if ( StrExtract( LabelStr, RotateIndex + 1) != "" ) RotateIndex++;
            else RotateIndex = 0;
            kStaticVarSet( "RotateIndex" + ColName + RowNumber, RotateIndex );
 
            Label = StrExtract( LabelStr, RotateIndex );
 
            if ( StrExtract( BackColorStr, RotateIndex ) == "" ) BackColor = StrToNum( StrExtract( BackColorStr, 0 ) );
            else BackColor = StrToNum( StrExtract( BackColorStr, RotateIndex ) );
 
            if ( StrExtract( TextColorStr, RotateIndex ) == "" ) TextColor = StrToNum( StrExtract( TextColorStr, 0 ) );
            else TextColor = 	StrToNum( StrExtract( TextColorStr, RotateIndex ) );
 
            kStaticVarSetText( "Label" + ColName + RowNumber, Label );
            kStaticVarSet( "TextColor" + ColName + RowNumber, TextColor );
            kStaticVarSet( "BackColor" + ColName + RowNumber, BackColor );
				StaticVarSet("RotateInit"+ ColName + RowNumber, True);
        }
    }
    Label 	= kStaticVarGetText( "Label" + ColName + RowNumber);
    return Label;
}
 
 
function ButtonColumnEnd()
	{
	global ButtonHeight, ButtonWidth, PanelYoffset, PanelXoffset, ColNumber, RowNumber, ColName;
	ChartIDStr 	= NumToStr(GetChartID(),1.0,False);
	ULButtonX 		= PanelXoffset + (ColNumber-1) * ButtonWidth;
	LRButtonX		= ULButtonX + ButtonWidth;
	for( Row = 1; Row <= RowNumber; Row++ ) 
		{
		ULButtonY 		= (Row-1) * ButtonHeight + PanelYoffset;
		LRButtonY		= ULButtonY + ButtonHeight;
		Label 	= kStaticVarGetText("Label"+ColName+Row);
		TextColor 	= Nz(kStaticVarGet("TextColor"+ColName+Row));
		BackColor 	= Nz(kStaticVarGet("BackColor"+ColName+Row));
		GfxSelectSolidBrush( BackColor);
		GfxRectangle( ULButtonX, ULButtonY, LRButtonX, LRButtonY ); 
		GfxSetBkColor( BackColor);
		GfxSetTextColor( TextColor );
		GfxDrawText( Label, ULButtonX, ULButtonY, LRButtonX, LRButtonY, 32 | 1 | 4);
		}
	}
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading ... Loading ...

Button Header (Collapse/Expand)

Note: A number of variables and function names were changed to provide more consistent naming; please upgrade your code and Include file. I regret that such changes may happen rather often, however, the only alternative would be to complete all posts for this topic and publish them all at once. Since there is no guarantee that all code will ever be fully completed (most of my development work never stops), I think it is better to publish whatever is functional, as if this were a development blog.

The purpose of the Button Header is to name button columns (this is needed to key static variables) and provide a Collapse/Expand function for Button Columns. Clicking on a Button Header will alternatively Collapse and Expand button columns. This allows you to quickly expose chart sections that were hidden by the Control Panel. A collapsed Button Column will look like this:

clip_image002

Clicking on the Header Button will expand the column to look as show below:

clip_image002[5]

A few variables are displayed in the Title to facilitate debugging. The following listing shows the test code used to display the above Button Column. Note again that there are two ways to process button clicks: using the values returned by the button functions, or using the Switch() statement.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <ControlPanelInclude-003.afl>
 
global ColNumber;
RequestTimedRefresh(1);
ButtonHeight = Param("Button Height",20,5,200,1); 
ButtonWidth = Param("Button Width",120,5,200,1); 
PanelYoffset = Param("Button Row Offset (px)",10,0,Status("pxheight"),1); 
PanelXoffset = Param("Button Column Offset (px)",10,0,Status("pxwidth"),1); 
FontRatio = Param("Font: ButtonHeight ratio",2,1,20,0.1);
 
ButtonColumnBegin( "1" );
ButtonHeader( "COLUMN HEADER1", colorBlue, colorLightBlue,colorWhite);
ButtonText( "AUTO-TRADING ON", colorBlue, colorWhite);
Reset = ButtonTrigger( "START SESSION", colorBrightGreen, colorRed, colorBlack);
CancelAll = ButtonTrigger( "CANCEL ALL", colorBrightGreen, colorRed, colorBlack);
CloseAll = ButtonTrigger( "CLOSE ALL", colorBrightGreen, colorRed, colorBlack);
EndSession = ButtonTrigger( "END SESSION", colorBrightGreen, colorRed, colorBlack);
ButtonColumnEnd( );
 
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch( ClickCoordinates )
	{
	case 101:
	Say( "1 1");
	break;
	case 102:
	Say( "1 2");
	break;
	case 103:
	Say( "1 3");
	break;
	case 104:
	Say( "1 4");
	break;
	case 105:
	Say( "1 5");
	break;
	case 106:
	Say( "1 6");
	break;
	}
 
Plot(C,"",1,128);
 
Title = "\n"+
"  Click Coordinates: "+ClickCoordinates+"\n"+
"Column Expanded Var: "+Nz(kStaticVarGet(ColName+"ColExpanded"));

The ButtonHeader() is similar to the ButtonText() function but has a Collapse/Expand variable added. Here is the code for the new ButtonHeader() function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function ButtonHeader( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColExpanded, Colname;
	RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
	kStaticVarSet("RowNumber"+ColName, RowNumber);
	Trigger = GetMouseClick( ColNumber, RowNumber );
	if( Trigger ) 
		{
		BackColor = backColor2; 
		ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
		if( ColExpanded ) kStaticVarSet(ColName+"ColExpanded", False);
		else kStaticVarSet(ColName+"ColExpanded", True);
		}
	else BackColor = backColor1;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
	kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
	kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
	}

In the above code, when the left Mouse button is clicked, a static variable named ColExpanded is toggled between True and False. All earlier button functions have been modified to only execute their internal code only if this variable is True. This way Buttons will only display if the variable ColExpanded it True. The listing below shows how the TriggerButton() was modified. This and the HeaderButton functions are located in the Include file at the end of this post; there is no need to copy them separately.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function ButtonTrigger( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColName;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( ColExpanded )
		{
		ColName = VarGetText("ColName");
		RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
		kStaticVarSet("RowNumber"+ColName, RowNumber);
		Trigger = GetMouseClick( ColNumber, RowNumber );
		if( Trigger ) BackColor = backColor2; else BackColor = backColor1;
		kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
		kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
		kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
		}
	else Trigger = 0;
	return Trigger;
	}

The new ControlPanelInclude-003.afl Include file is listed below, it must be copied to your default Include folder for the above code to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ControlPanelInclude-003.afl
procedure kStaticVarSet( SName, SValue ) 		
	{
	ChartID = GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSet(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGet( SName ) 					
	{ 
	ChartID 	= GetChartID();
	Var = StaticVarGet(Sname+ChartID);
	return Var;
	}
 
procedure kStaticVarSetText( SName, SValue ) 	
	{ 
	ChartID 	= GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSetText(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGetText( SName ) 				
	{ 
	ChartID = GetChartID();
	return StaticVarGetText(Sname+ChartID); 
	}
 
function NewColumn()
	{
	VarSet("ColNumber", 0);
	}
 
function GetMouseClick( ColNumber, RowNumber )
	{
	global PanelYoffset, PanelXoffset, ButtonHeight, ButtonWidth;
	LButtonDown = GetCursorMouseButtons() == 9;
	Click = 0;
	if( LButtonDown )
		{
		ULButtonX 		= PanelXoffset + (ColNumber-1) * ButtonWidth;
		LRButtonX		= ULButtonX + ButtonWidth;
		ULButtonY 		= (RowNumber -1) * ButtonHeight + PanelYoffset;
		LRButtonY		= ULButtonY + ButtonHeight;
		MouseCoord = Nz(StaticVarGet("ClickCoordinates"));
		if( MouseCoord == 0 AND LButtonDown )
			{
			MousePx = GetCursorXPosition( 1 );
			MousePy = GetCursorYPosition( 1 );
			if( MousePx > ULButtonX AND MousePx < LRButtonX AND MousePy > ULButtonY AND MousePy < LRButtonY )
				{
				StaticVarSet("ClickCoordinates",ColNumber*100+RowNumber);
				Click = 1;
				}
			}
		}
	return Click;
	}
 
function ButtonColumnBegin( ColName ) 
	{
	global FontRatio, ColName, ColNumber, ButtonHeight, ButtonWidth, PanelXoffset, PanelYoffset, Colname;
	ColNumber = VarGet("ColNumber");
	if( IsEmpty( ColNumber ) ) 
		{
		VarSet("ColNumber",1);
		StaticVarSet("ClickCoordinates",0);
		}
	else VarSet("ColNumber", ++ColNumber);
	ColName = ColName+GetChartID();
	kStaticVarSet("RowNumber"+ColName, 0);
	VarSetText("ColName",ColName);
	GfxSetOverlayMode( 0 );
	GfxSelectFont( "Tahoma", ButtonHeight/FontRatio, 800 ); 
	GfxSelectPen( colorBlack ); 
	GfxSetBkMode( 1 );
	}
 
function ButtonText( TextButton, backColor, TextColor)
	{
	global ColNumber, RowNumber, Colname;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( ColExpanded )
		{
		ColName = VarGetText("ColName");
		RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
		kStaticVarSet("RowNumber"+ColName, RowNumber);
		kStaticVarSetText("TextButton"+ColName+RowNumber, TextButton);
		kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
		kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
		}
	}
 
function ButtonTrigger( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColName;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	if( ColExpanded )
		{
		ColName = VarGetText("ColName");
		RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
		kStaticVarSet("RowNumber"+ColName, RowNumber);
		Trigger = GetMouseClick( ColNumber, RowNumber );
		if( Trigger ) BackColor = backColor2; else BackColor = backColor1;
		kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
		kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
		kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
		}
	else Trigger = 0;
	return Trigger;
	}
 
function ButtonHeader( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber, ColExpanded, Colname;
	RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
	kStaticVarSet("RowNumber"+ColName, RowNumber);
	Trigger = GetMouseClick( ColNumber, RowNumber );
	if( Trigger ) 
		{
		BackColor = backColor2; 
		ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
		if( ColExpanded ) kStaticVarSet(ColName+"ColExpanded", False);
		else kStaticVarSet(ColName+"ColExpanded", True);
		}
	else BackColor = backColor1;
	ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
	kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
	kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
	kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
	}
 
function ButtonColumnEnd()
	{
	global ButtonHeight, ButtonWidth, PanelYoffset, PanelXoffset, ColNumber, RowNumber, ColName;
	ChartIDStr 	= NumToStr(GetChartID(),1.0,False);
	ULButtonX 		= PanelXoffset + (ColNumber-1) * ButtonWidth;
	LRButtonX		= ULButtonX + ButtonWidth;
	for( Row = 1; Row <= RowNumber; Row++ ) 
		{
		ULButtonY 		= (Row-1) * ButtonHeight + PanelYoffset;
		LRButtonY		= ULButtonY + ButtonHeight;
		Label 	= kStaticVarGetText("TextButton"+ColName+Row);
		TextColor 	= Nz(kStaticVarGet("TextColor"+ColName+Row));
		BackColor 	= Nz(kStaticVarGet("BackColor"+ColName+Row));
		GfxSelectSolidBrush( BackColor);
		GfxRectangle( ULButtonX, ULButtonY, LRButtonX, LRButtonY ); 
		GfxSetBkColor( BackColor);
		GfxSetTextColor( TextColor );
		GfxDrawText( Label, ULButtonX, ULButtonY, LRButtonX, LRButtonY, 32 | 1 | 4);
		}
	}
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...

Command Buttons (Trigger type)

This series of posts is actually written while the functions are being developed. It is for this reason that the functions and Include file may change with each next post. Hopefully they will be better with each revision. Please always use the latest versions.

There have been many requests for on-chart custom Command Buttons. Command Buttons are mouse-click sensitive buttons or menu-items that, when clicked on, will execute a specific section of AFL code. This post introduces Command Buttons of the Trigger-type that respond to Left-Button clicks. This Trigger Button can be used in the same way you would use the ParamTrigger() function. Note that the first button does not respond to mouse-clicks; it is not a trigger button. The TextCell was designed to display text only, for example to display status information for your trading system. Here is an example of a simple horizontal layout:

triggerbuttons.png

To display the buttons horizontally lengthens the code a little because the code is optimized for vertical button columns. Here is the code that places the above button array on your chart:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <ControlPanelInclude-001.afl>
 
global ColNumber;
RequestTimedRefresh(1);
CellHeight = Param("Cell Height",20,5,200,1); 
CellWidth = Param("Cell Width",120,5,200,1); 
PanelYoffset = Param("Cell Row Offset (px)",10,0,Status("pxheight"),1); 
PanelXoffset = Param("Cell Column Offset (px)",10,0,Status("pxwidth"),1); 
FontRatio = Param("Font: CellHeight ratio",2,1,20,0.1);
 
Column_Begin( "1" );
TextCell( "AUTO-TRADING", colorRed, colorBlack);
Column_End( );
 
Column_Begin( "2" );
Reset = TriggerCell( "START SESSION", colorBrightGreen, colorRed, colorBlack);
Column_End( );
 
Column_Begin( "3" );
CancelAll = TriggerCell( "CANCEL ALL", colorBrightGreen, colorRed, colorBlack);
Column_End( );
 
Column_Begin( "4" );
CloseAll = TriggerCell( "CLOSE ALL", colorBrightGreen, colorRed, colorBlack);
Column_End( );
 
Column_Begin( "5");
EndSession = TriggerCell( "END SESSION", colorBrightGreen, colorRed, colorBlack);
Column_End( );
 
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch( ClickCoordinates )
	{
	case 201:
	Say( "201");
	break;
	case 301:
	Say( "301");
	break;
	case 401:
	Say( "401");
	break;
	case 501:
	Say( "501");
	break;
	}
 
Plot(C,"",1,128);
 
Title = "CLICK COORDINATES: "+ClickCoordinates;

The Trigger function returns a trigger, i.e., a True state that lasts only for the current refresh and that returns False at the next pass through the code. A Triggername is assigned to each button and is used to key the static variables. Backcolor1 is the normal color of the button. Backcolor2 is the color the button takes on when it is clicked on; this gives a visual confirmation that the click was registered. If a button is clicked on, the button coordinates (vertical position, horizontal position) are returned in compressed for as ColNumber*100+RowNumber.

Trigger action can be invoked in two ways: by checking the value returned by the trigger functions, and by processing the click-coordinates in a Switch() statement. Each method may have advantages depending on the application.

Below a listing of the revised Include file, please copy to your default include folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// ControlPanelInclude-001.afl
procedure kStaticVarSet( SName, SValue ) 		
	{
	ChartID = GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSet(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGet( SName ) 					
	{ 
	ChartID 	= GetChartID();
	Var = StaticVarGet(Sname+ChartID);
	return Var;
	}
 
procedure kStaticVarSetText( SName, SValue ) 	
	{ 
	ChartID 	= GetChartID();
	InIndicator = Status("Action") == 1;
	if( InIndicator ) StaticVarSetText(Sname+ChartID, Svalue); 
	}
 
function kStaticVarGetText( SName ) 				
	{ 
	ChartID = GetChartID();
	return StaticVarGetText(Sname+ChartID); 
	}
 
function Column_Begin( ColName ) 
	{
	global FontRatio, ColName, ColNumber, CellHeight, CellWidth, PanelXoffset, PanelYoffset;
	ColNumber = VarGet("ColNumber");
	if( IsEmpty( ColNumber ) ) 
		{
		VarSet("ColNumber",1);
		StaticVarSet("ClickCoordinates",0);
		}
	else VarSet("ColNumber", ++ColNumber);
	ColName = ColName+GetChartID();
	GfxSetOverlayMode( 0 );
	GfxSelectFont( "Tahoma", CellHeight/FontRatio, 800 ); 
	GfxSelectPen( colorBlack ); 
	GfxSetBkMode( 1 );
	kStaticVarSet("RowNumber"+ColName, 0);
	VarSetText("ColName",ColName);
	return ColNumber;
	}
 
function Column_End( )
	{
	global CellHeight, CellWidth, PanelYoffset, PanelXoffset, ColNumber, RowNumber;
	ChartIDStr 	= NumToStr(GetChartID(),1.0,False);
	ColName 		= VarGetText("ColName");
	ULCellX 		= PanelXoffset + (ColNumber-1) * CellWidth;
	LRCellX		= ULCellX + CellWidth;
	for( Row = 1; Row <= RowNumber; Row++ ) 
		{
		ULCellY 		= (Row-1) * CellHeight + PanelYoffset;
		LRCellY		= ULCellY + CellHeight;
		TextCell 	= kStaticVarGetText("TextCell"+ColName+Row);
		TextColor 	= Nz(kStaticVarGet("TextColor"+ColName+Row));
		BackColor 	= Nz(kStaticVarGet("BackColor"+ColName+Row));
		GfxSelectSolidBrush( BackColor);
		GfxRectangle( ULCellX, ULCellY, LRCellX, LRCellY ); 
		GfxSetBkColor( BackColor);
		GfxSetTextColor( TextColor );
		GfxDrawText( TextCell, ULCellX, ULCellY, LRCellX, LRCellY, 32 | 1 | 4);
		}
	}
 
function TextCell( TextCell, backColor, TextColor)
	{
	global ColNumber, RowNumber;;
	ColName = VarGetText("ColName");
	RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
	kStaticVarSet("RowNumber"+ColName, RowNumber);
	kStaticVarSetText("TextCell"+ColName+RowNumber, TextCell);
	kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
	kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
	}
 
function NewColumn()
	{
	VarSet("ColNumber", 0);
	}
 
function CheckMouseClick( ColNumber, RowNumber )
	{
	global PanelYoffset, PanelXoffset, CellHeight, CellWidth;
	LButtonDown = GetCursorMouseButtons() == 9;
	Click = 0;
	if( LButtonDown )
		{
		ULCellX 		= PanelXoffset + (ColNumber-1) * CellWidth;
		LRCellX		= ULCellX + CellWidth;
		ULCellY 		= (RowNumber -1) * CellHeight + PanelYoffset;
		LRCellY		= ULCellY + CellHeight;
		MouseCoord = Nz(StaticVarGet("ClickCoordinates"));
		if( MouseCoord == 0 AND LButtonDown )
			{
			MousePx = GetCursorXPosition( 1 );
			MousePy = GetCursorYPosition( 1 );
			if( MousePx > ULCellX AND MousePx < LRCellX AND MousePy > ULCellY AND MousePy < LRCellY )
				{
				StaticVarSet("ClickCoordinates",ColNumber*100+RowNumber);
				Click = 1;
				}
			}
		}
	return Click;
	}
 
function TriggerCell( Label, backColor1, BackColor2, TextColor)
	{
	global ColNumber, RowNumber;;
	ColName = VarGetText("ColName");
	RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
	kStaticVarSet("RowNumber"+ColName, RowNumber);
	Trigger = CheckMouseClick( ColNumber, RowNumber );
	if( Trigger ) BackColor = backColor2; else BackColor = backColor1;
	kStaticVarSetText("TextCell"+ColName+RowNumber, Label);
	kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
	kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
	return Trigger;
	}
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading ... Loading ...

A Basic Messaging Panel

Also see Moving Low Level Graphics (GFX) Objects on your Charts

This first post introduces you to the basic techniques on how to create a matrix of text cells to display messages and system status on your chart. At this stage the cells are not mouse-click sensitive; this and other features will be added later. In this example the number of columns, rows, the font size, and the location of the message panel, can be set from the Param window. In your final application you might want to make these parameters constant and remove the corresponding Param statements. You can combine any number of Panels, here is an example for multiple panels layouts:

image

The following simple panel is produced by the code in this post.

image

The code below will place the above Message panel on your chart. A code description follows below listing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
#include <MessagePanelInclude.afl>
 
global ColNumber;
 
CellHeight = Param("Cell Height",20,5,200,5);
 
CellWidth = Param("Cell Width",120,5,200,5);
 
PanelYoffset = Param("Cell Row Offset (px)",10,0,Status("pxheight"),5);
 
PanelXoffset = Param("Cell Column Offset (px)",10,0,Status("pxwidth"),5);
 
FontRatio = Param("Font:CellHeight ratio",2,1,20,0.1);
 
MsgCol_Begin( "COLUMNNAME 1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
 
TextCell( "Text Message 1", BackgroundColor=1, TextColor=2);
 
TextCell( "Text Message 2", 2, 3);
 
TextCell( "Text Message 3", 8, 4);
 
TextCell( "Text Message 4", 7, 5);
 
TextCell( "Text Message 5", 4, 6);
 
TextCell( "Text Message 6", 3, 7);
 
TextCell( "Text Message 7", 2, 8);
 
MsgCol_End();
 
MsgCol_Begin( " COLUMNNAME 2", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
 
TextCell( "Text Message 1", 9, 2);
 
TextCell( "Text Message 2", 8, 3);
 
TextCell( "Text Message 3", 7, 4);
 
TextCell( "Text Message 4", 6, 5);
 
TextCell( "Text Message 5", 5, 6);
 
TextCell( "Text Message 6", 4, 7);
 
TextCell( "Text Message 7", 3, 8);
 
MsgCol_End();

Message Panel code above calls the Include file listed at the end of this post. The The MsgCol_Begin() function defines the name and dimensions for the current column:

1
MsgCol_Begin( "COLUMNNAME 1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );

You can create many columns. The ColName is used in Static variables to allow the code to know to which Column the TextCells belong. The last four arguments are self-explanatory. The Overlay and background modes can be changed inside this function, or you can extract these GFX statements and execute them separately.

The TextCell() function adds one TextCell to the column. It defines the Message, Background color, and TextColor to be used:

1
2
 
TextCell( "Text Message 1", colorBlack, colorWhite);

The MsgCol_End() terminates the current column and draws the GFX pgraphics to the chart.

The Include file makes extensive use of static variables that are wrapped in kStaticVar…() to make the static variables unique to the current ChartID. This is needed to call the functions from different panes and windows without interfering with one another. For more on this see Keying Static Variables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 
// This is the Include file MessagePanelInclude.afl, copy to your default Include folder
 
procedure kStaticVarSet( SName, SValue )
 
{
 
ChartID = GetChartID();
 
InIndicator = Status("Action") == 1;
 
if( InIndicator ) StaticVarSet(Sname+ChartID, Svalue);
 
}
 
function kStaticVarGet( SName )
 
{
 
ChartID = GetChartID();
 
Var = StaticVarGet(Sname+ChartID);
 
return Var;
 
}
 
procedure kStaticVarSetText( SName, SValue )
 
{
 
ChartID = GetChartID();
 
InIndicator = Status("Action") == 1;
 
if( InIndicator ) StaticVarSetText(Sname+ChartID, Svalue);
 
}
 
function kStaticVarGetText( SName )
 
{
 
ChartID = GetChartID();
 
return StaticVarGetText(Sname+ChartID);
 
}
 
function MsgCol_Begin( ColName, CellHeight, CellWidth, PanelXoffset, PanelYoffset )
 
{
 
global FontRatio, ColName, ColNumber;
 
ColNumber = VarGet("ColNumber");
 
if( IsEmpty( ColNumber ) ) VarSet("ColNumber",1);
 
else VarSet("ColNumber", ++ColNumber);
 
ColName = ColName+GetChartID();
 
GfxSetOverlayMode( 0 );
 
GfxSelectFont( "Tahoma", CellHeight/FontRatio, 800 );
 
GfxSelectPen( colorBlack );
 
GfxSetBkMode( 1 );
 
kStaticVarSet("PanelItemNum"+ColName, 0);
 
VarSetText("ColName",ColName);
 
return ColNumber;
 
}
 
function MsgCol_End( )
 
{
 
global CellHeight, CellWidth, PanelYoffset, PanelXoffset, ColNumber, PanelItemNum;
 
ChartIDStr = NumToStr(GetChartID(),1.0,False);
 
ColName = VarGetText("ColName");
 
ULCellX = PanelXoffset + (ColNumber-1) * CellWidth;
 
LRCellX = ULCellX + CellWidth;
 
for( Row = 1; Row <= PanelItemNum; Row++ )
 
{
 
ULCellY = (Row-1) * CellHeight + PanelYoffset;
 
LRCellY = ULCellY + CellHeight;
 
TextCell = kStaticVarGetText("TextCell"+ColName+Row);
 
TextColor = Nz(kStaticVarGet("TextColor"+ColName+Row));
 
BackColor = Nz(kStaticVarGet("BackColor"+ColName+Row));
 
if( Row==1) TextCell = StrReplace( TextCell, ChartIDStr, "");
 
GfxSelectSolidBrush( BackColor);
 
GfxRectangle( ULCellX, ULCellY, LRCellX, LRCellY );
 
GfxSetBkColor( BackColor);
 
GfxSetTextColor( TextColor );
 
GfxDrawText( TextCell, ULCellX, ULCellY, LRCellX, LRCellY, 32 | 1 | 4);
 
}
 
}
 
function TextCell( TextCell, backColor, TextColor)
 
{
 
global InitializePanels, PanelVisible;
 
ColName = VarGetText("ColName");
 
PanelItemNum = Nz(kStaticVarGet("PanelItemNum"+ColName))+1;
 
kStaticVarSet("PanelItemNum"+ColName, PanelItemNum);
 
kStaticVarSet("CellState"+ColName+PanelItemNum, False);
 
Label = StrExtract(TextCell,0);
 
kStaticVarSetText("TextCell"+ColName+PanelItemNum, Label);
 
kStaticVarSet("TextColor"+ColName+PanelItemNum, TextColor);
 
kStaticVarSet("BackColor"+ColName+PanelItemNum, backColor);
 
}
 
function Newpanel()
 
{
 
VarSet("ColNumber", 0);
 
}

For those who want to experiment with multi-panel layouts here is the code used to produce the xample shown earlier:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include
 
global ColNumber;
_SECTION_BEGIN("MESSAGE PANEL 1");
CellHeight				= Param("Cell Height",20,5,200,1);
CellWidth 				= Param("Cell Width",120,5,200,1);
PanelYoffset 			= Param("Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset			= Param("Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio   			= Param("Font:CellHeight ratio",2,1,20,0.1);
 
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "PANEL 1", colorBlack, colorWhite);
TextCell( "Text Message 2", 2, 3);
TextCell( "Text Message 3", 8, 4);
TextCell( "Text Message 4", 7, 5);
TextCell( "Text Message 5", 4, 6);
TextCell( "Text Message 6", 3, 7);
TextCell( "Text Message 7", 2, 8);
TextCell( "Text Message 8", 9, 2);
TextCell( "Text Message 9", 8, 3);
TextCell( "Text Message 10", 7, 4);
TextCell( "Text Message 11", 6, 5);
TextCell( "Text Message 12", 5, 6);
TextCell( "Text Message 13", 4, 7);
TextCell( "Text Message 14", 3, 8);
MsgCol_End();
_SECTION_END();
 
_SECTION_BEGIN("MESSAGE PANEL 2");
CellHeight				= Param("2Cell Height",20,5,200,1);
CellWidth 				= Param("2Cell Width",120,5,200,1);
PanelYoffset 			= Param("2Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset			= Param("2Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio   			= Param("2Font:CellHeight ratio",2,1,20,0.1);
 
Newpanel();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "PANEL 2", 1, colorWhite);
MsgCol_End();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message B", 2, 1);
MsgCol_End();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message C", 4, colorWhite);
MsgCol_End();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message D", 5, colorWhite);
MsgCol_End();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message E", 4, colorWhite);
MsgCol_End();
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message F", 5, colorWhite);
MsgCol_End();
_SECTION_END();
 
_SECTION_BEGIN("MESSAGE PANEL 3");
Newpanel();
CellHeight				= Param("1Cell Height",20,5,200,1);
CellWidth 				= Param("1Cell Width",120,5,200,1);
PanelYoffset 			= Param("1Cell Row Offset (px)",10,0,Status("pxheight"),1);
PanelXoffset			= Param("1Cell Column Offset (px)",10,0,Status("pxwidth"),1);
FontRatio   			= Param("1Font:CellHeight ratio",2,1,20,0.1);
 
MsgCol_Begin( "COLUMNNAME  1", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "PANEL 3", colorBlack, colorWhite);
TextCell( "Text Message 22", 2, 3);
TextCell( "Text Message 23", 8, 4);
TextCell( "Text Message 24", 7, 5);
TextCell( "Text Message 25", 4, 6);
TextCell( "Text Message 26", 3, 7);
TextCell( "Text Message 27", 2, 8);
MsgCol_End();
 
MsgCol_Begin( "COLUMNNAME  2", CellHeight, CellWidth, PanelXoffset, PanelYoffset );
TextCell( "Text Message 28", 9, 2);
TextCell( "Text Message 29", 8, 3);
TextCell( "Text Message 30", 7, 4);
TextCell( "Text Message 31", 6, 5);
TextCell( "Text Message 32", 5, 6);
TextCell( "Text Message 33", 4, 7);
TextCell( "Text Message 34", 3, 8);
MsgCol_End();
_SECTION_END();
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)
Loading ... Loading ...

Introduction to Real-Time Control-Panels

IMPORTANT NOTES:

1) Posts in this category are published as code is developed and you should use the most recent version posted. This code is shared without extensive field testing and may contain errors or function different than you expect. Always verify that the code does what you want it to do before using it in a real application. This publishing method is used to give you a chance to use it at the current stage of development, else you would have to wait until all functions are completed – and that time might never come :-)

2) All code on the UKB takes advantage of the latest AFL functions. If you encounter problems, and before posting questions, please verify that you are running the latest AmiBroker beta software. New releases are usually announced in the AmiBroker Development Log. The code you find here is modified too frequently to add/maintain version() statements to/in all programs published.

3) The code covered in this series of posts make extensive use of GFX functions please read the posts in the GFX Programming category.

==========

In Real-Time trading it is handy to use "Control Panels". Control Panels are custom button layouts that can be used to change system settings, and give Real-Time visual feedback on the state of the system. Clicking any of the buttons lets you execute specific code with a single mouse click. While the AmiBroker Parameter window is very useful for use with Indicators it lacks important features needed in Real-Time. Posts in this category will cover the development of a custom menu system for use in Real-Time applications. It will offer: relocatable and collapsible menus, dynamic coloring, multi-state toggles, dynamic labels, sizable buttons and fonts, status indicators, unlimited menu columns, etc. Of course you can conceive and add your own special functions. The main code can be placed in an Include file and menus and buttons can be added to your code with statements somewhat similar to the AmiBroker Param(). The code below generates the first column for the test menu shown in the image below the code.

1
2
3
4
5
6
7
Menu_Begin( "MENUS", ButtonHeight, ButtonWidth, MenuXoffset, MenuYoffset );       
MenuMinimized = MenuHeader( BLU, WHT);        
ExpandAll = MenuTrigger( "EXPAND ALL", ColorTrigger, ColorTriggerOn, BLK );        
SaveMenus = MenuTrigger( "SAVE", ColorTrigger, ColorTriggerOn, BLK );        
LoadMenus = MenuTrigger( "LOAD", ColorTrigger, ColorTriggerOn, BLK );        
MovingMenu = ButtonRotate( "MOVING,DRAG MENU", "4,1", "7,2");       
Menu_End();

A Rotate button changes state with each click. It can function as a ParamToggle() but can also be used to rotate through multiple states like Buy, Sell, Short, and Cover just by clicking the button multiple times. Each click can change the Button label and color. Here is a typical menu layout:

image

Menus can be collapsed by Double-Clicking on any of the Blue headers. This means you can uncover hidden chart sections instantly, without having to move the menu block. In its collapsed state the menu looks like this:

image

You can also collapse individual menus with a single click on the blue header, as shown below.

image

Posts in this series will progress through various prerequisites and building blocks to help you design your own menu layout.

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading ... Loading ...