Buttons & Textfields on mt4 chart possible now

 

Here i want to introduce a new free addon for mt4 as preview. I am currently testing a product called mt4gui. This product makes possible to place buttons, text fields, list fields directly onto chart; here is a preview screenshoot which is already working

http://fx1.net/wiki/uploads/img_7.png

Buttons react immediate after click without waiting for broker side tick. We are improving this product with more features next weeks. Why i post this is to get ideas from community whats needed. Of course not everything can be realised really but i ll filter interesting ideas here.

Here is an example very basic code demonstrates usage:

//
// Copyright (c) www.fx1.net  2009-2011
//

#import "toolbox.dll"   
   int tbPutButton(int,int,int,int,int,string);   
   bool tbIsClicked( int );
#import

#include <libtrade.mqh>
#include <libvisual.mqh>

int btn1 = 0;
int buybtn,sellbtn,closebtn,lotbtnp,lotbtnm;
double  LotSize = 0.10;

int init()
  {
   lotbtnp = tbPutButton(WindowHandle(Symbol(),Period()),100,55,50,35,"Lot +");
   lotbtnm = tbPutButton(WindowHandle(Symbol(),Period()),150,55,50,35,"Lot -");
   
   buybtn = tbPutButton(WindowHandle(Symbol(),Period()),210,55,100,35,"Market Buy");
   sellbtn = tbPutButton(WindowHandle(Symbol(),Period()),210,90,100,35,"Market Sell");
   closebtn = tbPutButton(WindowHandle(Symbol(),Period()),210,145,100,35,"Close All");      
   pFontSize(14);
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
  pReset();
  p("Lotsize: "+DoubleToStr(LotSize,2),Yellow);
  
  if (tbIsClicked(lotbtnp)) LotSize=LotSize+0.10;      
  if (tbIsClicked(lotbtnm) && LotSize>0.10) LotSize=LotSize-0.10;      
  
  
  if (tbIsClicked(buybtn))
      {
      PlaySound("ok.wav");
      OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,"Buy",1);
      }

  if (tbIsClicked(sellbtn))
      {
      PlaySound("ok.wav");
      OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,"Sell",1);
      }

  if (tbIsClicked(closebtn))
      {
      PlaySound("ok.wav");
      CloseAllByMagic(3,1);
      } 
  Print(tbIsClicked(buybtn));
  Print(tbIsClicked(sellbtn));
  Print(tbIsClicked(closebtn));
  return(0);
  }
 

We have released new version of MT4GUI now. All betatesters are welcome to contact me

for samples: http://www.fx1.net/wiki/pmwiki.php/MT4GUI/MT4GUI

#import "toolbox.dll"   
   int tbPutObject(int,string,int,int,int,int,string);
   int tbRemoveAll(int);
   int tbSetText(int,string,int,string);
   int tbSetBgColor(int,int);
   int tbSetTextColor(int,int);
   
   bool tbIsClicked( int );
   int tbRemove(int); 
   int tbEnable(int,int);
#import

 


Great idea, but product is not working yet. Not without the "libtrade.mqh" and "libvisual.mqh". Where can I get those files to really test the mt4gui.dll?

Without those files compiler cannot define the "pFontSize", "pReset", "p" and "CloseAllByMagic" functions.

 

Here is new screenshoot update


 

pro_

you can find the files in download section since 2 days there are updates. Colors are working now and several bugs have been fixed.

Yes you need the include files but they are not related with mt4gui project. Its simply my own routines to define some functions like p (print to screen). Sample code is fully demonstrating mt4gui and on other hand we are still working on that project.

Coming soon:

Mouse position detection
Background of chart detection to automatically adapt bgcolors of objects
Listbox

regards

 
 

The product IS working and it is exactly what I need. But...

I have a few issues with it.

1) cannot place the text on screen; (lots, SL, TP, etc. line)

2) colors do not work, no matter what I do;

3) this is more of a suggestion - is it possible to place the buttons in a separate subwindow? It will be much more convinient, will look like a trade console and if subwindow is minimized will help avoid accidental clicks on a button. As far as I can see from the PutObject function, coordinates are not related to main or sub-window.

But reagrdless of all this, this is a great product. To have it implemented in MT4 was long-awaited. Thanx.

 

one more thing:

buttons stay on after the expert is removed.

 

pro__

1) to place a text on screen you can use MQL internal objects here is an example code:

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
string pxy(string mytext,color clr,int posx,int posy,int size)
{
   string n="pxy3txt"+posx+posy;
   ObjectCreate(n, OBJ_LABEL, 0, Time[lib_startbarno], lib_nextlinelevel);
   ObjectSet(n, OBJPROP_CORNER, 0);
   ObjectSet(n, OBJPROP_XDISTANCE, posx);
   ObjectSet(n, OBJPROP_YDISTANCE, posy);
   ObjectSet(n, OBJPROP_COLOR, clr);
   ObjectSet(n, OBJPROP_BACK, false);
   ObjectSetText(n, mytext, size);
   return(n);
}

Another full example is:

#import "mt4gui.dll"   
   int tbPutObject(int,string,int,int,int,int,string);
   int tbRemoveAll(int);
   int tbSetText(int,string,int,string);
   int tbSetBgColor(int,int);
   int tbSetTextColor(int,int);
   string tbGetText( int );
   bool tbIsClicked( int );
   int tbRemove(int); 
   int tbEnable(int,int);
#import

#include <libtrade.mqh>
#include <libvisual.mqh>
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Login implementation demo
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
int btn1,btn2,edit1,edit2,l1,l2;
int ticks;
bool LoggedIn = false;
string obj1="";

int init()
  {
   int hwnd=WindowHandle(Symbol(),Period());
   tbRemoveAll(hwnd); ObjectsDeleteAll();
   
   
   //void  pxy(string mytext,color clr,int posx,int posy,int size)
   pxy("Please login",Yellow,250,50,19);
   pxy("Login :",White,250,100,17);
   pxy("Passwd:",White,250,140,17);
   
   l1=tbPutObject(hwnd,"text",350,100,250,30,"Username");   
   l2=tbPutObject(hwnd,"text",350,140,250,30,"Password");   
   btn1=tbPutObject(hwnd,"button",250,200,150,40,"Login");
   btn2=tbPutObject(hwnd,"button",450,200,150,40,"Exit");
   
   
   // set colors
   tbSetBgColor(btn1,Green); tbSetTextColor(btn1,White);
   tbSetBgColor(btn2,IndianRed); tbSetTextColor(btn2,White);
   
   tbSetText(l2,"xxxxxxxxxx",24,"Wingdings");
        
   return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//| dont forget to remove objects on deinit()                        |
//+------------------------------------------------------------------+
int deinit()
  {
   tbRemove(btn1);tbRemove(btn2);
   tbRemove(l1);tbRemove(l2);   
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int hwnd=WindowHandle(Symbol(),Period()); ticks++; pReset();
   if (MathMod(ticks,20)==19 && StringLen(obj1)>0) ObjectDelete(obj1);
   
   
   
   // If still not logged in we use this block
   if (!LoggedIn)
   {
      // exit button
      if (tbIsClicked(btn2)) {     ObjectsDeleteAll(); tbRemoveAll(hwnd); Destroy("Authentification Failed"); return(1);      }
  
      // login button
      if (tbIsClicked(btn1)) {
       if (tbGetText(l1)=="admin" && tbGetText(l2)=="pass")
         { PlaySound("ok.wav"); LoggedIn=true; tbRemoveAll(hwnd); ObjectsDeleteAll(); }
         else
         { PlaySound("alert2.wav"); obj1 = pxy("Authentification Failed",Red,250,20,12);}        
      } 
      return(1);
   }
   // From here we have the functions after login
   p("Admin has been autentificated successfully",Green); 
   
   
   
   return(0);
  }
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
string pxy(string mytext,color clr,int posx,int posy,int size)
{
   string n="pxy3txt"+posx+posy;
   ObjectCreate(n, OBJ_LABEL, 0, Time[lib_startbarno], lib_nextlinelevel);
   ObjectSet(n, OBJPROP_CORNER, 0);
   ObjectSet(n, OBJPROP_XDISTANCE, posx);
   ObjectSet(n, OBJPROP_YDISTANCE, posy);
   ObjectSet(n, OBJPROP_COLOR, clr);
   ObjectSet(n, OBJPROP_BACK, false);
   ObjectSetText(n, mytext, size);
   return(n);
}

As you see on my screenshoots demos work. This version of mt4gui i have just uploaded as version 0.3, you can take latest version. 0.1 has no colors support at all. You are probably using 0.1.

To remove buttons from screen you must use deinit()

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//| dont forget to remove objects on deinit()                        |
//+------------------------------------------------------------------+
int deinit()
  {
   tbRemove(btn1);tbRemove(btn2);
   tbRemove(l1);tbRemove(l2);   
   return(0);
  }
 

Hi,

This is the most useful addon I've ever seen, thank you for the developing.

Is there any way to get the status of a checkbox or get the text of a textbox/label/button?

Colors do not work with version 0.2.

Reason: