Libraries: TradeTransactions - page 4

 

According to the first tests, I assume that for double and datetime we should make separate resources and name of global variables. Is this correct?

const RESOURCEDATA<double>ResourceDouble("::Double_"+__FILE__); 
const RESOURCEDATA<datetime>ResourceTime("::Time_"+__FILE__); 

int OnInit()
  {
   _GlobalVariableSet("ResourceName",ResourceDouble.GetFullName()); 
   Print(" ResourceDouble.GetFullName(): ",ResourceDouble.GetFullName());

   _GlobalVariableSet("ResourceName1",ResourceTime.GetFullName());  
   Print(" ResourceTime.GetFullName(): ",ResourceTime.GetFullName());   
   
//---
   return(INIT_SUCCEEDED);
  }
 
Nauris Zukas:

According to the first tests, I assume that for double and datetime we should make separate resources and name of global variables. Is this correct?

Unfortunately, it is very difficult to reach your level of programming language proficiency. Perhaps someone else will explain it to you.

 
fxsaber:

Unfortunately, it is very difficult to get to your level of programming language proficiency. Perhaps someone else will explain it to you.

Well, the main thing is that everything works for me so far.

 
fxsaber:

Update ResourceData.mqh and try these indicators



Good afternoon! Can't you transfer from .mqh to the indicator? Or is there some trick to not reset every time when compiling the indicator? I made such a variant, but it resets when compiling the indicator:

#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>m_Resource("::"+__FILE__); // Resource for data transfer (ticks)

class CMyTicks
  {
protected:
public:
   //+------------------------------------------------------------------+
   //| Constructor.|
   //+------------------------------------------------------------------+ 
   void CMyTicks()
     {
      _GlobalVariableSet("ResourceName",m_Resource.GetFullName()); // Write the full name of the resource (read-only) to the global variable 
     }
   //+------------------------------------------------------------------+
   //| Destructor.|
   //+------------------------------------------------------------------+ 
   void ~CMyTicks()
     {
      //_GlobalVariableDel("ResourceName");
     }

   //+------------------------------------------------------------------+ 
   void CollectTicks()
     {
      MqlTick m_Ticks[];
      CopyTicks(_Symbol,m_Ticks,COPY_TICKS_ALL,0,5); // Generated data
      m_Resource=m_Ticks; // Recorded the data
     }

  };
//+------------------------------------------------------------------+
// Data retrieval
#property indicator_chart_window
#property indicator_plots 0

#include <Test_Keep_Info_13.mqh>
CMyTicks  Test;

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

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

int OnCalculate(const int rates_total,const int prev_calculated,const int,const double &[])
  {
   if(prev_calculated==0)
     {
      Resource.Get(Ticks); // Read data from the resource.
      ArrayPrint(Ticks);   // Print the obtained data

      if(ArraySize(Ticks)<1)
        {
         Test.CollectTicks();
         Print(" SAVE TICKS ");
        }

      Resource.Get(Ticks); // Read data from the resource.
      ArrayPrint(Ticks);   // Print the obtained data
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

And on the account of "someone else will explain", so I already know the answer, will be "ask the author". Thank you!

 
Nauris Zukas:


Good afternoon! Can't you transfer from .mqh to the indicator? Or is there some trick to not reset every time the indicator is compiled? I made such a variant, but it resets when compiling the indicator:

And on the account of "someone else will explain", so I already know the answer, will be "ask the author". Thank you!

Unfortunately, I can't understand the question.

 
fxsaber:

Unfortunately, I can't understand the question.

The object is static, but the data is destroyed. What is wrong in my example?

 
Nauris Zukas:

The object is static, but the data is destroyed. What is wrong in my example?

Unfortunately, you have big gaps in your understanding of OOP, so you are not getting what you intended. Ask on the forum for help with general OOP questions.

 
fxsaber:

Unfortunately, you have big gaps in your understanding of OOP, so it doesn't work out as intended. Ask the forum for help with general OOP questions.

Okay, thanks.

 

The library sources contain Convert.mqh, which quickly converts an array of one type into an array of another type.

 

You can exchange anything through Resources.

// Example of exchanging any data (including string arrays).

#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; // 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
  
  Resource.Get(Container2.Data); // Got the data
      
  // Get the data in its original form
  string Str2[];
  Container[0].Get(Str2);                // Got the array
  ArrayPrint(Str2);

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