Chart size and position

 

Hello, 

may i ask why i can't set the height, width and position of a chart after opening it?

This is the code i use:

// General Variables
bool ChartSetInteger();


// function
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
  if(id==CHARTEVENT_OBJECT_CLICK && ObjectGet(sparam,OBJPROP_TYPE)==OBJ_BUTTON)
      {
      long idchart=ChartOpen(ObjectGetString(0,sparam,OBJPROP_TEXT),PERIOD_M15);
      ChartApplyTemplate(idchart,"Default");
      ChartSetInteger(idchart,CHART_WIDTH_IN_PIXELS,800);
      ChartSetInteger(idchart,CHART_HEIGHT_IN_PIXELS,500);
      }

I also tried to use WindowRedraw(); and tried to write a different indicator just with  

ChartSetInteger(idchart,CHART_WIDTH_IN_PIXELS,800);
ChartSetInteger(idchart,CHART_HEIGHT_IN_PIXELS,500);

to put directly on the new opened chart but nothing works!

Thanks.

 

Read the help. These are read-only chart properties:

CHART_WIDTH_IN_PIXELS

Chart width in pixels

int r/o

CHART_HEIGHT_IN_PIXELS

Chart height in pixels

int      modifier - subwindow number

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Examples of Working with the Chart
  • www.mql5.com
Examples of Working with the Chart - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

How can i do to set the size and posizion of a chart by code, then?

Thanks.

 
Francesco Grassi :

How can i do to set the size and posizion of a chart by code, then?

Thanks.

You can GET the dimensions of the graph. You cannot SET the dimensions of the graph (if we are talking about standard graphics).

But you can create a graph - a graphic object ( OBJ_CHART ) and then you can control the size (example inside the help)


Add:

OBJ_CHART

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_CHART
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_CHART
  • www.mql5.com
OBJ_CHART - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks for the explanation.

With "if we are talking about standard graphics" you mean that i could achieve this using external libraries?

 
Francesco Grassi :

Thanks for the explanation.

With " if we are talking about standard graphics" you mean that i could achieve this using external libraries?

Read above. I said everything and gave examples. I also highly recommend reading the help.

 

By the way, take a look at the new charting functions: (applies to real charts)

CHART_IS_DOCKED

The chart window is docked. If set to false, the chart can be dragged outside the terminal area

bool

CHART_FLOAT_LEFT

The left coordinate of the undocked chart window relative to the virtual screen

int

CHART_FLOAT_TOP

The top coordinate of the undocked chart window relative to the virtual screen

int

CHART_FLOAT_RIGHT

The right coordinate of the undocked chart window relative to the virtual screen

int

CHART_FLOAT_BOTTOM

The bottom coordinate of the undocked chart window relative to the virtual screen

int

Documentation on MQL5: Language Basics / Data Types / Integer Types / Bool Type
Documentation on MQL5: Language Basics / Data Types / Integer Types / Bool Type
  • www.mql5.com
Bool Type - Integer Types - Data Types - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thank you very much for the info mate. I'll make some tests when i'm free from work.

Bytheway i try to read the help but sometimes i just don't know what to look for :)

Have a nice day.

Reason: