RAQ

How to use the MQL function MessageBox to Open a Trade

 

Q:

How do I open a messagebox with a question if I would like to open or cancel the trade before opening the trade ?

A:

The MQL function “MessageBox” is available in the VTS Toolbox and can be used for this.  It’s not as easy as it should be because I did not include the constant values needed for selection in the current version of VTS (4.0.0.78).  I’ll be sure to include the values in the next release of VTS so that they will be available for easy selection.  For now, I’ll provide the values here, and we just have to manually enter them when we configure the MQL function MessageBox.

First, we have the values used to determine what buttons are shown on the MessageBox.  This value is entered in the “flags” parameter of MessageBox.  Mostly we’ll want to use MB_OKCANCEL. This will display the familar OK and Cancel buttons on the message box.

Constant

Value

Description

MB_OK

0x00000000

Message window contains only one button: OK. Default

MB_OKCANCEL

0x00000001

Message window contains two buttons: OK and Cancel

MB_ABORTRETRYIGNORE

0x00000002

Message window contains three buttons: Abort, Retry and Ignore

MB_YESNOCANCEL

0x00000003

Message window contains three buttons: Yes, No and Cancel

MB_YESNO

0x00000004

Message window contains two buttons: Yes and No

MB_RETRYCANCEL

0x00000005

Message window contains two buttons: Retry and Cancel

MB_CANCELTRYCONTINUE

0x00000006

Message window contains three buttons: Cancel, Try Again, Continue

 Next, we need have the values that are returned from the MessageBox after the user clicks. We will want to check for this value in a VTS Logic element.
For this example, we’ll check for IDOK – this means the user clicked OK.

Constant

Value

Description

IDOK

1

“OK” button has been pressed

IDCANCEL

2

“Cancel” button has been pressed

IDABORT

3

“Abort” button has been pressed

IDRETRY

4

“Retry” button has been pressed

IDIGNORE

5

“Ignore” button has been pressed

IDYES

6

“Yes” button has been pressed

IDNO

7

“No” button has been pressed

IDTRYAGAIN

10

“Try Again” button has been pressed

IDCONTINUE

11

“Continue” button has been pressed

 

To start, get the MessageBox function from the VTS ToolBox:

Connect the MessageBox function to the True output of the Logic Element that checks for your trade signal. So if your trade signal is True, the MessageBox function will execute and display a message that allows you to choose OK or Cancel.  Then connect another Logic after the MessageBox function that checks the value of what was clicked. Connect the fnOpenTrade function to the True output so the trade is opened if you select OK.

This is how the MQL programming MessageBox function is configured:

 This is how the Logic that checks for the value of the MessageBox is configured:

So for now, you’ll have to manually enter the values MB_OK and MB_OKCANCEL, but in the next version of VTS, I’ll add the selection values to the pulldown menus to make it easier.  I’ll also make a short video showing how to build and run the EA.

 

To get notified about the latest questions and answers, follow us!