Features of the mql5 language, subtleties and tricks - page 196

 
fxsaber:

No suggestion as to where the hour comes from (the same for me). Perhaps it depends on the time zone.


This is no longer interesting.

No guesses. I have Moscow. With GMT not an hour... No other thoughts.

 

Andrey Khatimlianskii:

Forum on trading, automated trading systems and trading strategy testing

How to use automatic error monitoring in the terminal?

Renat Fatkhullin, 2021.01.22 16:12

There is an undocumented way to forcibly reset logs to disk through Print(NULL)

Cool!

 
Andrey Khatimlianskii:

fxsaber:

Cool!

In a hurry to share without checking.

 
Andrey Khatimlianskii:

In my haste to share without checking.


What if the string is zeroed in first and then printed
 

Option to show (not activate) the chart (MT5 only)

// Показывает (не активирует) данный чарт.
bool ChartShow( const long Chart )
{
  const bool IsDocked = ChartGetInteger(Chart, CHART_IS_DOCKED);
  
  return(ChartSetInteger(Chart, CHART_IS_DOCKED, !IsDocked) && 
         ChartSetInteger(Chart, CHART_IS_DOCKED, IsDocked) &&
         ChartGetInteger(Chart, CHART_WINDOW_HANDLE));  
}


Example usage.

// Переключает чарты клавишами клавиатуры '<'/'>'.

#define  KEY_LEFT2 188  // '<'
#define  KEY_RIGHT2 190 // '>'

int GetExpertCharts( long &Charts[], const string ExpertName = NULL )
{
  int Amount = 0;
  
  for (long Chart = ChartFirst(); Chart != -1; Chart = ChartNext(Chart))
    if ((ExpertName == NULL ) || (ChartGetString(Chart, CHART_EXPERT_NAME) == ExpertName))
    {
      Amount = ArrayResize(Charts, Amount + 1, 10);
      
      Charts[Amount - 1] = Chart;
    }
    
  return(ArrayResize(Charts, Amount));
}

long ChartNextShow( const long Chart, const int Step = 1 )
{
  long ResChart = Chart;
  
  long Charts[];  
  const int Size = GetExpertCharts(Charts);
  
  if ((Size > 1) && (bool)(Step % Size))
    for (int i = 0; i < Size; i++)  
      if (Charts[i] == Chart)
      {
        ResChart = Charts[(i + ((Step > 0) ? Step : (Size - ((-Step) % Size)))) % Size];
        
        ChartShow(ResChart); // https://www.mql5.com/ru/forum/170952/page196#comment_20841674
        
        break;
      }

  return(ResChart);  
}

void OnChartEvent( const int id, const long &lparam, const double&, const string& ) 
{         
  static long Chart = ChartID();
  
  if (id == CHARTEVENT_KEYDOWN) 
    switch ((int)lparam)
    {
    case KEY_LEFT2:
      Chart = ChartNextShow(Chart, -1); // Показали чарт слева
      break;

    case KEY_RIGHT2:
      Chart = ChartNextShow(Chart); // Показали чарт справа
      break;
    }
}

Unfortunately, no chart activation option could be found. Only display.

 
Solution to an old problem.
/*
// https://www.mql5.com/ru/forum/1111/page2863#comment_18591240
#define VALUE 10

#define MACROS

#ifdef MACROS
  // Нужно VALUE увеличить в два раза.
#endif
*/

// https://www.mql5.com/ru/forum/1111/page2965#comment_20841725
#define  MACRO(  x, y, z )       enum nn##z { y = x };
#define  MACRO2( x, y )          MACRO( x, y, __LINE__ )

// https://www.mql5.com/ru/forum/1111/page2866#comment_18603128
#define  VALUE 10

MACRO2(VALUE, VALUE_TMP) // VALUE_TMP - поле enum, поэтому имя не должно повторяться.
#undef  VALUE
#define  VALUE (VALUE_TMP * 2)

void OnStart()
{
  Print(VALUE);
}

This option is better than this one.

#define  MACRO3(x, y)            const int y = x;

MACRO3(VALUE, VALUE_TMP)

It does not need a variable. All values are set at compile time. Thank you @A100!

 
fxsaber:

Unfortunately, no chart activation option could be found. Only the display.

I don't understand......... is that what you're talking about? It's a script.


ps; And what is this

  const bool IsDocked = ChartGetInteger(Chart, CHART_IS_DOCKED);

I can't find it in the documentation...

Files:
200.mq5  2 kb
 
Alexey Viktorov:

ps; What is this

I can't find it in the documentation...

It's ALT+D on the chart.

 
Alexey Viktorov:

I don't get it......... is that what you're talking about? It's a script.

Thanks, something I overdid. Of course, above got the chart management that couldn't be achieved before. But my goal was different.

// Активирует данный чарт.
bool ChartActivate( const long Chart )
{
  return(ChartSetInteger(Chart, CHART_BRING_TO_TOP, true) && ChartGetInteger(Chart, CHART_WINDOW_HANDLE));
}


Example of use.

// Переключает чарты с одним и тем же советником клавишами клавиатуры '<'/'>'.

void ChartNextActivate( const int Step = 1, const bool Expert = true )
{
  long Charts[];  
  // https://www.mql5.com/ru/forum/170952/page196#comment_20841674
  const int Size = GetExpertCharts(Charts, Expert ? ChartGetString(0, CHART_EXPERT_NAME) : NULL);
  const long Chart = ChartID();
  
  if ((Size > 1) && (bool)(Step % Size))
    for (int i = 0; i < Size; i++)  
      if (Charts[i] == Chart)
      {
        // https://www.mql5.com/ru/forum/170952/page197#comment_20845067
        ChartActivate(Charts[(i + ((Step > 0) ? Step : (Size - ((-Step) % Size)))) % Size]);
        
        break;
      }

  return;  
}

void OnChartEvent( const int id, const long &lparam, const double&, const string& ) 
{         
  if (id == CHARTEVENT_KEYDOWN) 
    switch ((int)lparam)
    {
    case KEY_LEFT2:
      ChartNextActivate(-1);
      break;

    case KEY_RIGHT2:
      ChartNextActivate();      
      break;
    }
}
Reason: