Return value button on mql4

 

Hello everyone, I need help how to return value of button into a number on mql4:

When press [1]B (green button), the mode will change from 0 to 1. 

here is the code:

//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                                               anney lu anney laa |
//+------------------------------------------------------------------+
#property copyright "anney"
#property  description "anney"

color font_color = White; //Red;
int font_size = 9;
string font_face = "Lucida Console";
int corner = 1; //0 - for top-left corner, 1 - top-right, 2 - bottom-left, 3 - bottom-right

int distance_y1 = 16;

bool normalize = true; //false; //If true then the spread is normalized to traditional pips
double Poin;
int n_digits = 2;
double divider = 1;

bool OnlyBuy = False;
bool OnlySell = False;

enum MyEnum
   {
    No, // 0
    Buy, // 1
    Sell, // 2
    Hedge  // 3
   };
input MyEnum mode = No;

double eL=1;
int P=0;
bool   Journaling=true; // Journaling

//button
int Corner = 0;
int Move_X = 0;
int Move_Y = 0;

int Button_Width = 100;
string Font_Type = "Arial Bold";
int Font_Size = 10;
color Font_Color = White;
//button

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

int init()
  {
  
   ObjectCreate("Mode", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Mode", OBJPROP_CORNER, corner);
   ObjectSet("Mode", OBJPROP_XDISTANCE, 20);
   ObjectSet("Mode", OBJPROP_YDISTANCE, distance_y1);     
   
   if ((Poin > Point) && (normalize))
   {
      divider = 10.0;
      n_digits = 2;
   }   
   //stats end init 
//----
  
   if(Digits==5 || Digits==3 || Digits==1)P=10;else P=1;
  
 //button  
   CreateButtons();
   
   ToolTips_Text ("Buy_btn");
   
   return(INIT_SUCCEEDED);
 //button

   return (0);

  }

void OnDeinit(const int reason)
  {
   DeleteButtons();

   ObjectDelete("Mode");
  }

void OnChartEvent (const int id, const long &lparam, const double &dparam, const string &sparam)
    {
     ResetLastError();
     if (id == CHARTEVENT_OBJECT_CLICK) {if (ObjectType (sparam) == OBJ_BUTTON) {ButtonPressed (0, sparam);}}
    }
    
void CreateButtons()
    {
     int Button_Height = Font_Size*2.8;
     if (!ButtonCreate (0, "Buy_btn", 0, 010 + 000 + Move_X, 020 + 010 + Move_Y, Button_Width + 025, Button_Height, Corner, "[1]B", Font_Type, Font_Size, Black, Lime, Black)) return;
          
     ChartRedraw();
    }

void DeleteButtons()
    {
     ButtonDelete (0, "Buy_btn");     
    }

void ButtonPressed (const long chartID, const string sparam)
    {
    
     if (sparam == "Buy_btn") Buy_Button (sparam);     
     Sleep (10);
    }
    
void ToolTips_Text(const string sparam)
  {
  
   if (sparam == "Buy_btn") {ObjectSetString (0, sparam, OBJPROP_TOOLTIP, "BUY Orders");}   
  }

//+-------------------------------------------------------------+


int Buy_Button (const string sparam)
  {   
   mode == 1;
   return(0);
  }


bool ButtonCreate (const long chart_ID=0, const string name="Button", const int sub_window=0, const int x=0, const int y=0, const int width=500,
                   const int height=18, int corner=0, const string text="Button", const string font="Arial Bold",
                   const int font_size=10, const color clr=clrBlack, const color back_clr=C'170,170,170', const color border_clr=clrNONE,
                   const bool state=false, const bool back=false, const bool selection=false, const bool hidden=true, const long z_order=0)
  {
   ResetLastError();
   if (!ObjectCreate (chart_ID,name, OBJ_BUTTON, sub_window, 0, 0))
     {
      Print (__FUNCTION__, ": failed to create the button! Error code = ", GetLastError());
      return(false);
     }
   ObjectSetInteger (chart_ID, name, OBJPROP_XDISTANCE, x);
   ObjectSetInteger (chart_ID, name, OBJPROP_YDISTANCE, y);
   ObjectSetInteger (chart_ID, name, OBJPROP_XSIZE, width);
   ObjectSetInteger (chart_ID, name, OBJPROP_YSIZE, height);
   ObjectSetInteger (chart_ID, name, OBJPROP_CORNER, corner);
   ObjectSetInteger (chart_ID, name, OBJPROP_FONTSIZE, font_size);
   ObjectSetInteger (chart_ID, name, OBJPROP_COLOR, clr);
   ObjectSetInteger (chart_ID, name, OBJPROP_BGCOLOR, back_clr);
   ObjectSetInteger (chart_ID, name, OBJPROP_BORDER_COLOR, border_clr);
   ObjectSetInteger (chart_ID, name, OBJPROP_BACK, back);
   ObjectSetInteger (chart_ID, name, OBJPROP_STATE, state);
   ObjectSetInteger (chart_ID, name, OBJPROP_SELECTABLE, selection);
   ObjectSetInteger (chart_ID, name, OBJPROP_SELECTED, selection);
   ObjectSetInteger (chart_ID, name, OBJPROP_HIDDEN, hidden);
   ObjectSetInteger (chart_ID, name, OBJPROP_ZORDER,z_order);
   ObjectSetString  (chart_ID, name, OBJPROP_TEXT, text);
   ObjectSetString  (chart_ID, name, OBJPROP_FONT, font);
   return(true);
  }
  
bool ButtonDelete (const long chart_ID=0, const string name="Button")
  {
   ResetLastError();
   if (!ObjectDelete (chart_ID,name))
     {
      Print (__FUNCTION__, ": Failed to delete the button! Error code = ", GetLastError());
      return(false);
     }
   return(true);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 
//drop down menu
   if (mode == 0) 
   {
    OnlyBuy = false;
    OnlySell = false;
   }
   else if (mode == 1) 
   {
    OnlyBuy = true;
    OnlySell = false;
   }  
   else if (mode == 2) 
   {
    OnlyBuy = false;
    OnlySell = true;
   } 
   else if (mode == 3) 
   {
    OnlyBuy = true;
    OnlySell = true;
   }
//end drop down menu

//stats

{
ObjectSetText("Mode", "Mode: " + IntegerToString(NormalizeDouble(mode / divider, 1), 1), font_size, font_face, font_color);
}
  
//----
   return(0);
  }


//+------------------------------------------------------------------+
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893