Extending MqlTick - page 2

 
Hannan Nussbaum:

static CustomTick Ticks[1];

ExchangeTicks.DataSave(Ticks, true);

Error: 'Ticks' - parameter conversion not allowed

What can be done to solve this? When using the standard MqlTick is works fine.

(DataSave method see above code in class EXCHANGE_DATA)


since MQL does not have C pointers  

struct ctick
{
    MqlTick tick;
    char symbol[8];
    int account;
}

etick;

remark:

I put "char symbol[8]" in place of "string symbol", because in functions like e.g. FileWriteArray() you can not use a struct that contains a string

regards

 
Demos Stogios:

since MQL does not have C pointers  

remark:

I put "char symbol[8]" in place of "string symbol", because in functions like e.g. FileWriteArray() you can not use a struct that contains a string

regards


Still parameter conversion error since ExchangeTicks.DataSave(Ticks, true); 

expect Ticks of type MqlTick.

 
Hannan Nussbaum:

Still parameter conversion error since ExchangeTicks.DataSave(Ticks, true); 

expect Ticks of type MqlTick.


Ok mea culpa, my post was more like "use C like programming, no OOP ", so I can not be of much help (as I can not read OOP). But in general, DataSave is a function you have made, so it expects whatever you have made it to expect. So,  there may be a problem somewhere else, but as I have said  I can not read OOP sorry :)

 
whroeder1:
You can derive from a structure just fine. You can't use an array of the derived in place of an array of the base. You'll have to copy each element yourself.

The point is it's not coherent.

If you derive a structure from MqlRates (internal mql), you can pass it as an array in place of MqlRates in CopyRates, it compiles, but failed at runtime. It should not compile, as with any custom structure.

 
Alain Verleyen: . It should not compile, as with any custom structure.

Passing a custom structure is not the problem, (the reference doesn't need adjusting since there's no multiple inheritance.) Passing an array of them is because there's no way to index the different sizes, and that should not compile.

 
whroeder1:

Passing a custom structure is not the problem, (the reference doesn't need adjusting since there's no multiple inheritance.) Passing an array of them is because there's no way to index the different sizes, and that should not compile.

Exact. But it compiles (with CopyRates) and that's what confused me. Thanks for clarifying it.
 
Alain Verleyen:

The point is it's not coherent.

If you derive a structure from MqlRates (internal mql), you can pass it as an array in place of MqlRates in CopyRates, it compiles, but failed at runtime. It should not compile, as with any custom structure.

I'm not sure what you guys are talking about... Passing a struct derived from MqlRates to CopyRates works just fine on my end. (MT4 build 1090)

struct MyRates : public MqlRates
{
   double PriceTypical() const { return (high+low+close) / 3;}
};

void OnStart()
{
   MyRates rates[];
   ArraySetAsSeries(rates,true);
   int total = CopyRates(_Symbol,_Period,0,Bars,rates);
   for(int i=0;i<total&&i<10;i++)
      printf("[%d] %s:: %f", i, TimeToString(rates[i].time), rates[i].PriceTypical());
}
Edit: Perhaps you forgot to add "public" to the declaration?
 
nicholishen:

I'm not sure what you guys are talking about... Passing a struct derived from MqlRates to CopyRates works just fine on my end. (MT4 build 1090)

Edit: Perhaps you forgot to add "public" to the declaration?

A single structure as a reference is fine, while the array declaration relies on the structure length. In your example, the length does not change.

 
nicholishen:

I'm not sure what you guys are talking about... Passing a struct derived from MqlRates to CopyRates works just fine on my end. (MT4 build 1090)

Edit: Perhaps you forgot to add "public" to the declaration?
and MT5 build < ~1640.
Reason: