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

 
Alexey Viktorov #:

Try this

this option does nothing at all - I release the script on the chart and nothing happens.
 
DanilaMactep #:
This option does nothing at all - I release the script on the chart and nothing happens.

Did the declaration of the variable

string tplName = "FIBOmAGIC СРЕДНЕСРОК.tpl";//ИМЯ ПОДГРУЖАЕМОГО ШАБЛОНА

was by any chance deleted?

 
Alexey Viktorov #:

Did the declaration of the variable

was by any chance deleted?

If I did, the compiler would yell unidentified variable. But now I'll try again...
 
Alexey Viktorov #:

Did the declaration of the variable

was by any chance deleted?

I double-checked. The variable isn't deleted. I compile and the script does nothing.
 
DanilaMactep #:
This option does nothing at all - I release the script on the chart and nothing happens.

doesn't that work for you?

//+------------------------------------------------------------------+
//|                                           ChartApplyTemplate.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- покажем окно входных параметров при запуске скрипта
#property script_show_inputs
//----
sinput string Template           = "ADX";          // Имя шаблона(without '.tpl')
sinput ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Период
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long currChart, prevChart = ChartFirst();
   int i = 0, limit = 100;
   bool errTemplate;
   while(i < limit)
     {
      currChart = ChartNext(prevChart);
      if(TimeFrame != PERIOD_CURRENT)
        {
         ChartSetSymbolPeriod(prevChart, ChartSymbol(prevChart), TimeFrame);
        }
      errTemplate = ChartApplyTemplate(prevChart, Template + ".tpl");
      if(!errTemplate)
        {
         Print("Error ", ChartSymbol(prevChart), "-> ", GetLastError());
        }
      if(currChart < 0)
         break;
      Print(i, ChartSymbol(currChart), " ID =", currChart);
      prevChart = currChart;
      i++;
     }
  }
//+------------------------------------------------------------------+
 
137 Matrix #:

doesn't that work for you?

If I'm not mistaken, this is where it all started - it didn't work as I recall ;-) And I don't know where to put the template name in the code either. In short, it's kind of a mess...
 
DanilaMactep #:
If i'm not mistaken, that's how it started and it didn't work as i remember ;-)

I already showed it to you - I don't know why it doesn't work for you - it works for me on both mt4 and mt5.

\\\\\\\\\\\\\\\\\\\\

you can also change the colour of the charts

//+------------------------------------------------------------------+
//|                                       CHART_COLOR_BACKGROUND.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- покажем окно входных параметров при запуске скрипта
#property script_show_inputs
//----
sinput color Backclr = clrWhite; // Цвет фона графика.
sinput color Foreclr = clrBlack; // Цвет осей, шкалы и строки OHLC графика.
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
//--- переменные для идентификаторов графиков
   long currChart, prevChart = ChartFirst();
   int i = 0, limit = 100;
   bool errTemplate;
   Print("ChartFirst = ", ChartSymbol(prevChart), " ID = ", prevChart);
   while(i < limit) // у нас наверняка не больше 100 открытых графиков
     {
      currChart = ChartNext(prevChart); // на основании предыдущего получим новый график
      errTemplate = ChartBackColorSet(Backclr, prevChart);
      errTemplate = ChartForeColorSet(Foreclr, prevChart);
      if(errTemplate)
        {
         Print("Error ", ChartSymbol(prevChart), "-> ", GetLastError());
        }
      if(currChart < 0)
         break;          // достигли конца списка графиков
      Print(i, ChartSymbol(currChart), " ID =", currChart);
      prevChart = currChart; // запомним идентификатор текущего графика для ChartNext()
      i++;// не забудем увеличить счетчик
     }
  }
//+------------------------------------------------------------------+
//| Функция устанавливает цвет фона графика.                         |
//+------------------------------------------------------------------+
bool ChartBackColorSet(const color clr, const long chart_ID = 0)
  {
//--- сбросим значение ошибки
   ResetLastError();
//--- установим цвет фона графика
   if(!ChartSetInteger(chart_ID, CHART_COLOR_BACKGROUND, clr))
     {
      //--- выведем сообщение об ошибке в журнал "Эксперты"
      Print(__FUNCTION__ + ", Error Code = ", GetLastError());
      return(false);
     }
//--- успешное выполнение
   return(true);
  }
//+------------------------------------------------------------------+
//| Функция устанавливает цвет осей, шкалы и строки OHLC графика.    |
//+------------------------------------------------------------------+
bool ChartForeColorSet(const color clr, const long chart_ID = 0)
  {
//--- сбросим значение ошибки
   ResetLastError();
//--- установим цвет осей, шкалы и строки OHLC графика
   if(!ChartSetInteger(chart_ID, CHART_COLOR_FOREGROUND, clr))
     {
      //--- выведем сообщение об ошибке в журнал "Эксперты"
      Print(__FUNCTION__ + ", Error Code = ", GetLastError());
      return(false);
     }
//--- успешное выполнение
   return(true);
  }
//+------------------------------------------------------------------+
 
137 Matrix #:

I already showed it to you - I don't know why it doesn't work for you - it works for me on both mt4 and mt5.

\\\\\\\\\\\\\\\\\\\\

here's another way to change the colour of the charts.

It's just an unavoidable force majeure, it's just a stroke - I might not see something, that's all. But thank you very much for your help.

 
DanilaMactep #:

It's just a force majeure - the aftermath of my stroke - somewhere I might not see something, that's all. But thank you very much for your help.

You don't need to add a .tpl to the code, it's already done for you.

You just need to put in the name of the template.

 Template + ".tpl"

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

sinput string Template           = "ADX";          // Имя шаблона(without '.tpl')
      errTemplate = ChartApplyTemplate(prevChart, Template + ".tpl");
      if(!errTemplate)
        {
         Print("Error ", ChartSymbol(prevChart), "-> ", GetLastError());
        }
 
137 Matrix #:

you don't need to add (.tpl) to the code, it's already prescribed for you.

you just need to enter the name of the template into the .

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I think I've got it figured out - next time, please give me the instruction for use, because you won't understand it without a half a litre)))))) ;-) Thanks so much for the help :-)