Errors, bugs, questions - page 1241

 
barabashkakvn:

The update search is triggered when connecting to the MetaQuotes-Demo server. It is possible in the following cases:

  1. Switching a trading account from some account to a trading account opened on MetaQuotes-Demo;
  2. When restarting the terminal.
Thank you.
 
joo:

:O

No, the error doesn't show up anymore.

Schrodinger was pacing the room looking for a mucked-up kitten, but it was sitting in a box neither dead nor alive. )))

 
tol64:

Schrodinger was pacing the room looking for a mucked-up kitten, but the kitten was sitting in a box neither dead nor alive. )))

Very strange indeed. What's going to stop working next time?
 
joo:
Very strange indeed. What will stop working next time?
There's no telling. We'll have to put a check on it. )
 
joo:

I put the prints in place - the error is gone...

The observer effect in quantum mechanics is something...

We only reproduced your situation when we slipped NaN into the expression.
 
Renat:
We only reproduced your situation when we slipped NaN into the expression.

so does fabs work correctly or not?

 
joo:

is fabs working properly or not?

Correct.
 

Good afternoon, I'm asking for help in implementing what I think is a simple scheme.

I have an EA that works well on one symbol. I want to "tweak" it so it works for several symbols at once. For this, I need to properly create a data array, the members of which could be accessed by all instances of the EA attached to several different symbols. I.e. there is only one data array, but there are multiple instances of the EA. Each EA instance can read and modify array members.

As I understand it, you need to create an array with static members (static).

A simple example: count the total number of ticks in all charts, where the EAs are attached. Let's attach the EA to 2 charts and on the OnTick() event increase the counter by 1. For simplicity, I tried to use a static variable counter instead of the array. Unfortunately, each EA works only with its counter, the counter is not "common". Result:

symbol1, tick1 : counter = 0;

symbol1, tick2 : counter = 1;

symbol2, tick1 : counter = 0; - here expected counter = 2

For example, I created a simple class with a counter:

//+------------------------------------------------------------------+
//|                                                   TestStatic.mqh |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class TestStatic
  {
private:
static int counter;
public:
                     TestStatic();
                    ~TestStatic();

static void IncreaseCounter();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
TestStatic::TestStatic()
  {
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
TestStatic::~TestStatic()
  {
  }
//+------------------------------------------------------------------+
int TestStatic::counter=0;
TestStatic::IncreaseCounter()
  {
   Print("Symbol: "+_Symbol +", counter: "+ TestStatic::counter);
   TestStatic::counter++;
  };

Here is the EA code:

//+------------------------------------------------------------------+
//|                                                Exp_testMulti.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#include <TestStatic.mqh>

static string tickCounter[2][2];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   TestStatic::IncreaseCounter();
    
  }
//+------------------------------------------------------------------+

Please help me to understand it, thank you very much in advance!

 
VangoghFX:

Good afternoon! I'm asking for help in implementing what I think is a simple scheme.

I have an EA that works well on one symbol. I want to "tweak" it so it works for several symbols at once. For this, I need to properly create a data array, the members of which could be accessed by all instances of the EA attached to several different symbols. I.e. there is only one data array, but there are multiple instances of EAs. Each EA instance can read and modify array members.

As I understand it, you need to create an array with static members (static).

A simple example: count the total number of ticks in all charts, where the EAs are attached. Let's attach the EA to 2 charts and on the OnTick() event increase the counter by 1. For simplicity, I tried to use a static variable counter instead of the array. Unfortunately, each EA works only with its counter, the counter is not "common". Result:

symbol1, tick1 : counter = 0;

symbol1, tick2 : counter = 1;

symbol2, tick1 : counter = 0; - here expected counter = 2

For example, I created a simple class with a counter:

Here is the EA code:

Please help me to understand it, thank you very much in advance!

Afternoon. Specifically, to implement your example with ticks, global variables of terminal (there was recently published an article on this topic). About such an array... Not sure, I should try it. But I can suggest another variant. In one Expert Advisor, prescribe the necessary symbols for work and make, as you suggested, a static/global array of necessary data. And let the EA loop through all the required symbols.
 
Tapochun:
Good afternoon. Specifically for your example with ticks, global terminal variables will work (there was an article on this recently). About such an array... I'm not sure, I need to try. But I can suggest another variant. In one Expert Advisor, prescribe the necessary symbols for work and make, as you suggested, a static/global array of necessary data. And let the Expert Advisor loop through all the necessary symbols.

Thank you very much for your reply.

I have used the example with ticks as the simplest and most illustrative one to describe the general idea. The Expert Advisor uses more complex algorithms.

I do not like the variant where N symbols are written in one EA because it is too cumbersome and difficult to use. There are several articles on this topic on the portal, and I've seen them: but I don't like big loops, arrays, copying of data, a lot of packs of variables for each symbol, etc. I want to use a simpler and more efficient, in my opinion, approach: one code of EA for each symbol (the symbol is determined by the chart, to which the EA is linked) - and each copy of the EA works in parallel with other ones. But in this case, the analytical information, which is needed for making decisions, is shared with each other.

The idea of having global variables visited me, but it is more of a procedural approach, and I want to use all the advantages of the OOP. I plan to write a separate class that would pass the necessary analytical data to Expert Advisors in the form of an array and let them make trade decisions.

Reason: