You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to make lot reset button, but I need to get much better result then this, but I can't.
( I do not like all my ea's and indicators Button objects because all of them very ugly like this one. )
I need two things from you guys who can help and gives me good advice, please I really need your help.
I spent a lot of time, and I can't figure out what is a problem with my code.
Thanks in advance.
//--- second time edited - while I write this comment maybe I was snoozing...
ObjectSetString ( 0, "button lot reset", OBJPROP_TEXT , "x" );
ObjectSetString ( 0, "button lot reset", OBJPROP_FONT , "Verdana" );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_FONTSIZE , 14 );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_XDISTANCE , 16 );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_YDISTANCE , 16 );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_XSIZE , 18 );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_YSIZE , 18 );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_CORNER , CORNER_LEFT_UPPER );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_COLOR , White );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_BGCOLOR , Black );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_BORDER_COLOR , Black );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_STATE , false );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_BACK , false );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_SELECTABLE , false );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_SELECTED , false );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_HIDDEN , true );
ObjectSetInteger ( 0, "button lot reset", OBJPROP_ZORDER , true );
//| Create the button |
//+------------------------------------------------------------------+
bool ButtonCreate(const long chart_ID=0, // chart's ID
const string name="Button", // button name
const int sub_window=0, // subwindow index
const int x=0, // X coordinate
const int y=0, // Y coordinate
const int width=50, // button width
const int height=18, // button height
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
const string text="Button", // text
const string font="Arial", // font
const int font_size=10, // font size
const color clr=clrBlack, // text color
const color back_clr=C'236,233,216', // background color
const color border_clr=clrNONE, // border color
const bool state=false, // pressed/released
const bool back=false, // in the background
const bool selection=false, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- reset the error value
ResetLastError();
//--- create the button
if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create the button! Error code = ",GetLastError());
return(false);
}
//--- set button coordinates
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set button size
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set the chart's corner, relative to which point coordinates are defined
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set text color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set background color
ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border color
ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- set button state
ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
//--- enable (true) or disable (false) the mode of moving the button by mouse
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
Please you can just use the function from the documentation 'as is' to create the buttons just add it at the bottom of your code and you can call the function and pass the parameters.
So then you can just call:
Also
Thanks I fixed it, just it was a mistake.
--------------------------------------------
Please you can just use the function from the documentation 'as is' to create the buttons just add it at the bottom of your code and you can call the function and pass the parameters.
So then you can just call:
Thanks Marco that will help me a lot, and my EA's codes looks like cleaned up.
Also I need to ask about below code, what is it, how is it work? ( even I read about that but I don not understand more clearly )
Please explain it bit more, thanks in advance.
----------------------------------------
Also I need to use void instead of bool like below code so which one is good?
// or
void ButtonCreate(...)
The function either returns true or false depending in whether the button creation was successful or not so it depends on you if you want to verify that the button was indeed created.
For the second question the tooltip is what becomes visible when you hover your mouse over the object on the chart.
The way you are working now has limitations.
If you want to expand please read the following articles:
https://www.mql5.com/en/search#!keyword=graphical%20interfaces&module=mql5_module_articles
The function either returns true or false depending in whether the button creation was successful or not so it depends on you if you want to verify that the button was indeed created.
For the second question the tooltip is what becomes visible when you hover your mouse over the object on the chart.
The way you are working now has limitations.
If you want to expand please read the following articles:
https://www.mql5.com/en/search#!keyword=graphical%20interfaces&module=mql5_module_articles
Huge thanks.
WOW, man you are going to be my man, Mr. Marco.
( since your first comment - you helped me a lot - you always try to understand my concerns - one more time huge thanks )
I need to use .PNG file format in my EA's code, for LotSize icon.
But I found only .BMP file format, so can someone help me / advice me?
If any comment could quickly much appreciate, just I am hurry a bit more.
Thanks in advance.
I try to if lotsize better then lotvalue 'State true' else 'State false'.
( when I click 'Reset' object then turn to 'state false' and after I increase lot size state does not turn to true )
Is below code wrong?
if ( sparam == _namelotRset )
{
if ( _lotSize > _lotValue )
{
ObjectSetInteger( 0, sparam, OBJPROP_STATE, true );
} //---if Close
else
{
ObjectSetInteger( 0, sparam, OBJPROP_STATE, false );
} //---if Close
_lotSize = _lotValue * _lotMin;
_infoUpdate();
return;
} //---if Close
Thanks!
//--- second time edited
I try to make turn 'ON OFF' with below code.
Please see:
https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_bitmap
For the bitmap issue.
And for the other issue you can splice it into separate parts to set the state outside of sparam.