Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1419

 
Alexey Viktorov:

Wouldn't it be better to read the documentation more carefully?

CHART_BRING_TO_TOP

Display chart on top of all other charts

bool w/o


This means that this property is write-only. And you are trying to read it.........

Plus you are not giving a complete answer to the question

It is a script or an indicator.
It is an indicator. And it prints the result immediately when the window changes, i.e. it can read.
 
Valeriy Yastremskiy:

And I don't understand the point of the wail. The condition is always true.

The condition is always true, but the number of graphs is not known

 
Valeriy Yastremskiy:

If I don't understand what's going on, I print everything I have, sometimes it helps. And I don't understand the point of the vail. The condition is always true.

If anything, it has to be done statically, otherwise it resets

string symbol, printsimbol="";
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
 
MakarFX:
It is an indicator. And it immediately prints the result when the window changes, i.e. it can read.

Don't you think it reads like gibberish? Though unchangeable, it's still gibberish.

Try to print it out when the schedule changes. Then it is important to know how the active chart changes. If the indicator is on the far left chart, do you switch to the next one on the right, then switch to the one on the far right and so chaotically switch? Or do you just need to trace the exit from the chart where the indicator is and return to it?

 
Alexey Viktorov:

Don't you think it reads like gibberish? Though unchangeable, it's still gibberish.

Try to print it out when the schedule changes. Then it is important to know how the active chart changes. If the indicator is on the far left chart, do you switch to the next one on the right, then switch to the one on the far right and so chaotically switch? Or do you just need to trace leaving the chart where the indicator is and returning to it?

I do not know what reads, but it prints what you need

2021.03.16 09:33:25.650 Label USDCHF,M15: EURGBP
2021.03.16 09:33:25.148 Label USDCHF,M15: EURGBP
2021.03.16 09:33:24.647 Label USDCHF,M15: EURGBP
2021.03.16 09:33:24.145 Label USDCHF,M15: GBPCHF
2021.03.16 09:33:23.644 Label USDCHF,M15: GBPCHF
2021.03.16 09:33:23.142 Label USDCHF,M15: GBPCHF
2021.03.16 09:33:22.641 Label USDCHF,M15: USDCHF
2021.03.16 09:33:22.155 Label USDCHF,M15: USDCHF
2021.03.16 09:33:21.654 Label USDCHF,M15: USDCHF
2021.03.16 09:33:21.152 Label USDCHF,M15: EURGBP
2021.03.16 09:33:20.651 Label USDCHF,M15: EURGBP
2021.03.16 09:33:20.149 Label USDCHF,M15: EURGBP

It works on any chart (leftmost, rightmost, middle) and on any order of chart switching

Try

//+------------------------------------------------------------------+
//|                                                        Label.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetMillisecondTimer(500);
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
      string symbol01;
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            symbol01=ChartSymbol(currChart);      Print(symbol01);
           } 
         currChart=ChartNext(currChart);  i++;
        }
//--- 
  }
//+----------------------------------------------------------------------------+
 

Made it this way

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            symbol01=ChartSymbol(currChart);
           } 
         currChart=ChartNext(currChart);  i++;
        }
   PrintLabel();
//--- 
  }
//+----------------------------------------------------------------------------+
void PrintLabel()
  {
   if(symbol02!=symbol01){symbol02=symbol01; Print(symbol02);}
   return;
  }

Result

2021.03.16 10:00:05.075 Custom indicator Label USDCHF,M15: removed
2021.03.16 10:00:05.060 Label USDCHF,M15: uninit reason 1
2021.03.16 10:00:00.046 Label USDCHF,M15: USDCHF
2021.03.16 09:59:55.486 Label USDCHF,M15: EURCAD
2021.03.16 09:59:54.498 Label USDCHF,M15: CADCHF
2021.03.16 09:59:53.511 Label USDCHF,M15: EURGBP
2021.03.16 09:59:52.994 Label USDCHF,M15: GBPCHF
2021.03.16 09:59:51.991 Label USDCHF,M15: EURUSD
2021.03.16 09:59:48.945 Label USDCHF,M15: USDCHF
2021.03.16 09:59:48.428 Label USDCHF,M15: initialized
2021.03.16 09:59:47.046 Custom indicator Label USDCHF,M15: loaded successfully

Thank you all for your help!!!

 
MakarFX:

I don't know what reads, but it prints what it needs to

Works on any chart (leftmost, rightmost, middle) and on any order of chart change

Try

Reads 1 or 0. I don't know how accurate it is, but it surprisingly works...

Then here is a ready solution

/***************************Timer function***************************/
void OnTimer()
 {
  static long chart_ID = 0;
  string symbol01;
  long currChart = ChartFirst();
  while(currChart >= 0)
   {
    if(chart_ID != ChartGetInteger(currChart, CHART_WINDOW_HANDLE) && ChartGetInteger(currChart,CHART_BRING_TO_TOP,0) == 1)
     {
      chart_ID = ChartGetInteger(currChart, CHART_WINDOW_HANDLE);
      symbol01 = ChartSymbol(currChart);
      Print(symbol01, " ", EnumToString(ChartPeriod(currChart)), " ", chart_ID);
     }
    currChart = ChartNext(currChart);
   }
 }/*******************************************************************/
 
MakarFX:

Made it this way

Result

Thank you all for your help!!!

If there are two graphs of the same character or more,


it won't work.

 
MakarFX:

I don't know what reads, but it prints what it needs to

Works on any chart (leftmost, rightmost, middle) and on any order of chart change

Try

void OnTimer()
{
   long currChart=0,prevChart=ChartFirst();
   int i=0,limit=100;
   static long CurrID;
   while(i<limit) { // у нас наверняка не больше 100 открытых графиков
      currChart=ChartNext(prevChart); // на основании предыдущего получим новый график
      if(ChartGetInteger(currChart,CHART_BRING_TO_TOP))
         break;
      if(currChart<0) break;          // достигли конца списка графиков
      prevChart=currChart;// запомним идентификатор текущего графика для ChartNext()
      i++;// не забудем увеличить счетчик
   }
   if(CurrID!=currChart) {
      Print(ChartSymbol(currChart));
      CurrID=currChart;
   }
}


P.S. While writing, the codes have already sketched :)

 
Alexey Viktorov:

It reads 1 or 0. I don't know how reliable it is, but it surprisingly works...

Then here's the solution.

It works, thanks.

Vitaly Muzichenko:


P.S. While writing this, the code has already been written :)

Skips first chart window.

Alexey Viktorov:

If there will be two charts of the same character or more,

it won't work

It just works the way it should. The point is to print if a character changes!

Reason: