Add this object:
// *** Background ObjectCreate(ChartID(), objectBackgroundName, OBJ_RECTANGLE_LABEL, 0, 0, 0); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_XDISTANCE, 10); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_YDISTANCE, 10); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_XSIZE, 500); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_YSIZE, 275); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_BGCOLOR, clrBlack); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_BORDER_COLOR, clrBlack); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_BORDER_TYPE, BORDER_FLAT); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_WIDTH, 0); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_BACK, false); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_SELECTABLE, false); ObjectSetInteger(ChartID(), objectBackgroundName, OBJPROP_HIDDEN, true);
#property link "http://www.mql4.com" #property version "1.00" #property strict #include <Controls\Panel.mqh> #include <Charts\Chart.mqh> //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- ShowPanel(300,200); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- MyPanel.Destroy(); MyChart.Detach(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- static int chartwidth; if (id==CHARTEVENT_CHART_CHANGE) { if (MyChart.WidthInPixels()!=chartwidth) { chartwidth=MyChart.WidthInPixels(); MyPanel.Move(chartwidth-300,0); } } } //+------------------------------------------------------------------+ CPanel MyPanel; CChart MyChart; void ShowPanel(int width, int height) { int x; MyChart.Attach(ChartID()); x=MyChart.WidthInPixels()-width; if (!MyPanel.Create(NULL,"MyPanel",NULL,x,0,x+width,height)) return; MyPanel.ColorBackground(Green); MyPanel.Show(); }
The sample keeps the rectangle in place even when the chart has been changed in its size.
Rather use MQL5 Classes for things like that ;)
Hope this helps ...
Hello my friends,
Could you please help me to make this code better.
I succeeded at building a Menu for my EA that help me to view important information. the Menu look like this:
I want to add a rectangle frame to the background so it will look like this:
Here is the code of the Menu:
Hello, please take here:
//===Choose to show or hide Menu #define SHOW 0 #define HIDE 1 enum SH { Show,Hide }; //---Expert Proprities extern SH ShowMenu = SHOW; extern double LOTSIZE = 0.01; extern int Profit = 50; extern int StopLoss = 50; extern color MenuColor = clrWhite; extern color LiningColor = clrDarkGreen; extern int MenuFont = 11; extern int MagicNumber = 0; //---initialize global variables int medzera,i; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { if(ShowMenu == SHOW) { DrawMenu(); } //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- if(ShowMenu == SHOW) { ObjectDelete("Lining"); ObjectDelete("LotLabel"); ObjectDelete("TPLabel"); ObjectDelete("SPLabel"); ObjectDelete("LotValue"); ObjectDelete("TPValue"); ObjectDelete("SPValue"); } //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---Show or hide Menu if(ShowMenu == SHOW) { ReDrawMenu(); } return(0); } //+------------------------------------------------------------------+ //| DRAW MENU OBJECTS FUNCTIONS | //+------------------------------------------------------------------+ //--- Function to draw Menu for the first time bool DrawMenu() { medzera = 8; //--- Create Labels Cells ObjectCreate("Lining",OBJ_LABEL,0,0,0,0,0); ObjectCreate("LotLabel",OBJ_LABEL,0,0,0,0,0); ObjectCreate("TPLabel",OBJ_LABEL,0,0,0,0,0); ObjectCreate("SPLabel",OBJ_LABEL,0,0,0,0,0); //---Modify Label Cells ObjectSetText("Lining", "ggg",5 * MenuFont, "Webdings",LiningColor); ObjectSet("Lining",OBJPROP_XDISTANCE,MenuFont); ObjectSet("Lining",OBJPROP_YDISTANCE,MenuFont+3); ObjectSet("Lining",OBJPROP_CORNER,1); ObjectSetText( "LotLabel", "Lot Size: " , MenuFont, "Arial", MenuColor); ObjectSet("LotLabel",OBJPROP_XDISTANCE,medzera * MenuFont); ObjectSet("LotLabel",OBJPROP_YDISTANCE,10+1*MenuFont); ObjectSet("LotLabel",OBJPROP_CORNER,1); ObjectSetText("TPLabel", "Take Profit in Pips: ", MenuFont, "Arial",MenuColor); ObjectSet("TPLabel",OBJPROP_XDISTANCE,medzera * MenuFont); ObjectSet("TPLabel",OBJPROP_YDISTANCE,15+2*(MenuFont+2)); ObjectSet("TPLabel",OBJPROP_CORNER,1); ObjectSetText("SPLabel", "Stop Loss in Pips: ", MenuFont, "Arial",MenuColor); ObjectSet("SPLabel",OBJPROP_XDISTANCE,medzera * MenuFont); ObjectSet("SPLabel",OBJPROP_YDISTANCE,20+3*(MenuFont+2)); ObjectSet("SPLabel",OBJPROP_CORNER,1); //--- Create Numerical Value Cells ObjectCreate("LotValue",OBJ_LABEL,0,0,0,0,0); ObjectCreate("TPValue",OBJ_LABEL,0,0,0,0,0); ObjectCreate("SPValue",OBJ_LABEL,0,0,0,0,0); //--- Modify numerical Value Cells ObjectSetText("LotValue", ""+ LOTSIZE, MenuFont, "Arial",MenuColor); ObjectSet("LotValue",OBJPROP_XDISTANCE, 3 * MenuFont); ObjectSet("LotValue",OBJPROP_YDISTANCE,10+1*(MenuFont+2)); ObjectSet("LotValue",OBJPROP_CORNER,1); ObjectSetText("TPValue"," "+Profit, MenuFont, "Arial",MenuColor); ObjectSet("TPValue",OBJPROP_XDISTANCE,3 * MenuFont); ObjectSet("TPValue",OBJPROP_YDISTANCE,15+2*(MenuFont+2)); ObjectSet("TPValue",OBJPROP_CORNER,1); ObjectSetText("SPValue", " "+ StopLoss, MenuFont, "Arial",MenuColor); ObjectSet("SPValue",OBJPROP_XDISTANCE,3 * MenuFont); ObjectSet("SPValue",OBJPROP_YDISTANCE,20+3*(MenuFont+2)); ObjectSet("SPValue",OBJPROP_CORNER,1); return(0); } //--- Function to redraw Menu on each tick bool ReDrawMenu() { medzera = 8; ObjectSetText("LotValue", ""+LOTSIZE, MenuFont, "Arial",MenuColor); ObjectSetText("TPValue", Profit, MenuFont, "Arial",MenuColor); ObjectSetText("SPValue", StopLoss, MenuFont, "Arial",MenuColor); return(0); }
Add this object:
You mean I should Use OBJ_RECTANGLE_LABEL instead of OBJ_RECTANGLE.
OK, I did it :)
I also changed the way of changing the size of the Menu, instead of using MenuFont I will use MenuSize parameter. It work fine now and I can change the size of the Menu , and I can Hide or Show it.
Now the code look like this:
//===Choose to show or hide Menu #define SHOW 0 #define HIDE 1 enum SH { Show,Hide }; //---Expert Proprities extern SH ShowMenu = SHOW; extern double LOTSIZE = 0.01; extern int Profit = 50; extern int StopLoss = 50; extern color MenuColor = clrWhite; extern color FrameColor = clrGreen; extern int MenuSize = 1; extern int MagicNumber = 0; //---initialize global variables int medzera,i; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { if(ShowMenu == SHOW) { DrawMenu(); } //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- if(ShowMenu == SHOW) { ObjectDelete("FrameLabel"); ObjectDelete("LotLabel"); ObjectDelete("TPLabel"); ObjectDelete("SPLabel"); ObjectDelete("LotValue"); ObjectDelete("TPValue"); ObjectDelete("SPValue"); } //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---Show or hide Menu if(ShowMenu == SHOW) { ReDrawMenu(); } return(0); } //+------------------------------------------------------------------+ //| DRAW MENU OBJECTS FUNCTIONS | //+------------------------------------------------------------------+ //--- Function to draw Menu for the first time bool DrawMenu() { medzera = 8; int MenuFont = MenuSize*11; //--- Create Labels Cells ObjectCreate("FrameLabel",OBJ_RECTANGLE_LABEL,0,0,0,0,0,0); ObjectCreate("LotLabel",OBJ_LABEL,0,0,0,0,0); ObjectCreate("TPLabel",OBJ_LABEL,0,0,0,0,0); ObjectCreate("SPLabel",OBJ_LABEL,0,0,0,0,0); //---Modify Label Cells //**** ObjectSet("FrameLabel",OBJPROP_BGCOLOR,FrameColor); ObjectSet("FrameLabel",OBJPROP_CORNER,1); ObjectSet("FrameLabel",OBJPROP_BACK,true); ObjectSet("FrameLabel",OBJPROP_XDISTANCE,MenuSize*220); ObjectSet("FrameLabel",OBJPROP_YDISTANCE,MenuSize*18); ObjectSet("FrameLabel",OBJPROP_XSIZE,MenuSize*200); ObjectSet("FrameLabel",OBJPROP_YSIZE,MenuSize*60); //*** ObjectSetText( "LotLabel", "Lot Size: " , MenuFont, "Arial", MenuColor); ObjectSet("LotLabel",OBJPROP_XDISTANCE,MenuSize*88); ObjectSet("LotLabel",OBJPROP_YDISTANCE,MenuSize*21); ObjectSet("LotLabel",OBJPROP_CORNER,1); ObjectSetText("TPLabel", "Take Profit in Pips: ", MenuFont, "Arial",MenuColor); ObjectSet("TPLabel",OBJPROP_XDISTANCE,MenuSize*88); ObjectSet("TPLabel",OBJPROP_YDISTANCE,MenuSize*41); ObjectSet("TPLabel",OBJPROP_CORNER,1); ObjectSetText("SPLabel", "Stop Loss in Pips: ", MenuFont, "Arial",MenuColor); ObjectSet("SPLabel",OBJPROP_XDISTANCE,MenuSize*88); ObjectSet("SPLabel",OBJPROP_YDISTANCE,MenuSize*59); ObjectSet("SPLabel",OBJPROP_CORNER,1); //--- Create Numerical Value Cells ObjectCreate("LotValue",OBJ_LABEL,0,0,0,0,0); ObjectCreate("TPValue",OBJ_LABEL,0,0,0,0,0); ObjectCreate("SPValue",OBJ_LABEL,0,0,0,0,0); //--- Modify numerical Value Cells ObjectSetText("LotValue", ""+ LOTSIZE, MenuFont, "Arial",MenuColor); ObjectSet("LotValue",OBJPROP_XDISTANCE, MenuSize*33); ObjectSet("LotValue",OBJPROP_YDISTANCE,MenuSize*21); ObjectSet("LotValue",OBJPROP_CORNER,1); ObjectSetText("TPValue"," "+Profit, MenuFont, "Arial",MenuColor); ObjectSet("TPValue",OBJPROP_XDISTANCE,MenuSize*33); ObjectSet("TPValue",OBJPROP_YDISTANCE,MenuSize*41); ObjectSet("TPValue",OBJPROP_CORNER,1); ObjectSetText("SPValue", " "+ StopLoss, MenuFont, "Arial",MenuColor); ObjectSet("SPValue",OBJPROP_XDISTANCE,MenuSize*33); ObjectSet("SPValue",OBJPROP_YDISTANCE,MenuSize*59); ObjectSet("SPValue",OBJPROP_CORNER,1); return(0); } //--- Function to redraw Menu on each tick bool ReDrawMenu() { medzera = 8; int MenuFont = MenuSize*11; ObjectSetText("LotValue", ""+LOTSIZE, MenuFont, "Arial",MenuColor); ObjectSetText("TPValue", Profit, MenuFont, "Arial",MenuColor); ObjectSetText("SPValue", StopLoss, MenuFont, "Arial",MenuColor); return(0); }
The sample keeps the rectangle in place even when the chart has been changed in its size.
Rather use MQL5 Classes for things like that ;)
Hope this helps ...
Hello, please take here:
Thanks a lot Alexander, your code is even better than mine.
You're welcome :) But one question: Why don't you use the classes? Its much safer and easier than this native stuff.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello my friends,
Could you please help me to make this code better.
I succeeded at building a Menu for my EA that help me to view important information. the Menu look like this:
I want to add a rectangle frame to the background so it will look like this:
Here is the code of the Menu: