Errors, bugs, questions - page 1439

 
George Merts:

As my experience shows, if the programmer writes something into an array containing 10 items with index 20, it most likely means that he/she made a mistake and the program should generate an error instead of increasing the array's size, thereby hiding a questionable action.

All those "arrays adjusting the size" are much more troublesome in terms of hiding potential errors than convenience. What's more, not having to keep track of an array's size is also a potentially dangerous practice, leading to hard-to-fix bugs.

Is it me, or haven't you worked with the languages in question? You don't have to specify an index to be added at all: it is assigned automatically and the array's size is also increased. The programmer just doesn't have a chance to make a mistake with the index during this operation.

You can implement similar behavior with classes, add the related functions pop, shift, unshift, etc. And drag a wagon of classes from code to code, with each code using %10...20 functions from it. Does this sound like a good solution? An example of right solution in my opinion is adding to ObjectsDeleteAll function the ability to delete by prefix - this is another micron towards higher level programming - and most coders flew into recycle bin so self-made function. Alas, we'll hardly see that with arrays...

 

И таскать телегу классов из кода в код, при том что в каждом коде из неё используются %10..20 функций.

Haven't you heard of include mqh files?
 

No need to write "smart array" classes, they are already in the MetaQuotes Standard Library, see the Arry class family

 
Hello.I'm trying to use MT5 to work with futures via broker "Otkritie".
When accessing the SymbolInfoTick function it turned out that the last two parameters of MqlTick structure
- time_msc, flag are missing. Is it possible to solve this problem? For example, take MT5 from this website,
try to connect it to broker's server. Or it is possible to get the required information in another way.
I'm interested: who initiated the transaction, the seller or the buyer?
 
Alexander Puzanov:

Is it just me, or haven't you worked with the languages in question? You don't have to specify an index to the added element at all, it is assigned automatically and the array's size is also increased. The programmer just doesn't have a chance to make a mistake with the index during this operation

Uhhhh... What chances the programmer has to make a mistake? You are wrong to think that you can take into account all variants of any complex program.

All those "default actions" must be properties of complex objects. Simple objects, such as variables, arrays and simple structures - must have as few "default" properties as possible.

For example, on creation - they must store an undefined value, not zero.

You can implement similar behavior with classes, add related functions pop, shift, unshift etc. And drag a wagon of classes from code to code, with each code using %10...20 functions from it. Does this sound like the right solution?

It's the right solution in terms of logic. When working with such classes - their behavior is transparent.

And what about "dragging a cartload of classes" - when coding you don't drag them, you just plug in the library. And when compiling, a normal linker shouldn't put into an executable all methods from the library, but only those that are used.

Example of right solution in my opinion - adding to ObjectsDeleteAll function delete by prefix - this is another micron towards higher level programming - and most coders have got flew into trash this self-made function. Alas, this is unlikely to happen with arrays...

In my opinion, this is also a wrong approach, for the same reason. The function is loaded with tasks that are not typical of it and do not follow the logic of its application.

The correct solution, it seems to me, is to have a class object manager on the graph that keeps a list of them, and removes the necessary ones as functions are called. The name prefixes, it seems to me, should serve solely to make some information on the object clear to a person. And deletion - should not be based in any way on the name of the object, but on saving that name in an array.

 
Demal:
Hello.I am trying to use MT5 to work with futures via broker "Otkritie".
When accessing the SymbolInfoTick function it turned out that the last two parameters of MqlTick structure
- time_msc, flag are missing. Is it possible to solve this problem? For example, take MT5 from this website,
try to connect it to broker's server. Or it is possible to get the required information in another way.
I am interested: who initiated the transaction, the seller or the buyer?
  1. What build of the terminal do you have now?
  2. Do you connect to a demo or real server?
 
version 5.0 build 1150, demo
 
Demal:
version 5.0 build 1150, demo

Update your terminal (you need to connect to the MetaQuotes-Demo server). Current build:

Terminal        MetaTrader 5 build 1210 started (MetaQuotes Software Corp.)

This is the script:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                              Copyright © 2015, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   MqlTick last_tick;
//--- 
   if(SymbolInfoTick(Symbol(),last_tick))
     {
      Print("time = ",last_tick.time,"; bid = ",last_tick.bid,
            "; ask = ",last_tick.ask,"; volume = ",last_tick.volume,
            "; time_msc = ",last_tick.time_msc,"; flag = ",last_tick.flags);
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());
  }
//+------------------------------------------------------------------+

Gives this result:

Test (RTS-12.15,H1)     time = 2015.11.26 09:42:57; bid = 88360.0; ask = 88400.0; volume = 2; time_msc = 1448530977000; flag = 0

Files:
Test.mq5  2 kb
 
Karputov Vladimir:

Update your terminal (you need to connect to the MetaQuotes-Demo server). Current build:

This is the script:

Gives this result:

Thank you, do you know why the flag has a value of 0, as if nothing has changed?
 
Demal:
Thanks, do you know why the flag has a value of 0, as if nothing has changed
UseCopyTicks and you'll be happy. AndSymbolInfoTick probably doesn't know how to work with the new tick structure yet.
Files:
CopyTicks.mq5  4 kb
Reason: