One more lifehack for access rights: If you have an irresistible desire to give access to private fields/functions of one class to another class, you can do the following using standard MQL tools:
We need to: make access to A::f1() from B
//--------- как былоclass A
{
int m;
int f1() {return m;} // нужно дать к нему доступ классу Bpublic:
A(int a): m(a) {}
};
class B {};
Let's rewrite it like this:
class A;
class B
{
private:
class AB
{
public:
virtualint CallAf1(A&) const = 0;
AB() {ABptr = &this;}
} static *ABptr;
// внутри B используем этот метод для получения доступа к A::f1()staticint CallAf1(A & obj)
{
return ABptr.CallAf1(obj);
}
public:
class AB2: AB {};
// вспомогательный метод - только для проверкиstaticvoid _f1_test(A & obj)
{
Print("test ", CallAf1(obj));
}
};
B::AB *B::ABptr = NULL;
class A
{
int m;
int f1() {return m;}
public:
A(int a): m(a) {}
//-- добавленоprivate:
class AB3: B::AB2
{
int CallAf1(A &obj) const {return obj.f1();}
} staticconst ABlink;
};
const A::AB3 A::ABlink;
To call (A)a.f1() inside B, call CallAf1(a). If f1() has parameters, we add them to CallAf1().
Test:
voidOnStart()
{
A f(2);
B::_f1_test(f);
}
You can make CallAf1() protected, but it will be a big hole in access rights - anywhere in the code you can create a descendant of class B and in it a public method to call CallAf1() - i.e. everyone will have access to A::f1().
P.S. The construct is very cumbersome (if you want, you can cram it into macros), but it has one advantage over friend C++: it gives access not to all class members, but only to selected ones.
One more lifehack for access rights: If you have an irresistible desire to grant access to private fields/functions of one class to another class, you can do this using standard MQL tools
It took me a long time to get into it... good move with virtualisation, thanks!
fxsaber #: Took a long time to get into it... good move with virtualisation, thanks!
The only thing I didn't write at the beginning is that you can't create any more objects of class B::AB2 (and its descendants), otherwise everything will fall apart :-)
Running this Expert Advisor in the Tester in the all symbols mode
inputint inTmp = 0; // https://www.mql5.com/ru/forum/321656/page90#comment_44727856bool Res = true;
// Проверяет, нормализована ли цена по алгоритму NormalizeDouble.bool IsNDPrice( constdouble &Price )
{
return(Price == NormalizeDouble(Price, 5));
}
// Проверяет, нормализована ли цена, как при парсинге или ручном вводе.bool IsNDPrice2( constdouble &Price )
{
return(Price == (double)DoubleToString(Price, 5));
}
voidOnTick()
{
MqlTick Tick;
if (SymbolInfoTick(_Symbol, Tick))
// Res &= IsNDPrice(Tick.bid) && IsNDPrice(Tick.ask); // OnTester == 1.
Res &= IsNDPrice2(Tick.bid) && IsNDPrice2(Tick.ask); // OnTester == 0.
}
doubleOnTester()
{
return(Res);
}
shows that all prices are normalised using the NormalizeDouble algorithm. And that if you work with prices obtained not from the Terminal, but by parsing or manual input, they require normalisation for correct operation. There is no need to be mistaken.
After Deinit, the new EA copy waits for more than a second (up to two seconds) to start. What are the reasons for such a long wait and is it possible to speed it up?
SymbolInfoTick will return the latest tick on each of these three calls. That is, the so-called collection of ticks without skipping through indicators is questionable, to put it mildly.
Proof of the impossibility of collecting ticks by an indicator (without skips).
begDayBar= iBarShift(_Symbol,_Period,begDayTime,false) according to the documentation the function returns -1 or the nearest bar offset depending on the exact parameter.
but today for some reason if begDayTime=2023.01.26 00:00:00 it returns -1 although there are such bars and they are not the last ones.
how to fill an array with one line?
clr_struct clr[] = {{0x999999}, {0x999999}};One more lifehack for access rights: If you have an irresistible desire to give access to private fields/functions of one class to another class, you can do the following using standard MQL tools:
We need to: make access to A::f1() from B
Let's rewrite it like this:
To call (A)a.f1() inside B, call CallAf1(a). If f1() has parameters, we add them to CallAf1().
Test:
You can make CallAf1() protected, but it will be a big hole in access rights - anywhere in the code you can create a descendant of class B and in it a public method to call CallAf1() - i.e. everyone will have access to A::f1().
P.S. The construct is very cumbersome (if you want, you can cram it into macros), but it has one advantage over friend C++: it gives access not to all class members, but only to selected ones.
One more lifehack for access rights: If you have an irresistible desire to grant access to private fields/functions of one class to another class, you can do this using standard MQL tools
Took a long time to get into it... good move with virtualisation, thanks!
REASON_ACCOUNT (even if the account is not changed, but just re-login is done) the Expert Advisor is completely unloaded and a new copy is loaded.
For this reason ExpertRemove in OnDeinit does not affect the new copy, because it touches the unloaded one.
Result after relogin.
After Deinit, the new EA copy waits for more than a second (up to two seconds) to start. What are the reasons for such a long wait and is it possible to speed it up?
SymbolInfoTick will return the latest tick on each of these three calls. That is, the so-called collection of ticks without skipping through indicators is questionable, to put it mildly.
Proof of the impossibility of collecting ticks by an indicator (without skips).
Result.
Forum on Trading, Automated Trading Systems and Testing Trading Strategies
Errors, bugs, questions
fxsaber, 2023.02.14 13:11
Unfortunately, MQL4 does not pull this kind of work yet.
begDayBar= iBarShift(_Symbol,_Period,begDayTime,false) according to the documentation the function returns -1 or the nearest bar offset depending on the exact parameter.
but today for some reason if begDayTime=2023.01.26 00:00:00 it returns -1 although there are such bars and they are not the last ones.
2023.02.15 15:19:23.254 !indDAY_WSOWROhLine (EURRUB_TOM,M15) begDayTime=2023.01.26 00:00:00 endDayTime=2023.01.27 00:00:00 begDayBar=-2 endDayBar=-1 indATR=0 Q5days=0
it may return -1 or it may return the correct bar.