Errors, bugs, questions - page 2041

 
Kirill Belousov:
We do not specify the subwindow number, but the function tells us (this is an output parameter, not an input parameter) - in which subwindow of the chart with the specified ID there is a price chart and it tells us what price and time correspond to the X,Y coordinates we specified in that chart.

This is understandable, passing the parameter by reference. But the question is open: why doesn't the function see in which subwindow number the indicator is installed and doesn't take data from it?

 
Vitaly Muzichenko:

This is understandable, passing the parameter by reference. But the question is open: why doesn't the function see which subwindow number the indicator is installed in and take data from it?

CHART_HEIGHT_IN_PIXELS
 
fxsaber:
CHART_HEIGHT_IN_PIXELS

It's a whole story with calculations if you have several indicators in subwindows, but thanks anyway for your time.

 
Vitaly Muzichenko:

It's a whole story with calculations if there are several indicators in subwindows, but thanks anyway for your time.

https://www.mql5.com/ru/docs/chart_operations/chartwindowfind

Документация по MQL5: Операции с графиками / ChartWindowFind
Документация по MQL5: Операции с графиками / ChartWindowFind
  • www.mql5.com
1. Функция ищет на указанном графике подокно с указанным "коротким именем" индикатора (короткое имя выводится слева вверху подокна) и в случае удачи возвращает номер подокна. Не следует путать короткое имя индикатора и имя файла, которое указывается при создании индикатора функциями iCustom() и IndicatorCreate(). Если короткое наименование...
 

Yes these are all functions I know.

The task is simple, we need to link the object in the 4th sub-window (highlighted in red) to the price, in this case it is -0.02, and the Y coordinate on the graph is 34


 
Vitaly Muzichenko:

The task is simple, you need to link the object in sub-window 4 (highlighted in red) to the price, in this case it is -0.02, and the Y coordinate on the graph is 34

#property indicator_separate_window

#property indicator_buffers 0 
#property indicator_plots 0

#define  CHART_SUBWINDOW_BORDER_SIZE 2 // Размер разделителя подокон

void OnInit()
{
  int X = 0;
  int Y = 0;

  const int SubWindow = ChartWindowFind();
  
  for (int i = 0; i < SubWindow; i++)  
    Y += (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, i) + CHART_SUBWINDOW_BORDER_SIZE;
  
  int SubWindow2;
  datetime time;
  double Price;
  
  if (ChartXYToTimePrice(0, X, Y, SubWindow2, time, Price))
    Print(SubWindow2);
}

int OnCalculate ( const int rates_total, const int, const int, const double &[] )
{ 
  return(rates_total);
}
 
fxsaber:

Thanks for the finished variant, I'll try to attach it to the indicators.

P.S. It worked, thanks again!


But the question remains, why should I specify the subwindow number in the function, if I have to dance with tambourine?

 
Vitaly Muzichenko:

Why should I specify the subwindow number in the function if I have to play with it?

Forum on trading, automated trading systems and strategy testing

Errors, Bugs, Questions

Kirill Belousov, 2017.10.15 19:50

We don't specify the subwindow number, the function tells us(this is an output parameter, not an input parameter) - in which subwindow of the chart with the specified ID is the price chart and what price and time correspond to the X,Y coordinates we specified on that chart.
 
Vitaly Muzichenko:

Thanks for the finished variant, I'll try to attach it to the indicators.

P.S. It worked, thanks again!


But the question remains, why should I specify the subwindow number in the function, if I want to make a mess?

The dance can be shortened by using ChartGetInteger() with this parameter

CHART_WINDOW_YDISTANCE

Distance in pixels along the vertical Y-axis between the upper border of the indicator subwindow and the upper border of the main chart window. At mouse events, the cursor coordinates are passed in the coordinates of the main chart window, while the coordinates of graphical objects in an indicator subwindow are set relative to the upper left corner of the subwindow.

The value is required for converting the absolute coordinates of the main chart to the local coordinates of a subwindow for correct work with the graphical objects whose coordinates are set relative to the upper left corner of the subwindow frame.

int r/o modifier - subwindow number

 
Kirill Belousov:

The dance can be shortened by using ChartGetInteger() with this parameter

CHART_WINDOW_YDISTANCE

Distance in pixels along the vertical y-axis between the upper frame of the indicator subwindow and the upper frame of the main chart window. At mouse events, the cursor coordinates are passed in the coordinates of the main chart window, while the coordinates of graphical objects in an indicator subwindow are set relative to the upper left corner of the subwindow.

The value is required for converting the absolute coordinates of the main chart to the local coordinates of a subwindow for correct work with the graphical objects whose coordinates are set relative to the upper left corner of the subwindow frame.

int r/o modifier - subwindow number

Thanks, shortened, same result, but less code!

Reason: