MessageBox (Yes/Cancel)

 

HI,, I have an EA that works great..

I added a Button to Close all trades, but I want to add a messagebox that confirms the entry.. 

EG..  Are you sure  Yes/No/Cancel.


But I can get the message box to come up, but when I hit Cancel it still closes the open orders.


I have searched the documentation, but can't find any examples of how it should be coded.

Any help would be gratefully appreciated.



int MessageBox(
   string Confirmation,
   string Caption=MB_OKCANCEL,
   int    Flag=2
   );
   
   
// Describe this function...
double CalculationSize()
  {
   LotSize = AccountBalance() * 0.00001;
   return 0;
  }
string strTF(int period)
  {
   switch(period)
     {
       //--
       case PERIOD_M1: return("M1");
       case PERIOD_M5: return("M5");
       case PERIOD_M15: return("M15");
       case PERIOD_M30: return("M30");
       case PERIOD_H1: return("H1");
       case PERIOD_H4: return("H4");
       case PERIOD_D1: return("D1");
       case PERIOD_W1: return("W1");
       case PERIOD_MN1: return("MN");
       //--
     }
   return(_Period);
  }  

 void OnChartEvent(const int id,         // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
  )
  {
   if(id==CHARTEVENT_OBJECT_CLICK && sparam==name_closeall && TradesCount()>0 )
         {   
            MessageBox(Confirmation,"0",MB_OKCANCEL); 
            PlaySound("ok.wav"); 
            Print("Close All Button");
            CloseAllOpenPositions(MaxSlippage); 
            myOrderDelete();
            ObjectSetInteger(ChartID(),name_closeall,OBJPROP_STATE,0);
           
            
         } 
 

You have to analyze the return value of MessageBox function in order to know which button was clicked.

int result = MessageBox(Confirmation,"0",MB_OKCANCEL);

The return value is the code see:https://www.mql5.com/en/docs/constants/io_constants/messbconstants

 https://www.mql5.com/en/docs/common/messagebox

Documentation on MQL5: Common Functions / MessageBox
Documentation on MQL5: Common Functions / MessageBox
  • www.mql5.com
It creates and shows a message box and manages it. A message box contains a message and header, any combination of predefined signs and command buttons. The function is not recommended for use in custom indicators, as the call to the MessageBox() suspends the...
 
Marco vd Heijden:

You have to analyze the return value of MessageBox function in order to know which button was clicked.

The return value is the code see:https://www.mql5.com/en/docs/constants/io_constants/messbconstants

 https://www.mql5.com/en/docs/common/messagebox

HI Marco,


Thanks for your reply, but unfortunately i am still confused.

which section do I change to your coding.. i tried both, but am still getting errors.

should I be changing this coding to your code above or the second section?

int MessageBox(
   string Confirmation,
   string Caption="Close All",
   int    Flag=0
   );
   

2nd section:

 if(id==CHARTEVENT_OBJECT_CLICK && sparam==name_closeall && TradesCount()>0 )
         {   
            MessageBox("Confirmation","0",MB_OKCANCEL); 
            PlaySound("ok.wav"); 
            Print("Close All Button");
            CloseAllOpenPositions(MaxSlippage); 
            myOrderDelete();
            ObjectSetInteger(ChartID(),name_closeall,OBJPROP_STATE,0);
           
            
         } 

I tried this with both "Confirmation"

I still get the error "'MessageBox' - ambiguous call to overloaded function with the same parameters

without the "  "

i also get the error Confirmation - undeclared identifier



Thanks


 
int result = MessageBox("test");
if(result == IDOK)
{
Alert("OK button has been pressed");
}

if(result == IDCANCEL)
{
Alert("Cancel button has been pressed");
}

Please read the links i provided in my previous post.

 


Marco vd Heijden:

Please read the links i provided in my previous post.

Thanks..

Works great..