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

 
137 Matrix #:

here's the script

Good afternoon. Transferred the code to the script like this.
//+------------------------------------------------------------------+//+------------------------------------------------------------------+
//|                                           ChartApplyTemplate.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "АВТОР - КОПИЯ 1"
#property link      "https://vk.com/danila_mastep"
#property version   "1.00"
//--- покажем окно входных параметров при запуске скрипта
#property script_show_inputs
//----
sinput string Template = "default"; // Имя шаблона(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++;
     }
  }
//+------------------------------------------------------------------+

When I drag and drop it on the chart and enter the template name in the input parameters, the terminal stops responding and nothing happens. The templates are not applied to all charts :-( Did I copy the code incorrectly or there is a problem with something else? I double-checked the name of the template - I enter only the name without the dot tpl
 
DanilaMactep #:
Hello. I put the code in the script like this.
When I drag and drop it on the chart and enter the template name in the input parameters, the terminal stops responding and nothing happens. The templates are not applied to all charts :-( Did I copy the code incorrectly or there is a problem with something else? I double-checked the name of the template - I enter only the name without the dot tpl

enter the name and this template will open on all open charts.

for example - save the template with the name template and write the template in the script settings

 
DanilaMactep #:
Good afternoon. I have transferred the code to the script like this.
When I drag and drop it on the chart and enter the template name in the input parameters, the terminal stops responding and nothing happens. The templates are not applied to all charts :-( Did I copy the code incorrectly or there is a problem with something else? I double-checked the name of the template - I enter only the name without the dot tpl

All you had to do was add one line to your code. Or even replace two lines with one

string tplName = "name.tpl";
/********************Script program start function*******************/
void OnStart()
 {
  long prevChart = ChartFirst();
  while(prevChart >= 0)
   {
    //if(ChartPeriod(prevChart) != PERIOD_H1)
    //  ChartSetSymbolPeriod(prevChart, ChartSymbol(prevChart), PERIOD_H1);
    ChartApplyTemplate(prevChart, tplName);
    prevChart = ChartNext(prevChart);
   }
 }/******************************************************************/
/*****************************End program****************************/
 

Good afternoon! The situation is as follows: I have two identical charts open in the terminal. One robot is installed on one and the other one on the other one. How can I register in the code (if it is possible), so that the position opened by robot 1 is also opened in the chart where robot 2 is placed? Or better yet, how to make robot-1 open a position only on the chart with Robot-2? My "knowledge" is not enough.

My "knowledge" is not enough. Thank you.

 
novichok2018 #:

Good afternoon! The situation is as follows: I have two identical charts open in the terminal. One robot is installed on one and the other one on the other one. How can I register in the code (if it is possible), so that the position opened by robot 1 is also opened in the chart where robot 2 is placed? Or better yet, how to make robot-1 open a position only on the chart with Robot-2? My "knowledge" is not enough.

My "knowledge" is not enough. Thank you.

If the charts are the same, the orders are visible on both. Orders are opened by the symbol, not by the chart.
 
Alexey Viktorov #:

All you had to do was add one line to your code. Or even replace two lines with one

Alexey, thanks a lot for the tip - added lines and everything worked, the only problem - now even when manually selecting the default template the terminal hangsXD))))))))) seems it's time to clean the computer, but there are signs of failures (
 
Tretyakov Rostyslav #:
If the charts are the same, the orders are visible on both of them. Orders are opened on the symbol, not on the chart.

This is understandable, but I need the order not just to be visible on the second chart, but to open on it. It is not necessary that it opens on the first chart. It would seem why, because I could simply combine two codes into one and then there would be no need to open the second chart, but the thing is that the second robot is someone else's and I don't have access to its code.

 

Hi all!

How can I make all the charts in MT4 (and I have 9 of them open at the same time) switch quickly from light to dark background and back?

 
DanilaMactep #:
Aleksey, thanks a lot for the tip - added lines and everything worked, only problem - now even when manually selecting the default template the terminal hangsXD))))))))) looks like it's time to clean computer, but there are signs of trouble(

Not sure when it hangs, from what actions... but I noticed a small error in the code. No flag to force script shutdown.

We need to fix the loop line

  while(prevChart >= 0 && IsStopped())
 
novichok2018 #:

This is understandable, but I need the order not just to be visible on the second chart, but to open on it. It is not necessary that it opens on the first chart. You would think that I don't really need it because I could just merge the two codes into one and then the second chart would not have to be opened.

The orders are not opened on the chart!!!

You explain the essence of the problem. Is it necessary for one EA to open orders and the other to accompany?

Reason: