Libraries: TradeTransactions - page 8

 
ifffrt #:
The same error still got thrown even after I made that change, sorry.

Download each file separately from the Russian version of the codebase.

TradeTransactions
TradeTransactions
  • www.mql5.com
Доступ к данным OnTradeTransaction в любом месте программы
 

Hello,

Please help me, I am stuck on one point. I made 2 EAs, one saves data, the other reads it. I have a problem with resource discovery.

This code saves the data and from it I can access it and read it:

#include "ResourceData.mqh" // https://www.mql5.com/en/code/22166

#define PRINT(A) Print(#A + " = " + (string)(A));

  struct ExampleStruct

    {

     string ea_name;

     string symbol;

     string direction;

     string time_for_command;

    };

 ExampleStruct qexamplestruct[2];

int OnInit(void)

  {

      EventSetTimer(1);

   return(INIT_SUCCEEDED);

  } 

void OnTimer()

{    

  // Произвольные данные для примера

  string Str[] = {"123", "Hello World!"};  

  qexamplestruct[0].direction="buy";

  qexamplestruct[0].ea_name="TestEAname";

  qexamplestruct[0].symbol="EURUSD";  

  qexamplestruct[0].time_for_command="01.01.2021";

  string stringtosend = Serialize(qexamplestruct[0]);


  const RESOURCEDATA<uint> Resource("::ResoC"); // Ресурс для обмена данными

  CONTAINER<uint> Container;         // Создаем контейнер - все будет храниться в массиве простого типа (в примере выбран uint)

 Container[0] = Str;

 Container[1] = stringtosend;


  const string NameOut = StringSubstr(MQLInfoString(MQL_PROGRAM_PATH), StringLen(TerminalInfoString(TERMINAL_PATH)) + 5) + "::ResoC";  

   Print(NameOut); // Вывели полное имя ресурса.

  Resource = Container.Data;  // Отправили данные на обмен

//---

   }

   string Serialize(const ExampleStruct &s)

{

   return s.ea_name + "\n" + s.symbol + "\n" + s.direction + "\n" + s.time_for_command;

}


ExampleStruct Deserialize(const string &line)

{

   string parts[];

   StringSplit(line, '\n', parts);


   ExampleStruct s;

   if(ArraySize(parts) > 0) s.ea_name = parts[0];

   if(ArraySize(parts) > 1) s.symbol = parts[1];

   if(ArraySize(parts) > 2) s.direction = parts[2];

   if(ArraySize(parts) > 3) s.time_for_command = parts[3];

   return s;

}

And this code reads the data and every time writes that there is nothing:

#include "ResourceData.mqh" // https://www.mql5.com/en/code/22166

#define PRINT(A) Print(#A + " = " + (string)(A));

int OnInit(void){return(INIT_SUCCEEDED);} 

void OnTick()

{    

  const RESOURCEDATA<uint> Resource("\Terminal\99A739E3DB06068691C851DE1765F329\MQL5\Experts\ZC\Conections\Draft4.ex5::ResoC"); // Ресурс для доступа к данным (только для чтения) из другой программы

  CONTAINER<uint> Container4; // Сюда будем получать данные

  Resource.Get(Container4.Data); // Считали данные из ресурса.  

    for (int i = 0; i < Container4.GetAmount(); i++)

       Print("i==",i);

         string Str4;

           Container4[0].Get(Str4);                // Получили массив

  Print("Test!!!"+Str4);   

  Print(Str4);

//---

   }

I seem to be doing everything by analogy, but for some reason I don't see any information from the one I wrote, neither an array of string type, nor a single string that I get from my structure

TradeTransactions
TradeTransactions
  • 2018.09.06
  • www.mql5.com
Доступ к данным OnTradeTransaction в любом месте программы
 
Alexander #:

I seem to do everything by analogy, but for some reason no information is displayed from the one I wrote, neither an array of string type, nor a single string that I get from my structure.

I haven't run it, but I assume that this is the case.

  string GetFullName( void ) const
  {
    // Must be TERMINAL_DATA_PATH вместо TERMINAL_PATH.
        return((this.GetName()[0] == ':') ? ::StringSubstr(::MQLInfoString(MQL_PROGRAM_PATH), ::StringLen(::TerminalInfoString(TERMINAL_PATH)) + 5) + this.GetName() : this.GetName());
  }

Try it this way.

const string NameOut = StringSubstr(MQLInfoString(MQL_PROGRAM_PATH), StringLen(TerminalInfoString(TERMINAL_DATA_PATH)) + 5) + "::ResoC";
 
fxsaber #:

Haven't run it, but I'm assuming that' s the case.

Try this for yourself.

Hello, thank you for writing

Tried it straight away, as it has been written about here before. I went through the options of fixing both in the name to address, also corrected in "ResourceData.mqh". Unfortunately did not help. I have not found the cause yet

 
I checked the resource name using Print("Full Name: ",Resource.GetFullName()); I take the correct name, I tried both TERMINAL_PATH and TERMINAL_DATA_PATH path variants - the result is the same.
 

I've made some more progress -

When using ResourceReadImage(FullNameCorrect,Arr,width,height)) directly, I can accept data from a resource created by another EA, everything works correctly. When accessing the same resource name via library functions (similar to the one attached above) - the data is not accepted.

I will report further when I find what the problem was.

 

I'm creating a resource:

a - through the library

b - manually (ResourceCreate)

I access the resource data from another EA using the same resource name:

a - through the library

b - manually(ResourceReadImage)

Result:

The resource created through the library is not found either manually or through the library

A resource created manually is found and read manually, but is not found through the library.

 
Alexander #:

A resource created through the library is not found either manually or through the library

A manually created resource is located and read manually, but is not located through the library.

It works through the library.

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

#define  PRINT(A) Print(#A + " = " + (string)(A));

void OnStart()
{    
  // Arbitrary data for the example
  string Str[] = {"123", "Hello World!"};
  double Num = 5;
  MqlTick Tick = {0};
  Tick.bid = 1.23456;

  const RESOURCEDATA<uint> Resource("::ResoC"); // Resource for data sharing
  CONTAINER<uint> Container;         // Create a container - everything will be stored in an array of a simple type (uint is chosen in the example)
  
  // Fill the container with different data
  Container[0] = Str;
  Container[1] = Num;
  Container[2] = Tick;
    
  // Print the types of data stored in the container
  for (int i = 0; i < Container.GetAmount(); i++)
    PRINT(Container[i].GetType())

  Resource = Container.Data;  // Sent the data for exchange
  
  CONTAINER<uint> Container2; // This is where we will get the data

  const RESOURCEDATA<uint> Resource2(Resource.GetFullName()); // Resource for data sharing
  
  Resource2.Get(Container2.Data); // Got the data
      
  // Get the data in its original form
  string Str2[];
  Container2[0].Get(Str2);                // Got the array
  ArrayPrint(Str2);

  PRINT(Container2[1].Get<double>())      // We got a number
  PRINT(Container2[2].Get<MqlTick>().bid) // We got the structure 
}


I don't know why your original example doesn't work yet.

 
fxsaber #:

Why your original example doesn't work - I don't know yet.

If everything else is correctly written, it will help.

Forum on trading, automated trading systems and testing trading strategies.

Libraries: TradeTransactions

Alexander, 2025.09.15 21:09

void OnTimer()
{    
  // ....
  static const RESOURCEDATA<uint> Resource("::ResoC"); // Resource for data sharing
  // ....
}

You created an object on each input to OnTimer and, accordingly, killed it - on the output. Therefore, the resource lived for microseconds and was not on the side.

class RESOURCE
{
public:
  ~RESOURCE( void)
  {
    ::ResourceFree(this.Name);
  }
 
fxsaber #:
static

What an obvious point, which I looked past for 2 days without noticing it)

Thank you very much!


Everything works perfectly, the ability to exchange custom structures between algorithms using your library is a huge help for my trading, hats off to you!