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

 
Tretyakov Rostyslav #:

The continuestatement transfers control to the beginning of the nearest external while, do-while or for statement.

In my example, the operator return. I was asking for it.

 
JRandomTrader #:

Exits the OnTick function

How will it get out of OnTick if this subroutine is constantly circulating in the EA?
 
Олег Иванов #:
How will it exit from OnTick if this subroutine is constantly circulating in the EA?

That's what will come out of the current run (as if it had reached the end). On the next tick, there will be a new call.

 
JRandomTrader #:

That's what will come out of the current run (as if it had reached the end). On the next tick there will be a new call

I.e. it will return to the beginning of OnTick. thanks, got it.

 
Олег Иванов #:

I.e. will return to the beginning of the OnTick. Thanks, got it.

It will come back with the arrival of the new tick. You can wait a long time for it in the non-liquids.

OnTick is not a forever-type loop, but rather an interrupt operation.
 

Good afternoon, all. Please help me rewrite the script code. Now the script translates all open charts to period n1. How can I rewrite the code so that the script applies a template with the specified name to all open charts?

//| Script program start function                                    |
//+------------------------------------------------------------------+
/********************Script program start function*******************/
void OnStart()
 {
  long prevChart = ChartFirst();
  while(prevChart >= 0)
   {
    if(ChartPeriod(prevChart) != PERIOD_H1)
      ChartSetSymbolPeriod(prevChart, ChartSymbol(prevChart), PERIOD_H1);
    prevChart = ChartNext(prevChart);
   }
 }/******************************************************************/
/*****************************End program****************************/

//+------------------------------------------------------------------+
 
DanilaMactep open charts to period n1. How can I rewrite the code so that the script applies a template with the specified name to all open charts?

Here, this will help you.

ChartApplyTemplate(0,"..........tpl"))
 
Alekseu Fedotov #:

Here, this will help you.

And for a particularly "gifted" person, can you please explain the function
ChartApplyTemplate()
where in the script should be substituted?
 
DanilaMactep #:
And for a particularly "gifted" person, can you please explain the function in which place of the script should be substituted?

here's the script

//+------------------------------------------------------------------+
//|                                           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')
//----
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++;
     }
  }
//+------------------------------------------------------------------+
Files:
 
137 Matrix #:

here's the script

Thanks so much for the code - I'll be adding it to the meta editor tomorrow, it's getting late today.

Reason: