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

 
neverness:

I told you straight out that you shouldn't teach others when you have no idea yourself.

Help should be "qualified", not "from the street"!

Describe the problem again, what is needed.

 
Vitaly Muzichenko:

Re-describe the task again, what exactly is needed.

I am interested in being able to transfer data in MT4/MT5 between different modules.

For example:

How to transfer data from one indicator to another ?

How to transfer data from an indicator to a script ?

How to transfer data from the indicator to the Expert Advisor? etc. ... and so on.

The simple adding of transferred data to a separate file and then reading this data from the file in other modules is quite obvious and common way to transfer it.

But in this case there is a problem of synchronisation of transferred/read data.

Intuitively, I suppose that the MT4/MT5 terminal must have a certain shared buffer memory area and there must be procedures that regulate data exchange through this area.

But I didn't find anything like that in the description.

 
neverness:

I am interested in the MT4/MT5 transfer procedure between different modules.

For example:

How to transfer data from one indicator to another ?

How to transfer data from an indicator to a script?

How to transfer data from the indicator to the Expert Advisor ? etc. ... and so on.

The simple adding of transferred data to a separate file and then reading this data from the file in other modules is quite obvious and common way to transfer it.

But in this case there is a problem of synchronisation of transferred/read data.

Intuitively, I suppose that the MT4/MT5 terminal must have a certain shared buffer memory area and there must be procedures that regulate data exchange through this area.

But I didn't find anything of such kind in the description.

Well, data transfer can be performed through a file or a global variable of the terminal.

If it's a global variable:

// записываем значение, помещаем это всё в OnTick()
GlobalVariableSet("Sname", 123.25);

// Получаем в любой программе эти значения, так-же внутри OnTick()
GlobalVariableGet("Sname"); // получим 123.25

This is the easiest way to exchange between all the programs in one terminal

 
Vitaly Muzichenko:

Well, the data transfer can be through a file, or a global variable of the terminal, as written before

If a global variable:

This is the easiest way to exchange between all the programs in one terminal

Ok. Let's write in indicator an expression:

GlobalVariableSet("Sname", 123.25); This event occurs, for example, onTick().

But scripts do not work with data arrays, and they do not have OnTick() event. How the script knows that the OnTick() event has occurred and should apply the procedure to get new data

GlobalVariableGet("Sname");

You can use OnTimer() event instead of OnTick(). But the script has its own OnTimer(), while indicator has its own one, so they are not related to each other.

Here is the problem:

How to ensure thatGlobalVariableSet("Sname", 123.25); and GlobalVariableGet("Sname"); events are synchronous?

Or is there a procedure which monitors the changing of "Sname" value ? Like OnChange.

That is, how does the script know that the indicator has changed the value of "Sname", and this value has become 125,35 ?

Where is the bridge betweenGlobalVariableSet("Sname", 123.25); and GlobalVariableGet("Sname"); ?

They are in different programs.


 
neverness:

OK. Let's write an expression in the indicator:

GlobalVariableSet("Sname", 123.25); This event occurs, for example, when OnTick().

But scripts do not work with data arrays, and they do not have OnTick() event. How the script knows that the OnTick() event has occurred and should apply the procedure to get new data

GlobalVariableGet("Sname");

You can use OnTimer() event instead of OnTick(). But the script has its own OnTimer(), while indicator has its own one, so they are not related to each other.

Here is the problem:

How to ensure thatGlobalVariableSet("Sname", 123.25); and GlobalVariableGet("Sname"); events are synchronous?

Or is there a procedure which monitors the changing of "Sname" value ? Like OnChange.

That is, how does the script know that the indicator has changed the value of "Sname", and this value has become 125,35 ?

Where is the bridge betweenGlobalVariableSet("Sname", 123.25); and GlobalVariableGet("Sname"); ?

They are in different programs.

The connecting link is a computer hard disk. Record I think the problem is not, and you can get it in any event, even in the script, it does not differ from how you get the current value ASK and BID


P.S. I attach an indicator and script for example, in the indicator we record the tick volumes

Indicator

//+------------------------------------------------------------------+
//|                                                          Set.mq5 |
//|                                                   Copyright 2018 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   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[])
  {
//---
  ArraySetAsSeries(tick_volume,true);
  
  // записываем значение
   GlobalVariableSet("Sname", tick_volume[0]);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Script

//+------------------------------------------------------------------+
//|                                                          Get.mq5 |
//|                                                   Copyright 2018 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    Alert(GlobalVariableGet("Sname"));
  }
//+------------------------------------------------------------------+
Files:
Set.mq5  4 kb
Get.mq5  1 kb
 
Vitaly Muzichenko:

The connecting link is the computer's hard drive. I think it won't be a problem to write it, but you can get it from any event, even in a script, it's no different from how you get the current ASK and BID values

Cool!

And how to do it?

Give me an example.

For example, how to simulate such a case.

The indicator receives data, calculates the variance of the data and prepares ellipse point coordinates for the script (4 global variables Q1,Q2,T1,T2 to be passed to the script).

Now the indicator should give a command to the script that will draw an ellipse using these global variables.

How can the indicator do it?

 
Vitaly Muzichenko:

The connecting link is the computer's hard drive. I think it will not be a problem to record, but you can get it from any event even in the script, it does not differ from how you get the current values of ASK and BID


P.S. I attach an indicator and script for example, in the indicator we record the tick volumes

Indicator

The script

In your example, the script works only once - at start, i.e. when the event OnStart() occurs.

And then how?

Where is the synchronization?

How do you make the script work synchronously with the indicator?

For example, how to enable the script whenever the volumes exceed a certain value?

 
neverness:

So, in your example, the script works only once - at startup, i.e. when the OnStart() event occurs.

And then how?

Where is the synchronization?

How do you make the script work synchronously with the indicator?

For example, how to enable the script whenever the volumes exceed a certain value?

It is your task how to work with the script. Wouldn't it be easier to create an Expert Advisor rather than a script?

An indicator that gives values:

//+------------------------------------------------------------------+
//|                                                          Set.mq5 |
//|                                                   Copyright 2018 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   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[])
  {
//---
  ArraySetAsSeries(time,true);
  ArraySetAsSeries(tick_volume,true);

  // записываем нужные значение
   GlobalVariableSet("Q1", tick_volume[0]);
   GlobalVariableSet("Q2", tick_volume[1]);
   GlobalVariableSet("T1", time[0]);
   GlobalVariableSet("T2", time[1]);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


A simple example of a looped script:

//+------------------------------------------------------------------+
//|                                                          Get.mq5 |
//|                                                   Copyright 2018 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   while(!IsStopped())
    {
     double Q1 = GlobalVariableGet("Q1");
     double Q2 = GlobalVariableGet("Q2");
     datetime T1 = (datetime)GlobalVariableGet("T1");
     datetime T2 = (datetime)GlobalVariableGet("T2");
     Print("Q1 = ",Q1,", Q2 = ",Q2,", T1 = ",TimeToString(T1),", T2 = ",TimeToString(T2));
     Sleep(1000); // Пауза 1 секунда
    }
  }
//+------------------------------------------------------------------+

P.S. Corrected the code.

 
Vitaly Muzichenko:

It is up to you how to work with the script. Wouldn't it be easier for you to create an EA rather than a script?

An indicator that gives values:


A simple example of a looped script:

I understood that in MQL there is no possibility to synchronize different modules.

Ok. Then here's a question. What if I place the button on the field and feed the script to that button?

Is there such a possibility in MQL? Or there is no such a possibility either?

After all, the script must be launched somehow!

 
neverness:

I understand that in MQL there is no possibility to synchronise different modules.

Ok. Then here's a question. What if I place the button on the field and place the script on this button.

Is there such a possibility in MQL? Or there is no such a possibility either?

The script must be launched somehow!

The topic is old, but still read, or maybe someone will suggest something new. I do not run scripts and do not work with them at all)

Как вызвать скрипт из индикатора
Как вызвать скрипт из индикатора
  • 2008.10.15
  • www.mql5.com
Подскажите можноли и как вызвать на выполнение скрипт из индикатора...
Reason: