Libraries: TradeTransactions - page 2

 
Sergey Chalyshev:

So far I can't think of a use for this library.

It is definitely not needed on forex, and there is no need for it on the stock exchange.

If you are talking about partial execution, it works in full swing on Forex. In particular, that is why asynchrony is very much in demand at Forex, and therefore this library can be useful.

Have you tested this library on the stock exchange?

I haven't tested it on the stock exchange, but the stock exchange and forex are technically the same for the library. You just get data about all transactions anywhere you want, whenever you want. That's all there is to it. So nothing depends on the type of market here.

In what case do you think it will be useful?

The library will come in handy when asynchrony comes in handy. This is any mass (more than one) sending of trade orders. There can be many scenarios:

  • Opening/modifying/closing a character basket.
  • Griders.
  • Working with the results of partial executions.
  • Closing all positions and deleting all orders.
  • ...
 
fxsaber:

It is necessary to experiment. I think that simultaneous writing/reading of a resource works the same way as with global variables, because writing in both cases is creation: ResourceCreate and GlobalVariableSet. The only difference between a resource and a global is that you cannot even theoretically write anything to a resource at the same time. With global variables it is possible.


In fact, reading a resource is getting a piece of data from memory. And if reading has started, writing a resource should not affect it, because writing is allocating another piece of memory. They can hardly overlap because the OS itself will most likely prevent them from doing so. That's why, from my point of view, there should be no load/save conflicts with resources. But of course it is better to ask the developers this question.

Isn't a resource with the same name the same resource (and a piece of memory, respectively)?

It's easy to check - you should write something long with a special mark at the end and read it in parallel. If not a whole message will be read, it means there may be a conflict.

 
Andrey Khatimlianskii:

Isn't a resource with the same name the same resource (and chunk of memory, respectively)?

Writing is creating another resource.

It is easy to check - you should write something long with a special mark at the end and read it in parallel. If not a whole message will be read, then there may be a conflict.

#property script_show_inputs

input bool Save = true; // Save/Load

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166

#define  MINLENGTH 100000
#define _CS(A) ((!::IsStopped()) && (A))

void OnStart()
{  
  const RESOURCEDATA<int> Resource("::Test");
  int Array[];            

  while (_CS(true))
    if (Save)
      for (int i = 0; _CS(i < MINLENGTH); i++)    
      {
        const int Size = ArrayResize(Array, i + MINLENGTH);
        
        Array[Size - 1] = Size;
        
        Resource = Array;
      }
    else
    {
      ArrayResize(Array, 0);      
      const int Size = Resource.Get(Array);
      
      if (!Size || (Array[Size - 1] != Size))
      {
        Print(Size);
        
        break;
      }
    }        
}


This test script shows that there is no conflict.

 
fxsaber:

Recording is the creation of another resource.

This verification script shows that there are no conflicts.

I had something like that in mind:

#property script_show_inputs

input bool Save = true; // Save/Load

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166

#define  MINLENGTH 100000

void OnStart()
{  
        const RESOURCEDATA<int> Resource("::Test");
        int Array[];            
        string str = "";
        for ( int i = 0; i < MINLENGTH; i ++ ) str += (i%1000==0?"\n":"a");
        str += "\nCHECK";

        while ( !::IsStopped() )
    if (Save)
    {
        char arr[];
        StringToCharArray( (string)GetTickCount() + "\n" + str, arr );
        ArrayResize(Array, ArraySize(arr));
        ArrayCopy( Array, arr );
        Resource = Array;
    }
    else
    {
      ArrayResize(Array, 0);
      const int Size = Resource.Get(Array);
      char get[]; ArrayResize( get, Size );
      ArrayCopy( get, Array );
      string res = CharArrayToString( get );
      uint start = (uint)StringToInteger( StringSubstr( res, 0, StringFind( res, "\n" ) ) );
      Comment( "Delay = ", (GetTickCount() - start), " ms\n", res );
      if ( StringSubstr( res, StringLen( res )-5, 5 ) != "CHECK" ) { Print( res ); break; }
    }
}

It really doesn't seem to be lost.

 
Andrey Khatimlianskii:

I meant something like this:

It really doesn't seem to be lost.

This variant of the check does not take into account the change in the size of the resource and the data at the end of the resource.

 
fxsaber:

This check variant does not take into account changes in the size of the resource and the data at its end.

Can previously written data remain in memory? How to clear it?

 
Andrey Khatimlianskii:

Can previously recorded data remain in memory?

Theoretically, this is possible. Therefore, you should check this as well.

How to clear it?

Forum on trading, automated trading systems and testing trading strategies

Libraries: TradeTransactions

fxsaber, 2018.09.20 16:23.

  ResourceINT.Free();                // Deleted data from the resource

Cleaning the resource - deletion.

 
fxsaber:

Theoretically it can be allowed. That's why you should check it too.

There are no errors with two strings of different lengths:

#property script_show_inputs

input bool Save = true; // Save/Load

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166

#define  MINLENGTH 100000

void OnStart()
{  
        const RESOURCEDATA<int> Resource("::Test");
        int Array[];            
        string str[2] = {""};
        for ( int i = 0; i < MINLENGTH  ; i ++ ) str[0] += (i%1000==0?"\n":"a");
        for ( int i = 0; i < MINLENGTH/2; i ++ ) str[1] += (i%1000==0?"\n":"b");
        str[0] += "\nCHECK";
        str[1] += "\nCHECK";

        while ( !::IsStopped() )
    if (Save)
    {
        char arr[];
        static bool var = false;
        var = !var;
        StringToCharArray( (string)GetTickCount() + "\n" + str[var], arr );
        ArrayResize(Array, ArraySize(arr));
        ArrayCopy( Array, arr );
        Resource = Array;
    }
    else
    {
      ArrayResize(Array, 0);
      const int Size = Resource.Get(Array);
      char get[]; ArrayResize( get, Size );
      ArrayCopy( get, Array );
      string res = CharArrayToString( get );
      uint start = (uint)StringToInteger( StringSubstr( res, 0, StringFind( res, "\n" ) ) );
      Comment( "Delay = ", (GetTickCount() - start), " ms\n", res );
      if ( StringSubstr( res, StringLen( res )-5, 5 ) != "CHECK" ) { Print( res ); break; }
    }
}
 
Andrey Khatimlianskii:

No errors with two strings of different lengths either:

That's right. That's why I said that the original code checked it.

 
Have you ever considered using standard C++ style/naming conventions? I personally think your code is brilliant, but the reason I don't use your libraries (or have to refactor them) is because of the style being used. It's very difficult to mentally parse some of your code simply because you're not following any standard conventions. This is particularly frustrating for those of us who come from other languages. For example, this library names everything in CamelCase except the class declaration (ALLCAPS) which goes against the grain of any naming-conventions in almost all programming languages. Looking at the code is frustrating because in a lot of other languages 
CamelCase.thing

is accessing a class-wide attribute instead of an instance attribute. 

The same goes for the class declarations, and you like to use macros so much that I never know whether your class declarations are macros or enums. Typically, by MQL standard conventions, you should only use ALLCAPS for enums, macros, and constants -- and CamelCase is used for class declarations. Also, variables are defined using snake_case, by MQL convention.  


It is not my intention to offend you with my constructive-criticism, and I know you work very hard to make these libraries free for everyone, which is awesome and we need more devs like you. I know that I don't speak only for myself, and if you just made a minor tweaks to the style being applied then more developers would use your libraries. That is what you want, is it not?