//+------------------------------------------------------------------+ //| TEST_EA.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" string MC_name="Minichart"; //minichart name int OnInit() { ObjectsDeleteAll(0, MC_name); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ ObjectsDeleteAll(0, MC_name); } void OnTick() { handleMiniChart(); } void handleMiniChart(){ long MC_ID=-1; //minichart ID string symbol = "EURUSD"; ENUM_TIMEFRAMES period = PERIOD_M15; if(ObjectFind(0,MC_name)<0){ //create mini chart ObjectMiniChartCreate(0, MC_name, symbol, period); MC_ID=ObjectGetInteger(0,MC_name,OBJPROP_CHART_ID); Print("["+ChartSymbol()+"] Object Create: " +" obj symbol: "+(ObjectGetString(0,MC_name,OBJPROP_SYMBOL)) +" - obj period: "+(ObjectGetInteger(0,MC_name,OBJPROP_PERIOD)) +" - chart symbol: "+(ChartSymbol(MC_ID)) +" - chart period: "+(ChartPeriod(MC_ID)) ); }else{ MC_ID=ObjectGetInteger(0,MC_name,OBJPROP_CHART_ID); Print("["+ChartSymbol()+"] Object Exist: " +" obj symbol: "+(ObjectGetString(0,MC_name,OBJPROP_SYMBOL)) +" - obj period: "+(ObjectGetInteger(0,MC_name,OBJPROP_PERIOD)) +" - chart symbol: "+(ChartSymbol(MC_ID)) +" - chart period: "+(ChartPeriod(MC_ID)) ); } ChartRedraw(MC_ID); } bool ObjectMiniChartCreate(const long chart_ID=0, // chart's ID const string name="Minichart", // object name const string symbol=NULL, // symbol const ENUM_TIMEFRAMES period=0, // period const int x=0, // X coordinate const int y=0, // Y coordinate const int width=400, // width const int height=300, // height const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // anchoring corner const int sub_window=0, // subwindow index const int scale=2, // scale const bool date_scale=false, // time scale display const bool price_scale=false, // price scale display const color clr=clrRed, // border color when highlighted const ENUM_LINE_STYLE style=STYLE_SOLID, // line style when highlighted const int point_width=1, // move point size const bool back=false, // in the background const bool selection=false, // highlight to move const bool hidden=false, // hidden in the object list const long selectable=true, //selectable const long z_order=0) // priority for mouse click { //--- reset the error value ResetLastError(); //--- create Chart object if(!ObjectCreate(chart_ID,name,OBJ_CHART,sub_window,0,0)) { Print(__FUNCTION__, ": failed to create \"Chart\" object! Error code = ",GetLastError()); return(false); } //--- set object coordinates ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); //--- set object 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 symbol ObjectSetString(chart_ID,name,OBJPROP_SYMBOL,symbol); //--- set the period ObjectSetInteger(chart_ID,name,OBJPROP_PERIOD,period); //--- set the scale ObjectSetInteger(chart_ID,name,OBJPROP_CHART_SCALE,scale); //--- display (true) or hide (false) the time scale ObjectSetInteger(chart_ID,name,OBJPROP_DATE_SCALE,date_scale); //--- display (true) or hide (false) the price scale ObjectSetInteger(chart_ID,name,OBJPROP_PRICE_SCALE,price_scale); //--- set the border color when object highlighting mode is enabled ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set the border line style when object highlighting mode is enabled ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- set a size of the anchor point for moving an object ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,point_width); //--- 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 label by mouse ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,true); 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); }