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

 
Valeriy Yastremskiy:

I like the Boolean options better

I'm not quite sure how that applies here.

Can I have my code tweaked, if it's not too much trouble?

      string symbol;
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            if(ChartSymbol(currChart)!=symbol)
              {
               symbol=ChartSymbol(currChart); Print(symbol);
              }
           } 
         currChart=ChartNext(currChart);  i++;
        }
 
Why, Vitaly has written good code. He has i++ in the right place. How does this code work?
 
MakarFX:

Can you tell me how to make Print(), print once on value change

When what value is changed?

 
MakarFX:

I'm not quite sure how this can be applied here

Can my code be tweaked, if you don't mind?

string symbol, printsimbol="";
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            if(ChartSymbol(currChart)!=symbol)
              {
               symbol=ChartSymbol(currChart);if(printsimbol!=symbol) Print(symbol);printsimbol=symbol;
              }
           } 
         currChart=ChartNext(currChart);  i++;
        }
 
MakarFX:

I'm not quite sure how this can be applied here

Can my code be corrected, if it's not too much trouble?

You don't specify the details of where and how this construct is called.

In this case, if you have found the necessary chart and it is the only one, then make a break; immediately, so that you don't force the terminal.

You find the chart, memorize it and don't call the construct again. It's probably best to call it on an event, although it depends on the task.

 
Aleksei Stepanenko:

when what value changes?

When the active chart window changes, the function prints the active chart symbol.

Vitaly Muzichenko:

You do not specify the details of where and how this construct is called.

In this case, if you have found the necessary chart, and there is only one chart, then make a break; so that you do not force the terminal.

You find the chart, memorize it and don't call the construct again. Probably the best way to call it on an event, although it depends on the task.

Sorry, the function is called in the...

//+------------------------------------------------------------------+
//| 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++;
        }
//--- 
  }
Valeriy Yastremskiy:

Unfortunately, it doesn't work either. Prints endlessly(

 
MakarFX:

When the active chart window changes, the function prints the active chart symbol.

Sorry, the function is called in the...

Unfortunately it doesn't work either. It prints infinitely(

How about this? - only it will give a signal once in the print

//+------------------------------------------------------------------+
//|                                                         0001.mq5 |
//|                        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"
int ticks_to_close=1; // количество тиков
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   if(!EventSetTimer(1))
      Alert("Error create timer!");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  }
//+------------------------------------------------------------------+
//| 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);
           {
            if(ticks_to_close>0)
              {
               ticks_to_close--;
               Print(symbol01);
              }
           }
        }
      currChart=ChartNext(currChart);
      i++;
     }
//---
  }
//+------------------------------------------------------------------+
 
SanAlex:

How about this? - only it will give a signal once in the print

Wrong. It prints once at start-up. Doesn't do anything when changing the schedule.
 
MakarFX:

When the active chart window changes, the function prints the active chart symbol.

Sorry, the function is called in the...

Unfortunately it doesn't work either. It prints infinitely(

Or maybe you'd better read the documentation more carefully?

CHART_BRING_TO_TOP

Show 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.
 
MakarFX:

When the active chart window changes, the function prints the active chart symbol.

Sorry, the function is called in the...

Unfortunately it doesn't work either. It prints endlessly(

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

string symbol, printsimbol="";
      long currChart=ChartFirst(); int i=0;
      while(currChart>=0)
        {
         if(ChartGetInteger(currChart,CHART_BRING_TO_TOP,0)==true) 
           { 
            if(ChartSymbol(currChart)!=symbol)
              {
               symbol=ChartSymbol(currChart);if(printsimbol!=symbol) Print(symbol," ",ChartSymbol(currChart)," ",printsimbol,
" ",currChart," ",ChartFirst()," ",ChartNext(currChart)," ",ChartGetInteger(currChart,CHART_BRING_TO_TOP,0));
printsimbol=symbol;
              }
           } 
         currChart=ChartNext(currChart);  i++;
        }