This is my current Expert Advisor, but i dont know how to do it.
What i want is for example that the EA print a message when i click on the button.
#property strict//--- description#property description"Script creates the button on the chart."//--- display window of the input parameters during the script's launchinputstring InpName="Button"; // Button nameinputENUM_BASE_CORNER InpCorner=CORNER_RIGHT_UPPER;// Chart corner for anchoringinputstring InpFont="Arial"; // Fontinputint InpFontSize=14; // Font sizeinputcolor InpColor=clrBlack; // Text colorinputcolor InpBackColor=C'236,233,216'; // Background colorinputcolor InpBorderColor=clrNONE; // Border colorinputbool InpState=false; // Pressed/Releasedinputbool InpBack=false; // Background objectinputbool InpSelection=false; // Highlight to moveinputbool InpHidden=true; // Hidden in the object listinputlong InpZOrder=0; // Priority for mouse click//+------------------------------------------------------------------+//| Create the button |//+------------------------------------------------------------------+bool ButtonCreate(constlong chart_ID=0, // chart's IDconststring name="Button", // button nameconstint sub_window=0, // subwindow indexconstint x=0, // X coordinateconstint y=0, // Y coordinateconstint width=50, // button widthconstint height=18, // button heightconstENUM_BASE_CORNER corner=CORNER_RIGHT_UPPER,// chart corner for anchoringconststring text="Button", // textconststring font="Arial", // fontconstint font_size=10, // font sizeconstcolor clr=clrBlack, // text colorconstcolor back_clr=C'236,233,216', // background colorconstcolor border_clr=clrNONE, // border colorconstbool state=false, // pressed/releasedconstbool back=false, // in the backgroundconstbool selection=false, // highlight to moveconstbool hidden=true, // hidden in the object listconstlong z_order=0) // priority for mouse click
{
//--- reset the error valueResetLastError();
//--- create the buttonif(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create the button! Error code = ",GetLastError());
return(false);
}
//--- set button coordinatesObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set button sizeObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set the chart's corner, relative to which point coordinates are definedObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the textObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text fontObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font sizeObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set text colorObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set background colorObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border colorObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- display in the foreground (false) or background (true)ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the button by mouseObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object listObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chartObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---ObjectDelete(0,"button");
}
//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnTick()
{
//---int lenght = 100;
int height = 20;
//--- create the buttonif(ObjectFind(InpName)<0)
{
if(!ButtonCreate(0,InpName,0,110,10,lenght,height,InpCorner,"Press",InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,InpSelection,InpHidden,InpZOrder))
{
return;
}
}
//--- redraw the chartChartRedraw();
//---
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+voidOnChartEvent(constint id, // Event identifier constlong& lparam, // Event parameter of long typeconstdouble& dparam, // Event parameter of double typeconststring& sparam) // Event parameter of string type
{
//--- the left mouse button has been pressed on the chartif(id==CHARTEVENT_CLICK)
{
Print("The coordinates of the mouse click on the chart are: x = ",lparam," y = ",dparam);
}
//--- the mouse has been clicked on the graphic objectif(id==CHARTEVENT_OBJECT_CLICK)
{
Print("The mouse has been clicked on the object with name '"+sparam+"'");
}
}
Where is it printing? I am looking into the Journal tab when i make backtest and i dont see that the print there somethink when i click into the chart or on the button.
PlanandTrade:
Where is it printing? I am looking into the Journal tab when i make backtest and i dont see that the print there somethink when i click into the chart or on the button.
Perhaps buttons don't work in the Strategy Tester, try on a live chart . . . certainly in MT5 Buttons didn't work in the Strategy Tester, I haven't tested this recently.
Thank you for the info, i would not have find the reason why it dont work in the strategy tester without your info. I have try it now on a live chart and here it does work.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Sorry, got things messed up a bit.
This is my current Expert Advisor, but i dont know how to do it.
What i want is for example that the EA print a message when i click on the button.
Where is it printing? I am looking into the Journal tab when i make backtest and i dont see that the print there somethink when i click into the chart or on the button.
for example
<Picture removed by moderator>
Hello,
Please note the we are not allowed to advertise on this forum. From the rules :
Posting of advertising messages, spamming and flooding are forbidden.
So, please don't try to advertise, even indirectly. Thank you.