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

 
Yevhenii Levchenko:
How to set a time filter (by hours) for EA trading? Will the following option work:

YOU google (time limitation of the EA - for example) - there may be special features, e.g. bidding from 22:00 hr to 04:00 hr. In Kim I.V.'s fonts Subject: Only useful fonts from Kim - have a look.

Here's an option:

extern int HourStart=2;
// время начала работы советника в часах по времени терминала - может быть от 0 до 23
extern int HourEnd=22;
// время окончания работы советника в часах по времени терминала
// пример - советник начинает работать в 2 часа 0 минут, заканчивает работу в 22, то есть в 22 часа и после советник не выставляет новых ордеров и ждет рабочего времени - 2 часа
extern bool Use_Time=false;

...

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  { 
   bool time_trade=false;
   if(Use_Time==false) {time_trade=true;}
   if(Use_Time==true && Hour()>=HourStart && Hour()<HourEnd) {time_trade=true;}

...
   
 
Roman Shiredchenko:

YOU google it - there may be special features, e.g. bidding from 22:00 hrs to 04:00 hrs. In Kim's f.i.v. Topic: Only useful f.i.v.'s from Kim - have a look.

Here is an option:

Wow what a cool theme there ! Thank you!


And what I've done won't work?
 
Yevhenii Levchenko:

Wow what a cool theme there ! Thank you!


And what I've done won't work?

Yeah dunno - get it ready and use it, figure out what's right. Bicycles have all been invented, IMHO.

 
Yevhenii Levchenko:
How do I set the time filter (by hours) for EA trading? Would the following option work:

We discussed this some time ago, here's a topic, my examples all work, I use it, everything works in MT4https://www.mql5.com/ru/forum/317351


Yevhenii Levchenko:

What are the specifics of using Symbol() and _Symbol ?

Would the following code work correctly to check the presence of orders for the current symbol ?

No, Symbol() is an old way to get symbol name, the latest builds for MQL4 - MQL5 compatibility have added _Symbol

If you write code from scratch, use _Symbol, if you want to port the code to MQL5, you'll have less to edit it.

 
Igor Makanu:

We discussed this some time ago, here's a topic, my examples all work, I use it, everything works in MT4https://www.mql5.com/ru/forum/317351


No, Symbol() is an old way to get symbol name, the latest builds for MQL4 - MQL5 compatibility have added _Symbol

If you write code from scratch, use _Symbol, if you want to port the code to MQL5, you'll have less to edit it.

Thank you!

The code, of course, is much bigger than what I tried to prescribe... :) I'll have to sit and figure it out...
 
Igor Makanu:

We discussed this some time ago, here's a topic, my examples all work, I use it, everything works in MT4https://www.mql5.com/ru/forum/317351


No, Symbol() is an old way to get symbol name, the latest builds for MQL4 - MQL5 compatibility have added _Symbol

If you write code from scratch, use _Symbol, if you want to port the code to MQL5, you'll have less to edit it.

The difference is different. _Symbol is a predefined variable and Symbol() is a function.

Both work there and there. Everything is exactly the same. But once upon a time, one of the developers (I don't remember which one) said that it was preferable to use a function.

 

Forum on trading, automated trading systems and testing trading strategies

What is different between Symbol() and _Symbol

fxsaber, 2019.07.07 14:47

void Func( const string& ) {}

void OnStart()
{
  Func(Symbol()); // ERROR: 'Symbol' - parameter passed as reference, variable expected
  Func(_Symbol);  // OK   
}
 
Artyom Trishkin:

The difference is different. _Symbol is a predefined variable and Symbol() is a function.

Both work both ways. Everything is absolutely identical. But some time ago one of the developers (can't remember who exactly) said that it was preferable to use a function.

I think the best way to use it, I looked through the help, there is no definite recommendation from the developers

In practice, in some libraries the developers override Symbol() in class methods, in MQL5 I also overrode Symbol() method for custom TF in my class .... If it's convenient, I use it that way, I don't see any offence by the book axioms ))))

SZZ: I think it's already a religion... iClose() function should not be used - "it's a fake!" (С)

then here's a new trend _Symbol is worse than Symbol() ...measured the speed just in case, no difference at all, same work

#property strict
//+------------------------------------------------------------------+
#define    test(count_x10,msg,EX)        {uint mss=GetTickCount(); ulong count=(ulong)pow(10,count_x10);for(ulong i=0;i<count&&!_StopFlag;i++){EX;} \
                                printf("%s: loops=%i ms=%u",msg,count,GetTickCount()-mss);}

//+------------------------------------------------------------------+
void OnStart()
  {
   Print("test 1:"); srand(GetTickCount()); test(9,"_Symbol",string s=_Symbol+IntegerToString(rand()));
   Print("test 2:"); srand(GetTickCount()); test(9,"Symbol()",string s=Symbol()+IntegerToString(rand()));
   Print("test 3:"); srand(GetTickCount()); test(9,"_Symbol",string s=_Symbol+IntegerToString(rand()));
   Print("test 4:"); srand(GetTickCount()); test(9,"Symbol()",string s=Symbol()+IntegerToString(rand()));
   Print("test 5:"); srand(GetTickCount()); test(9,"_Symbol",string s=_Symbol+IntegerToString(rand()));
   Print("test 6:"); srand(GetTickCount()); test(9,"Symbol()",string s=Symbol()+IntegerToString(rand()));
  }
//+------------------------------------------------------------------+

2019.08.09 00:54:20.631 tst EURUSD,H1: Symbol(): loops=1000000000 ms=66203

2019.08.09 00:53:14.432 tst EURUSD,H1: test 6:

2019.08.09 00:53:14.432 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65515

2019.08.09 00:52:08.921 tst EURUSD,H1: test 5:

2019.08.09 00:52:08.921 tst EURUSD,H1: Symbol(): loops=1000000000 ms=65610

2019.08.09 00:51:03.301 tst EURUSD,H1: test 4:

2019.08.09 00:51:03.301 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65890

2019.08.09 00:49:57.418 tst EURUSD,H1: test 3:

2019.08.09 00:49:57.418 tst EURUSD,H1: Symbol(): loops=1000000000 ms=65563

2019.08.09 00:48:51.850 tst EURUSD,H1: test 2:

2019.08.09 00:48:51.850 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65750

2019.08.09 00:47:46.105 tst EURUSD,H1: test 1:

 
Igor Makanu:

I think you should use whatever is more convenient. I looked through the reference, there are no definite recommendations from the developers

In practice, in some libraries the developers override Symbol() in class methods, I also overrode Symbol() method for custom TF in MQL5 .... If it's convenient, I use it that way, I don't see any offence by the book axioms ))))

SZZ: I think this is a religion... iClose() function should not be used - "it's a fake!" (С)

then here's a new trend _Symbol is worse than Symbol() ...measured the speed just in case, no difference at all, same work

2019.08.09 00:54:20.631 tst EURUSD,H1: Symbol(): loops=1000000000 ms=66203

2019.08.09 00:53:14.432 tst EURUSD,H1: test 6:

2019.08.09 00:53:14.432 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65515

2019.08.09 00:52:08.921 tst EURUSD,H1: test 5:

2019.08.09 00:52:08.921 tst EURUSD,H1: Symbol(): loops=1000000000 ms=65610

2019.08.09 00:51:03.301 tst EURUSD,H1: test 4:

2019.08.09 00:51:03.301 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65890

2019.08.09 00:49:57.418 tst EURUSD,H1: test 3:

2019.08.09 00:49:57.418 tst EURUSD,H1: Symbol(): loops=1000000000 ms=65563

2019.08.09 00:48:51.850 tst EURUSD,H1: test 2:

2019.08.09 00:48:51.850 tst EURUSD,H1: _Symbol: loops=1000000000 ms=65750

2019.08.09 00:47:46.105 tst EURUSD,H1: test 1:

As the saying goes - what you buy, you sell for. The recommendation was not in the documentation, but from word of mouth on the forum.

 
Igor Makanu:

Why is the last line without a slash, and is it possible to return a value from a macro

#define  FOR3(a,b,c,loop) for(int i=0; i<a; i++) \
for(int j=0; j<b; j++) \
for(int k=0; k<c; k++) \
{loop;} 
Reason: