How to open a Chart Sub Window without using an indicator? MT5

 

I would like to open a subwindow via expert advisor but I do not see any Chart function that can open a subwindow without attaching an indicator(shell code with #property indicator_separate_window)

I can not attach the #property indicator_separate_window to an expert advisor without the compiler requiring the OnCalc() function which shouldn't be need for the wubwindow to operate.

 
Hello you can read this article maybe it has a solution for you: https://www.mql5.com/en/articles/2723
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
  • www.mql5.com
The first article Graphical Interfaces I: Preparation of the Library Structure (Chapter 1) considers in detail what this library is for. A complete list of links to the articles of the first part is at the end of each chapter. There, you can also download a complete version of the library at the current stage of development. The files must be...
 
The article requires editing of the standard include files so I decided to make the Subwindow.mq5 indicator and place that on the chart with the expert advisor. The EA then places objects in the subwindow
 

Return Value

The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an attempt is made to change its coordinates.


how long does it take to place one object on the chart?


//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

int OnInit()
  {
//--- create timer
   EventSetTimer(1);

//---
   return(INIT_SUCCEEDED);
  }

long timer=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   timer++;
   Print(" Check Timer: "+IntegerToString(timer));
//---

   SetText_subWindow("sub_tick",IntegerToString(timer),100,0,Blue,10);

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetText_subWindow(string name,string text,int x,int y,color colour,int size=12)
  {
   int find= ObjectFind(0,name);
   if(find>=0)// Object found in window 0 or window 1
     {
      Print("OBJECT FOUND "+name+" chart window():"+find);
      if(ObjectSetString(0,name,OBJPROP_TEXT,text))
        {
         Print("SetText_subWindow() Text Updated: "+text);
        }
        }else{
      if(ObjectCreate(0,name,OBJ_LABEL,1,0,0))
        {
         ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
         ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
         ObjectSetInteger(0,name,OBJPROP_COLOR,colour);
         ObjectSetInteger(0,name,OBJPROP_FONTSIZE,size);
         ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
         Print(" object created: "+name);
           }else{
         Print(" object creation failed; Error(): "+GetLastError());
        }
     }

  }
//+------------------------------------------------------------------+
 

The timer() loop in on 54 while the object on the chart is still at 52.


How can the the queue of the specified chart, become faster ? Is my code the source of the delay?

 
torytory:

The timer() loop in on 54 while the object on the chart is still at 52.


How can the the queue of the specified chart, become faster ? Is my code the source of the delay?

You need to refresh the chart : ChartRedraw().
 
Alain Verleyen:
You need to refresh the chart : ChartRedraw().

Thank you.Next, how can I display Comment() on top of an object. The image below has two objects , one with ObjectSetInteger(0,name,OBJPROP_BACK,false); and other True. you will see that Comment() can only display if the object is ObjectSetInteger(0,name,OBJPROP_BACK,true);

The issue is, if set to TRUE, the candles overlay the object and the Comment() are unreadable.


objects

 
torytory:

Thank you.Next, how can I display Comment() on top of an object. The image below has two objects , one with ObjectSetInteger(0,name,OBJPROP_BACK,false); and other True. you will see that Comment() can only display if the object is ObjectSetInteger(0,name,OBJPROP_BACK,true);

The issue is, if set to TRUE, the candles overlay the object and the Comment() are unreadable.



I suggest you better create Text Labels to plot your text informations, and stop using Comment for that purpose.

Text labels allows you to choose Font, Color, Size and Position for any information, can be used both on EA and on Indicators.


I just use Comment() for quick debuging purpose while coding.

because Commen() can be rewriten by any other indicator, like a "shared place" to put info. It is not reliable to keep important informations.


https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
  • www.mql5.com
//| Create a text label                                              |               chart_ID=0,                               sub_window=0,                             x=0,                                      y=0,                                      font_size=10,                          angle=0.0,                ...