Victor, I think the switch is better here - it's faster and more visual.
bool IsOrderType(int type)
{
switch (type)
{
case OP_BUY:
case OP_SELL:
case OP_BUYLIMIT:
case OP_SELLLIMIT:
case OP_BUYSTOP:
case OP_SELLSTOP:
return (true);
}
return (false);
}
Oh, by the way -- reasonable optimization of work in the tester -- I've been using it lately.
int FindLastOpenTime(int tip, int imagic)
{
int Res=-1;
int lOrderOpenTime=-1;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != imagic) continue;
if (!(tip==-1 || isOrderType(tip))) continue;
if (IsTesting()) return (OrderTicket()); // тутif (lOrderOpenTime==-1) {
lOrderOpenTime=OrderOpenTime();
Res=OrderTicket();
} elseif (lOrderOpenTime<OrderOpenTime()) {
lOrderOpenTime=OrderOpenTime();
Res=OrderTicket();
}
}
return (Res);
}
By the way, the function is called FindLastOpenTime and returns a ticket.
May be it is better so?
datetime FindLastOpenTime(int tip, int imagic, int& ticket)
{
//...
}
By the way, the function is called FindLastOpenTime, ...
The idea is that
if (lOrderOpenTime<OrderOpenTime()) {
lOrderOpenTime=OrderOpenTime();
Res=OrderTicket();
}
it may start working right at -1, I'm not quite sure why it needs an external if...else. Return, imho, is really better lOrderOpenTime, then return -1 will allow to catch the error.
always killed the logic of such a construction in cyclic operands :
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != imagic) continue; if (!(tip==-1 || isOrderType(tip))) continue;
see help :
The continue statement transfers control to the beginning of the nearest external while or for statement, causing the beginning of the next iteration. This operator is the opposite of break.
It is not clear at all, and if an order doesn't pass the conditions then what? Exit the loop? if continue operator is directly opposite to break operator ...
For me, the standard logic is clearer and more understandable :
int FindLastOpenTime(int type, int imagic){int time = 0;
for(int i = OrdersTotal() -1 ;i>=0;i--){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderSymbol()==Symbol()){
if(OrderType()==type){
if(OrderMagicNumber()==magic){
if(OrderOpenTime()>time){
time=OrderOpenTime();
}
}
}
}
}
}
return(time);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Victor, I think the switch is better here - it's faster and more visual.
Oh, by the way -- reasonable optimization of work in the tester -- I've been using it lately.
By the way, the function is called FindLastOpenTime and returns a ticket.
May be it is better so?
Victor, I think the switch is better here - it's quicker and clearer.
It's really clearer.
TheXpert:
By the way, the function is called FindLastOpenTime, ...
if (lOrderOpenTime<OrderOpenTime()) { lOrderOpenTime=OrderOpenTime(); Res=OrderTicket(); }it may start working right at -1, I'm not quite sure why it needs an external if...else. Return, imho, is really better lOrderOpenTime, then return -1 will allow to catch the error.is it logical to use this kind of thing?
always killed the logic of such a construction in cyclic operands :
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != imagic) continue;
if (!(tip==-1 || isOrderType(tip))) continue;
see help :
The continue statement transfers control to the beginning of the nearest external while or for statement, causing the beginning of the next iteration. This operator is the opposite of break.
It is not clear at all, and if an order doesn't pass the conditions then what? Exit the loop? if continue operator is directly opposite to break operator ...
For me, the standard logic is clearer and more understandable :
Puncture #2. Logic (logic) and brevity have little correlation.
A prime example right out of MQL, which, by the way, many people are not squeamish about using.
This is not logic -- it's a murder of logic. In addition, it is a potential breeding ground for implicit errors.
Not sure where the puncture is? And why the second one? If it is the second, where is the first?
For those who don't have an office or zip.
Dima add something for those who don't have metaeditor.exe :-)
Victor, congratulations again !