Libraries: TradeTransactions - page 3

 
nicholi shen:

Thank you for your appreciation. I learned how to program in this forum. I publish my work because it disciplines. I use my descriptions as clues, because I very quickly forget what and how I wrote.

I apologize for my coding style, but it was intended for myself. And was published as a side effect.

Unfortunately, it is impossible to assess the popularity of published works. If someone uses them, then a very narrow circle of users.

Increase the number of users - there is no such goal.

 

I can't get the data, here I run a script and as I understand the data is now stored somewhere in the terminal:

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
   const RESOURCEDATA<int>ResourceINT("::int"); // Resource for exchanging ints. const - as a proof that nothing is written to the class object 
   int ArrayINT[]={1,2,3};
   ResourceINT=ArrayINT;  // The resource stores an array. 
   int ArrayINT2[];
   ResourceINT.Get(ArrayINT2); // Read data from the resource.
   ArrayPrint(ArrayINT2);      // Withdrawn: 1 2 3 5 1 2 3 
  }
//+------------------------------------------------------------------+

here I run another script to get the data that was saved when I ran the first script, but the data is not displayed:

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166
//+------------------------------------------------------------------+
//| Script programme start function|
//+------------------------------------------------------------------+
void OnStart()
  {
//---
// This is the full name of the resource to be accessed from another programme
   //const string NameOut=StringSubstr(MQLInfoString(MQL_PROGRAM_PATH),StringLen(TerminalInfoString(TERMINAL_PATH))+5)+"::Ticks"; 
   const string NameOut=StringSubstr(MQLInfoString(MQL_PROGRAM_PATH),StringLen(TerminalInfoString(TERMINAL_PATH))+5,9)+"Test_Keep_Info.ex5::Ticks";   
   Print(NameOut); // Print the full name of the resource.
   const RESOURCEDATA<int>Resource(NameOut); // Resource for accessing data (read-only) from another programme
   int ArrayINT2[];
   Resource.Get(ArrayINT2); // Read data from the resource.
   ArrayPrint(ArrayINT2);      // Withdrawn: 

  }
//+------------------------------------------------------------------+

Can you correct where the error is?

 
Nauris Zukas:

I can't get the data, here I am running a script and as I understand it, the data is now stored somewhere in the terminal

Data is destroyed as soon as its owner (who wrote it) stops working. If this is not done, the Terminal's memory will quickly become cluttered.

Start the data master as an advisor/indicator. As long as it lives, its data will be available to others.

 
fxsaber:

Data is destroyed as soon as its owner (who wrote it) stops working. If this is not done, the memory of the Terminal will quickly become cluttered.

Start the data master as an advisor/indicator. As long as it lives, its data will be available to others.

It didn't work on indicators either. I think something is wrong with the path.

 
Nauris Zukas:

It didn't work on the indicators either. I think something is wrong with the path.

You create a resource in each OnCalculate and kill it when the function is finished.

You should make the object static. This is the basics of OOP.

 
fxsaber:

You create a resource in each OnCalculate and kill it when the function completes.

You should make the object static. This is the basics of OOP.

I added static, but it still doesn't work. Can you correct what is wrong there?

 
Nauris Zukas:

I added static, but it still doesn't work. Can you correct what is wrong there?

Update ResourceData.mqh and try these indicators

// Sending data
#property indicator_chart_window
#property indicator_plots 0

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166
#include <GlobalVariables.mqh> // https://www.mql5.com/ru/forum/189649#comment_4854618

const RESOURCEDATA<MqlTick> Resource("::" + __FILE__); // Resource for data transfer (ticks)

void OnInit()
{
  _GlobalVariableSet("ResourceName", Resource.GetFullName()); // Write the full name of the resource to the global variable (read-only)
}

void OnDeinit( const int )
{
  _GlobalVariableDel("ResourceName");
}

int OnCalculate( const int, const int, const int, const double &[] )
{
  MqlTick Ticks[];
  
  CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 5); // Generated data
  
  Resource = Ticks; // Recorded the data
    
  return(0);
}


// Data retrieval
#property indicator_chart_window
#property indicator_plots 0

#include <fxsaber\TradeTransactions\ResourceData.mqh> // https://www.mql5.com/en/code/22166
#include <GlobalVariables.mqh> // https://www.mql5.com/ru/forum/189649#comment_4854618

int OnCalculate( const int, const int, const int, const double &[] )
{
  static const RESOURCEDATA<MqlTick> Resource(_GlobalVariableGet<string>("ResourceName")); // Created a resource based on the full name passed in the global variable
  
  MqlTick Ticks[];

  Resource.Get(Ticks); // Read data from the resource.
  
  ArrayPrint(Ticks);   // Print the obtained data
  
  return(0);
}
 
fxsaber:

Update ResourceData.mqh and try these indicators


Thanks, I got something, now I will take it apart to see how it works.
Can you please correct the warnings in GlobalVariables.mqh? My knowledge ended at Res=-1, but it showed an error there. And I don't know how to remove the OnStart() warning either.


Files:
 
Nauris Zukas:

Can you please correct the warnings in GlobalVariables.mqh?

Files:
 
fxsaber:

Thank you!