Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1345

 
Vitaly Muzichenko #:

Again, do you need to change the prefix when loading the next copy?

can you say in words what the purpose is?

buttons can be created and controlled from outside your window.


what will it be?

 
Igor Makanu #:

can you say in words what the purpose is?

The buttons can also be created and controlled outside your window.


what would that be?

I don't know, but it should be like this: Create in your subwindow, and when you click, get the number of this subwindow. You don't need to draw anything, just a button that, when clicked, displays information in Alert about the subwindow number

 
Vitaly Muzichenko #:

I don't know, but this is the way to do it: Create in your subwindow, and when you click on it, you get the subwindow number. You don't need to draw anything, just a button that, when clicked, displays information in Alert about the subwindow number

checked on my first source:

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#include <Controls\Button.mqh>
CButton button;

//--- indicator buffers
double         Label1Buffer[];
input int MASlow = 21; // Период медленной МА
input int MAFast = 8;  // Период быстрой МА
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   string short_name = MQLInfoString(MQL_PROGRAM_NAME) + "=Set (" + (string)MASlow + "/" + (string)MAFast + ")";
   IndicatorSetString(INDICATOR_SHORTNAME, short_name);

  // IndicatorSetString(INDICATOR_SHORTNAME, "IndicatorSetString() Demo");
   SetIndexBuffer(0, Label1Buffer, INDICATOR_DATA);
   srand(GetTickCount());
   long c_id = ChartID();
   int c_wf = ChartWindowFind();
   Print(c_id, " / ", c_wf);
   button.Create(c_id, "button" + (string)rand(), c_wf, 10, 10, 100, 100);
   button.Text("Button");
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   for(int i = prev_calculated == 0 ? 0 : prev_calculated - 1; i < rates_total; i++)
   {
      Label1Buffer[i] = close[i];
   }
   return(rates_total);
}
//+------------------------------------------------------------------+


alas, everything is as you wrote - if you run multiple copies of this indicator with default parameters, the button will be only on the first indicator in a subwindow

but if you change the parameters during the start, everything is OK


in general, the situation is unclear

 
Igor Makanu #:

I checked it on my first source:

alas, everything is as you write - if you run several copies of this indicator with default parameters, the button will only be on the first indicator in the subwindow

but if you change the parameters during the start, everything is OK

in general, the situation is unclear

So, here is a question: How to change parameters automatically, without going into settings?

Nothing works so far ...

---

P.S. Ideally, but alas

input long MASlow = TimeLocal(); //
 
Vitaly Muzichenko #:

So far it's not working ...

And it won't:

added in:

int OnInit()
{
   Print(__FUNCTION__);

I put an indicator - I get OnInit in the log, but the next indicator is already silent, i.e. only one copy of the indicator is really running, and the other indicators are just a graphical shell

 
Igor Makanu #:

and it won't work:

added in:

I put the indicator - I get OnInit in the log, but the next indicator is already silent, i.e. only one copy of the indicator is really running, and the other indicators are just a graphical shell

That's how it is. I guess the architecture of mt5 is not right. The mt4 terminal is working fine.

If you have decided to do so in mt5, you would prohibit to run indicator copies with the same input parameters, because it seems to be present but absent.

 
Vitaly Muzichenko #:

That's the way it is. The architecture of mt5 must be a mess. Everything works fine in mt4.

If you decided to do so in mt5, you should have banned the launch of indicator copies with the same input parameters, because it seems to be there, but in fact it is not.

The calculation part of the indicator is not the same as the graphical one. Therefore, the calculation part is the same for all of them. There are several graphical ones.

Can't you just search all sub-windows in one indicator and put labels with sub-window number in them? At the same time to catch in the timer the number of subwindows of the chart: increased - add to a new subwindow label. But also search what indicator is placed in it - if it's different, then don't add...

Just an untested idea.

ZS. I don't agree about the "curvature". One calculation part for 20 identical indicators is better than 20 calculation parts for 20 identical indicators.

 
Artyom Trishkin #:

The calculation part of an indicator is not the same as the graphical part. Therefore, the calculation part is the same for all of them. There are several graphical ones.

Can't we just look for all sub-windows in one indicator, and put labels with sub-window number in them? At the same time to catch in the timer the number of subwindows of the chart: increased - add to a new subwindow label. But also search what indicator is placed in it - if different, then do not add...

Just an untested idea.

ZS. I don't agree about the "curvature". One calculation part for 20 identical indicators is better than 20 calculation parts for 20 identical indicators.

Did, no response to the button - OnChartEvent copy doesn't trigger and doesn't understand the subwindow number.

Anyway, here's what doesn't work and along with it the rest of the code

Forum on Trading, Automated Trading Systems and Strategy Testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Igor Makanu, 2021.09.12 21:53

you don't:

added to:

int OnInit()
{
   Print(__FUNCTION__);

I put an indicator - I get OnInit in the log, but the next indicator is already silent, i.e. only one copy of the indicator is actually running, and the other indicators are just a graphical shell


 
Vitaly Muzichenko #:

Did, no reaction to button - OnChartEvent copy doesn't work and doesn't understand subwindow number.

Anyway, here's what doesn't work and with it the rest of the code


BUT!!! If I make a template with 2-3 of these indicators under the name "Debug.tpl" and start debugging the indicator, then OnInit() works as it should.

In general, I made such an experiment:

I transferred #property to its maximum in OnInit() hoping that while not created indicator will run OnInit() and make a short name for indicator, depending on the number of indicators in the window.

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
//#property indicator_label1  "Label1"
//#property indicator_type1   DRAW_LINE
//#property indicator_color1  clrRed
//#property indicator_style1  STYLE_SOLID
//#property indicator_width1  2
//--- indicator buffers
double         Label1Buffer[];
input int MASlow = 21; // Период медленной МА
input int MAFast = 8;  // Период быстрой МА
//input string shortName = "1";  // Префикс…
long chart_id = ChartID();
string short_name = "";
/********************************************************************\
|           Custom indicator initialization function                 |
\********************************************************************/
int OnInit()
 {
//--- indicator buffers mapping
  long windows_total = ChartGetInteger(chart_id, CHART_WINDOWS_TOTAL);
  short_name = (string)windows_total;
  Print(short_name);
  PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);
  PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrRed);
  PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
  PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 2);
  PlotIndexSetString(0, PLOT_LABEL, "Label1");
  IndicatorSetString(INDICATOR_SHORTNAME, short_name);
  SetIndexBuffer(0, Label1Buffer, INDICATOR_DATA);
  return(INIT_SUCCEEDED);
 }/******************************************************************/

But it didn't help:

I start the first copy

Indicator name 2.........

I start the second copy - indicator name is still 2 for both indicators

I start the debugging and what do I see! The not yet loaded indicator is already printing... read the second and third line...

how can this be?


Further debugging stopped on entry to OnInit(), windows_total variable contains rubbish, short_name is still an empty string...

Hi......... but it's all already printed... how come???

And the short_name has already changed.

As a result, after a full loading of the indicator in debug mode, the indicator has the following names

Perhaps we should draw developers' attention to such bugs...

 
Hello friends, maybe I'm in the wrong place, but I see the section called: "Questions from Beginners MQL5 MT5 MetaTrader 5". So my question is: I used to download Demo EAs from Market for testing now what ever I did MT5 can not download Demo. MT4 without problems, MT5 no what's the reason?
Reason: